[AZ-175] Media table integration with XxHash64 content hashing and status lifecycle

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-31 06:36:56 +03:00
parent 6c24d09eab
commit 40be55ac03
10 changed files with 381 additions and 30 deletions
+42 -2
View File
@@ -6,6 +6,7 @@ app = Flask(__name__)
_mode = "normal"
_annotations: list = []
_media_store: dict = {}
def _fail():
@@ -46,12 +47,44 @@ def user_ai_settings(user_id):
}
@app.route("/api/media", methods=["POST"])
def create_media():
if _fail():
return "", 503
body = request.get_json(silent=True) or {}
mid = body.get("id")
if not mid:
return "", 400
_media_store[str(mid)] = dict(body)
return body, 201
@app.route("/api/media/<media_id>/status", methods=["PUT"])
def update_media_status(media_id):
if _fail():
return "", 503
body = request.get_json(silent=True) or {}
st = body.get("mediaStatus")
key = str(media_id)
rec = _media_store.get(key)
if rec is None:
rec = {"id": key}
_media_store[key] = rec
if st is not None:
rec["mediaStatus"] = st
return "", 204
@app.route("/api/media/<media_id>", methods=["GET"])
def media_path(media_id):
if _fail():
return "", 503
key = str(media_id)
rec = _media_store.get(key)
if rec and rec.get("path"):
return {"path": rec["path"]}
root = os.environ.get("MEDIA_DIR", "/media")
if media_id.startswith("sse-") or media_id.startswith("video-"):
if key.startswith("sse-") or key.startswith("video-"):
return {"path": f"{root}/video_test01.mp4"}
return {"path": f"{root}/image_small.jpg"}
@@ -69,9 +102,10 @@ def mock_config():
@app.route("/mock/reset", methods=["POST"])
def mock_reset():
global _mode, _annotations
global _mode, _annotations, _media_store
_mode = "normal"
_annotations.clear()
_media_store.clear()
return "", 200
@@ -81,9 +115,15 @@ def mock_status():
"mode": _mode,
"annotation_count": len(_annotations),
"annotations": list(_annotations),
"media_count": len(_media_store),
}
@app.route("/mock/annotations", methods=["GET"])
def mock_annotations_list():
return {"annotations": list(_annotations)}
@app.route("/mock/media", methods=["GET"])
def mock_media_list():
return {"media": dict(_media_store)}