From 0a6ba6feac236b29e0aba87908fd5b6781829abd Mon Sep 17 00:00:00 2001 From: marwin Date: Sat, 4 Apr 2026 21:05:51 +0200 Subject: [PATCH] Inject upload size limits from settings into frontend via DIORA_CONFIG Backend settings are now the single source of truth for EBOOK_MAX_BYTES and BG_MAX_BYTES. A new context processor exposes them to all templates, and base.html injects them as window.DIORA_CONFIG so app.js reads from there instead of hardcoded values. Co-Authored-By: Claude Sonnet 4.6 --- diora/context_processors.py | 7 +++++++ diora/settings.py | 1 + static/js/app.js | 8 ++++---- templates/base.html | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/diora/context_processors.py b/diora/context_processors.py index 1cb8fde..d2d8abf 100644 --- a/diora/context_processors.py +++ b/diora/context_processors.py @@ -3,3 +3,10 @@ from django.conf import settings def build_info(request): return {'BUILD_TIME': getattr(settings, 'BUILD_TIME', '')} + + +def upload_limits(request): + return { + 'EBOOK_MAX_BYTES': getattr(settings, 'EBOOK_MAX_BYTES', 10 * 1024 * 1024), + 'BG_MAX_BYTES': getattr(settings, 'BG_MAX_BYTES', 5 * 1024 * 1024), + } diff --git a/diora/settings.py b/diora/settings.py index 0efad8b..79451ef 100644 --- a/diora/settings.py +++ b/diora/settings.py @@ -62,6 +62,7 @@ TEMPLATES = [ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'diora.context_processors.build_info', + 'diora.context_processors.upload_limits', ], }, }, diff --git a/static/js/app.js b/static/js/app.js index d0fb3c8..7bb5afc 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -2344,8 +2344,8 @@ async function uploadBackground(file) { alert('Only JPEG, PNG, or WebP images are allowed.'); return; } - if (file.size > 5 * 1024 * 1024) { - alert('Image must be 5 MB or smaller.'); + if (file.size > DIORA_CONFIG.bgMaxBytes) { + alert(`Image must be ${DIORA_CONFIG.bgMaxBytes / 1024 / 1024} MB or smaller.`); return; } @@ -2884,8 +2884,8 @@ async function uploadEbook(file) { if (statusEl) statusEl.textContent = 'Only .epub and .pdf files are supported.'; return; } - if (file.size > 50 * 1024 * 1024) { - if (statusEl) statusEl.textContent = 'File too large (max 50 MB).'; + if (file.size > DIORA_CONFIG.ebookMaxBytes) { + if (statusEl) statusEl.textContent = `File too large (max ${DIORA_CONFIG.ebookMaxBytes / 1024 / 1024} MB).`; return; } diff --git a/templates/base.html b/templates/base.html index a4b6247..6ed5950 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,6 +13,7 @@ {% block title %}diora{% endblock %} + {% if encrypted_bg_json %} {% endif %}