@@ -325,6 +325,8 @@ UPSCALE_MULTIPLIER_HOST = env.str('UPSCALE_MULTIPLIER_HOST', 'packet:8080') # FILES ImageFile.LOAD_TRUNCATED_IMAGES = True +DATA_UPLOAD_MAX_MEMORY_SIZE = env.int('DATA_UPLOAD_MAX_MEMORY_SIZE', 5) << 20 + # Payments YOOKASSA_ACCOUNT_ID = env.str('YOOKASSA_ACCOUNT_ID', default='defaultapikey') YOOKASSA_SECRET_KEY = env.str('YOOKASSA_SECRET_KEY', default='defaultapikey') @@ -4,7 +4,7 @@ from typing import Literal from django.conf import settings from django.conf.urls.static import static from django.contrib import admin -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist, RequestDataTooBig from django.urls import include, path from django.utils.translation import gettext_lazy as _ from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView @@ -79,6 +79,14 @@ def object_does_not_exists_error_handler(request, exc: ObjectDoesNotExist): return api.create_response(request, {'message': _('Requested object does not exists')}, status=404) +@compatibility_api.exception_handler(RequestDataTooBig) +@api.exception_handler(RequestDataTooBig) +def request_data_too_big_error_handler(request, exc: RequestDataTooBig): + return api.create_response( + request, {'detail': _('Data size limit exceeded. Please reduce the size')}, status=413 + ) + + @api.exception_handler(InvalidToken) def invalid_token_error_handler(request, exc: InvalidToken): return api.create_response(request, {'message': _('Token is invalid')}, status=401) @@ -1178,6 +1178,10 @@ msgstr "Списания" msgid "Amount" msgstr "Количество" +#: lib/middleware.py:40 +msgid "Data size limit exceeded. Please reduce the size" +msgstr "Превышен лимит размера данных. Уменьшите размер" + #: payments/models/payment.py:41 msgid "Plan" msgstr "План" @@ -114,4 +114,6 @@ DJANGO_RUNSERVER_HIDE_WARNING=true PYTHONWARNINGS=ignore::UserWarning:polymorphic # temporarily # SSE STREAMING -FF__STREAMING_ENABLED=True \ No newline at end of file +FF__STREAMING_ENABLED=True + +DATA_UPLOAD_MAX_MEMORY_SIZE=5 # MB \ No newline at end of file