diff --git a/books/views.py b/books/views.py index fdad268..a52b9b3 100644 --- a/books/views.py +++ b/books/views.py @@ -181,7 +181,7 @@ def book_highlights(request, pk): raw_size = len(base64.b64decode(ct)) except Exception: return JsonResponse({'error': 'invalid base64 in ct'}, status=400) - if raw_size > 700 * 1024: + if raw_size > getattr(settings, 'HIGHLIGHTS_MAX_BYTES', 700 * 1024): return JsonResponse({'error': 'highlights data too large (max 700 KB)'}, status=400) row, _ = EBookHighlights.objects.get_or_create(user=request.user, book=book) @@ -226,7 +226,7 @@ def book_bookmarks(request, pk): raw_size = len(base64.b64decode(ct)) except Exception: return JsonResponse({'error': 'invalid base64 in ct'}, status=400) - if raw_size > 100 * 1024: + if raw_size > getattr(settings, 'BOOKMARKS_MAX_BYTES', 100 * 1024): return JsonResponse({'error': 'bookmarks data too large (max 100 KB)'}, status=400) row, _ = EBookBookmarks.objects.get_or_create(user=request.user, book=book) diff --git a/diora/context_processors.py b/diora/context_processors.py index d2d8abf..2c4a74c 100644 --- a/diora/context_processors.py +++ b/diora/context_processors.py @@ -9,4 +9,5 @@ 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), + 'PODCAST_INBOX_PAGE_SIZE': getattr(settings, 'PODCAST_INBOX_PAGE_SIZE', 200), } diff --git a/diora/settings.py b/diora/settings.py index 79451ef..8aa8c36 100644 --- a/diora/settings.py +++ b/diora/settings.py @@ -101,7 +101,13 @@ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media' -BG_MAX_BYTES = 5 * 1024 * 1024 # 5 MB +BG_MAX_BYTES = 5 * 1024 * 1024 # 5 MB +HIGHLIGHTS_MAX_BYTES = 700 * 1024 # 700 KB +BOOKMARKS_MAX_BYTES = 100 * 1024 # 100 KB + +VOLUME_DEFAULT = 204 # out of 255 +ITUNES_TIMEOUT = 6 # seconds +PODCAST_INBOX_PAGE_SIZE = 200 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/podcasts/views.py b/podcasts/views.py index 18d4841..299f0e8 100644 --- a/podcasts/views.py +++ b/podcasts/views.py @@ -145,7 +145,7 @@ def podcast_search(request): try: url = f'https://itunes.apple.com/search?term={urllib.parse.quote(q)}&media=podcast&limit=20' - resp = requests.get(url, timeout=6) + resp = requests.get(url, timeout=getattr(settings, 'ITUNES_TIMEOUT', 6)) resp.raise_for_status() raw = resp.json().get('results', []) except Exception as e: @@ -620,7 +620,7 @@ def inbox(request): ).values_list('episode_id', flat=True) ) - limit = min(int(request.GET.get('limit', 200)), 1000) + limit = min(int(request.GET.get('limit', getattr(settings, 'PODCAST_INBOX_PAGE_SIZE', 200))), 1000) offset = max(int(request.GET.get('offset', 0)), 0) episodes = list( diff --git a/radio/views.py b/radio/views.py index af6a122..669fcf5 100644 --- a/radio/views.py +++ b/radio/views.py @@ -206,7 +206,7 @@ def affiliate_links(request): f"https://itunes.apple.com/search" f"?term={urllib.parse.quote(track)}&media=music&limit=1" ) - resp = requests.get(itunes_url, timeout=5) + resp = requests.get(itunes_url, timeout=getattr(settings, 'ITUNES_TIMEOUT', 6)) resp.raise_for_status() results = resp.json().get('results', []) if results: @@ -584,9 +584,10 @@ def import_m3u(request): def stream_player(request): url = request.GET.get('url', '').strip() name = request.GET.get('name', '').strip() - vol = request.GET.get('vol', '204').strip() + _vol_default = getattr(settings, 'VOLUME_DEFAULT', 204) + vol = request.GET.get('vol', str(_vol_default)).strip() try: vol = max(0, min(255, int(vol))) except ValueError: - vol = 204 + vol = _vol_default return render(request, 'radio/stream_player.html', {'stream_url': url, 'stream_name': name, 'stream_vol': vol}) diff --git a/static/js/app.js b/static/js/app.js index 7bb5afc..531d80e 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1590,7 +1590,7 @@ async function savePodcastProgress() { } let _inboxOffset = 0; -const _inboxPageSize = 200; +const _inboxPageSize = DIORA_CONFIG.podcastInboxPageSize; async function loadAndRenderInbox(append = false) { const listEl = $('podcast-inbox-list'); diff --git a/templates/base.html b/templates/base.html index 6ed5950..509e3c3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,7 +13,7 @@ {% block title %}diora{% endblock %} - + {% if encrypted_bg_json %} {% endif %}