Files
DocsGPT/docsgpt/stt/upload_limits.py
T
Alex 574f96341e refactor: rename the application package to docsgpt
The backend import package is now docsgpt, the name it will carry on PyPI;
application was far too generic to install into anyone's site-packages.
git mv plus a mechanical rewrite of every import, dotted string and path
reference: 734 Python files, the compose files, Dockerfile, workflows, docs,
setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage
config, .gitignore. Behaviour is unchanged.

Kept for one release:
- A top-level application package whose meta-path finder resolves
  application.x.y to the already-imported docsgpt.x.y object, so old imports
  and entry points (celery -A application.app.celery,
  uvicorn application.asgi:asgi_app) keep working with a FutureWarning.
- Celery registers every application.* task name as an alias of its
  docsgpt.* task on start-up, so messages queued by the previous release still
  run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries
  the previous release wrote are left unread instead of firing twice.

The backend image builds from the repository root (docker build -f
docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore
allow-lists docsgpt/ and application/ and keeps caches, local data, .env
files, the sample index files and the Dockerfile out. Compose and the image
workflows point at the new context.
2026-09-07 10:20:43 +01:00

44 lines
1.3 KiB
Python

from pathlib import Path
from docsgpt.core.settings import settings
from docsgpt.stt.constants import SUPPORTED_AUDIO_EXTENSIONS
from docsgpt.utils import safe_filename
STT_REQUEST_SIZE_OVERHEAD_BYTES = 1024 * 1024
STT_SIZE_LIMITED_PATHS = frozenset(("/api/stt", "/api/stt/live/chunk"))
class AudioFileTooLargeError(ValueError):
pass
def get_stt_max_file_size_bytes() -> int:
return max(0, settings.STT_MAX_FILE_SIZE_MB) * 1024 * 1024
def build_stt_file_size_limit_message() -> str:
return f"Audio file exceeds {settings.STT_MAX_FILE_SIZE_MB}MB limit"
def is_audio_filename(filename: str | Path | None) -> bool:
if not filename:
return False
safe_name = safe_filename(Path(str(filename)).name)
return Path(safe_name).suffix.lower() in SUPPORTED_AUDIO_EXTENSIONS
def enforce_audio_file_size_limit(size_bytes: int) -> None:
max_size_bytes = get_stt_max_file_size_bytes()
if max_size_bytes and size_bytes > max_size_bytes:
raise AudioFileTooLargeError(build_stt_file_size_limit_message())
def should_reject_stt_request(path: str, content_length: int | None) -> bool:
if path not in STT_SIZE_LIMITED_PATHS or content_length is None:
return False
max_request_size_bytes = (
get_stt_max_file_size_bytes() + STT_REQUEST_SIZE_OVERHEAD_BYTES
)
return content_length > max_request_size_bytes