This commit is contained in:
Lars committed 2026-08-26 10:42:20 +02:00
1 parent 60f0d2830d
commit 53b1eff833
62 files changed
+6578 -355

No files matched your search

+15 -5
View File
@@ -5,6 +5,7 @@ Video containers are stored as-is; GPS in video metadata is not stripped yet.
"""
from __future__ import annotations
import os
import uuid
from pathlib import Path
@@ -27,10 +28,19 @@ VIDEO_TYPES = {
ALLOWED_TYPES = {**IMAGE_TYPES, **VIDEO_TYPES}
IMAGE_MAX_BYTES = 8 * 1024 * 1024
VIDEO_MAX_BYTES = 64 * 1024 * 1024
MEDIA_ROOT = DATA_DIR / "media"
MAX_BYTES = IMAGE_MAX_BYTES # tests and older imports
def media_root() -> Path:
env = (os.environ.get("KANSHO_MEDIA_ROOT") or "").strip()
if env:
return Path(env)
return DATA_DIR / "media"
MEDIA_ROOT = DATA_DIR / "media" # default; call media_root() at use time
def _owned(conn, table: str, record_id: str, profile_id: str) -> dict | None:
return row_to_dict(
conn.execute(f"SELECT * FROM {table} WHERE id = ? AND profile_id = ?", (record_id, profile_id)).fetchone()
@@ -150,7 +160,7 @@ def save_media(profile_id: str, entry_id: str, filename: str, content_type: str,
asset_id = str(uuid.uuid4())
ext = ALLOWED_TYPES[kind]
rel_path = f"{profile_id}/{asset_id}{ext}"
dest = MEDIA_ROOT / rel_path
dest = media_root() / rel_path
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_bytes(payload)
prefix = "video" if is_video else "image"
@@ -172,8 +182,8 @@ def save_image(profile_id: str, entry_id: str, filename: str, content_type: str,
return save_media(profile_id, entry_id, filename, content_type, data)
def list_media(profile_id: str, entry_id: str) -> list[dict]:
get_entry(profile_id, entry_id)
def list_media(profile_id: str, entry_id: str, *, include_deleted: bool = False) -> list[dict]:
get_entry(profile_id, entry_id, include_deleted=include_deleted)
with get_db() as conn:
rows = conn.execute(
"""
@@ -191,7 +201,7 @@ def get_media(profile_id: str, media_id: str) -> tuple[dict, Path]:
row = _owned(conn, "media_assets", media_id, profile_id)
if not row:
raise StoreError("not_found", "Medium nicht gefunden", 404)
path = MEDIA_ROOT / row["rel_path"]
path = media_root() / row["rel_path"]
if not path.is_file():
raise StoreError("not_found", "Mediendatei fehlt", 404)
return public_media(row), path