refactor(media): Vereinsflache Ablage; private als u{profile} unter Verein
- club: library/club/c{id}/{sha} (kein shared/)
- private: library/club/c{id}/u{profile}/{sha} statt …/private/
- Dedupe private: sha + club_id + uploaded_by_profile_id
- version 0.8.54
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3f0d02edab
commit
8d85649cf8
6 files changed
+103
-39
No files matched your search
@@ -2415,13 +2415,23 @@ async def upload_exercise_media(
|
||||
raise HTTPException(status_code=400, detail="Vereinsübung ohne club_id")
|
||||
dedupe_club = int(ex_club)
|
||||
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = %s
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, ex_vis, dedupe_club),
|
||||
)
|
||||
if ex_vis == "private":
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = 'private'
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
AND (uploaded_by_profile_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, dedupe_club, profile_id),
|
||||
)
|
||||
else:
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = %s
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, ex_vis, dedupe_club),
|
||||
)
|
||||
existing_asset = cur.fetchone()
|
||||
|
||||
if existing_asset:
|
||||
@@ -2509,7 +2519,13 @@ async def upload_exercise_media(
|
||||
)
|
||||
else:
|
||||
try:
|
||||
storage_key = library_storage_key(ex_vis, dedupe_club if ex_vis != "official" else None, full_sha, ext)
|
||||
storage_key = library_storage_key(
|
||||
ex_vis,
|
||||
dedupe_club if ex_vis != "official" else None,
|
||||
full_sha,
|
||||
ext,
|
||||
uploader_profile_id=profile_id if ex_vis == "private" else None,
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
dest_path = path_under_media_root(media_root, storage_key)
|
||||
|
||||
@@ -332,7 +332,15 @@ def _relocate_asset_file_if_governance_changed(
|
||||
return None
|
||||
ext = Path(old_key.replace("\\", "/")).suffix or ".bin"
|
||||
try:
|
||||
new_key = library_storage_key(next_vis, next_club_id, sha, ext)
|
||||
up = asset.get("uploaded_by_profile_id")
|
||||
up_i = int(up) if up is not None else None
|
||||
new_key = library_storage_key(
|
||||
next_vis,
|
||||
next_club_id if next_vis != "official" else None,
|
||||
sha,
|
||||
ext,
|
||||
uploader_profile_id=up_i if next_vis == "private" else None,
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
old_norm = old_key.replace("\\", "/").lstrip("/")
|
||||
@@ -557,13 +565,23 @@ def _ingest_library_media_file(
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
|
||||
full_sha = hashlib.sha256(raw).hexdigest()
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = %s
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, vis, next_cid),
|
||||
)
|
||||
if vis == "private":
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = %s
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
AND (uploaded_by_profile_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, vis, next_cid, profile_id),
|
||||
)
|
||||
else:
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = %s
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, vis, next_cid),
|
||||
)
|
||||
existing_asset = cur.fetchone()
|
||||
|
||||
if existing_asset:
|
||||
@@ -606,7 +624,13 @@ def _ingest_library_media_file(
|
||||
|
||||
media_root = get_effective_media_root(cur)
|
||||
try:
|
||||
storage_key = library_storage_key(vis, next_cid, full_sha, ext)
|
||||
storage_key = library_storage_key(
|
||||
vis,
|
||||
next_cid,
|
||||
full_sha,
|
||||
ext,
|
||||
uploader_profile_id=profile_id if vis == "private" else None,
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
dest_path = path_under_media_root(media_root, storage_key)
|
||||
|
||||
Reference in new issue
Block a user