temporary_link feature

This commit is contained in:
Mateusz Gruszczyński
2026-05-21 22:05:08 +02:00
parent cb48735178
commit b772c97d50
10 changed files with 844 additions and 41 deletions

View File

@@ -141,8 +141,6 @@ _MEDIA_INFO_SAMPLE_BYTES = 32 * 1024 * 1024
_MEDIA_INFO_CHUNK_BYTES = 1024 * 1024
_TEXT_PREVIEW_BYTES = 512 * 1024
_IMAGE_PREVIEW_BYTES = 8 * 1024 * 1024
_PDF_TEXT_BYTES = 16 * 1024 * 1024
_PDF_TEXT_PAGES = 10
_MEDIA_INFO_TMP_DIR = BASE_DIR / "data" / "media-info-samples"
@@ -296,41 +294,12 @@ def _image_file_preview(profile: dict, selected: dict, remote_path: str, max_byt
return result
def _pdf_imports():
# Note: pypdf is imported lazily so non-PDF previews do not depend on it at request time.
import sys
try:
from pypdf import PdfReader
return PdfReader
except ModuleNotFoundError as exc:
missing = str(getattr(exc, "name", "") or "pypdf")
if missing.split(".", 1)[0] == "pypdf":
raise RuntimeError(
"Python package 'pypdf' is not importable in the application runtime. "
"Install it inside the pyTorrent virtualenv and restart the service: "
"/opt/pyTorrent/venv/bin/pip install -r /opt/pyTorrent/requirements.txt && systemctl restart pytorrent. "
f"Runtime: {sys.executable}."
) from exc
raise RuntimeError(
f"pypdf is installed, but one of its Python dependencies is missing: {missing}. "
f"Runtime: {sys.executable}."
) from exc
except Exception as exc:
raise RuntimeError(
"pypdf was found, but failed during import. "
f"Runtime: {sys.executable}. Details: {exc}"
) from exc
def _pdf_file_preview(
profile: dict,
selected: dict,
remote_path: str,
max_bytes: int = _PDF_TEXT_BYTES,
max_pages: int = _PDF_TEXT_PAGES,
) -> dict:
# Note: The modal keeps a metadata payload here, while the frontend streams the real PDF through the existing file download route in inline mode.
# Note: pypdf is no longer required because PDFs are not parsed; the browser renders the original file stream.
size = int(selected.get("size") or 0)
return {
**selected,