feat: update media management and project status documentation
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 27s
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 27s
- Updated project status to reflect the latest media management milestones and version increment to 0.8.44. - Enhanced MEDIA_ASSETS_AND_ARCHIVE_SPEC.md with new API details for media asset lifecycle and inline media integration. - Improved exercise media handling in the frontend, including new preview features and user prompts for media deletion. - Adjusted backend API to ensure proper handling of media asset deletions without removing files, maintaining governance and user experience.
This commit is contained in:
1 parent
631ba1cb43
commit
e2964a077d
7 files changed
+437
-195
No files matched your search
@@ -2433,16 +2433,19 @@ def delete_exercise_media(
|
||||
media_id: int,
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""
|
||||
Entfernt nur die Verknüpfung Übung ↔ exercise_media (bzw. Embed-Zeile).
|
||||
Löscht keine Datei und keinen media_assets-Datensatz — optionales Papierkorb-Angebot nur clientseitig
|
||||
über orphan_media_asset_id, wenn dies die letzte Referenz auf das Asset war.
|
||||
"""
|
||||
profile_id = tenant.profile_id
|
||||
unlink_path: Optional[Path] = None
|
||||
orphan_media_asset_id: Optional[int] = None
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
_assert_can_edit_exercise(cur, exercise_id, tenant)
|
||||
media_root = get_effective_media_root(cur)
|
||||
cur.execute(
|
||||
"""SELECT em.file_path, em.media_asset_id, ma.storage_key AS asset_storage_key
|
||||
"""SELECT em.media_asset_id
|
||||
FROM exercise_media em
|
||||
LEFT JOIN media_assets ma ON ma.id = em.media_asset_id
|
||||
WHERE em.id = %s AND em.exercise_id = %s""",
|
||||
(media_id, exercise_id),
|
||||
)
|
||||
@@ -2450,41 +2453,19 @@ def delete_exercise_media(
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Medium nicht gefunden")
|
||||
rec = r2d(row)
|
||||
fp = rec.get("file_path")
|
||||
media_asset_id = rec.get("media_asset_id")
|
||||
asset_storage_key = rec.get("asset_storage_key")
|
||||
|
||||
cur.execute(
|
||||
"DELETE FROM exercise_media WHERE id = %s AND exercise_id = %s",
|
||||
(media_id, exercise_id),
|
||||
)
|
||||
|
||||
if media_asset_id:
|
||||
cur.execute(
|
||||
"SELECT COUNT(*) AS c FROM exercise_media WHERE media_asset_id = %s",
|
||||
(media_asset_id,),
|
||||
)
|
||||
cnt = int(r2d(cur.fetchone())["c"])
|
||||
if cnt == 0:
|
||||
cur.execute(
|
||||
"DELETE FROM media_assets WHERE id = %s RETURNING storage_key",
|
||||
(media_asset_id,),
|
||||
)
|
||||
del_asset = cur.fetchone()
|
||||
sk = None
|
||||
if del_asset:
|
||||
sk = r2d(del_asset).get("storage_key") or asset_storage_key
|
||||
if sk:
|
||||
unlink_path = path_under_media_root(media_root, sk)
|
||||
elif fp:
|
||||
unlink_path = _abs_media_path(fp, media_root)
|
||||
if int(r2d(cur.fetchone())["c"]) <= 1:
|
||||
orphan_media_asset_id = int(media_asset_id)
|
||||
|
||||
cur.execute(
|
||||
"DELETE FROM exercise_media WHERE id = %s AND exercise_id = %s",
|
||||
(media_id, exercise_id),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
if unlink_path and unlink_path.is_file():
|
||||
try:
|
||||
unlink_path.unlink()
|
||||
except OSError as e:
|
||||
logger.warning("Medien-Datei konnte nicht gelöscht werden: %s", e)
|
||||
|
||||
return {"ok": True}
|
||||
return {"ok": True, "orphan_media_asset_id": orphan_media_asset_id}
|
||||
Reference in new issue
Block a user