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 <noreply@anthropic.com>
This commit is contained in:
parent
9c0a046c57
commit
0a6ba6feac
4 changed files with 13 additions and 4 deletions
|
|
@ -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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
<link rel="apple-touch-icon" href="/static/icon-192.png">
|
||||
<link rel="stylesheet" href="/static/css/app.css">
|
||||
<title>{% block title %}diora{% endblock %}</title>
|
||||
<script>const DIORA_CONFIG = { ebookMaxBytes: {{ EBOOK_MAX_BYTES }}, bgMaxBytes: {{ BG_MAX_BYTES }} };</script>
|
||||
{% if encrypted_bg_json %}
|
||||
<script>const ENCRYPTED_BG = {{ encrypted_bg_json|safe }};</script>
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue