23b68d845b
- Rename /curate/retag to /curate/swap; response now includes new_tag - /curate/reorder: read body["order"] key (was ordered_ids); include date field - /curate/remove and /curate/swap: return 404 if asset_id not found - Update phase3.html JS fetch calls and reorder payload to match spec Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
from flask import Blueprint, current_app, jsonify, render_template, request
|
|
from app.state import load_state, save_state
|
|
|
|
bp = Blueprint("curate", __name__)
|
|
|
|
|
|
@bp.get("/curate")
|
|
def curate():
|
|
album_id = request.args["album_id"]
|
|
state = load_state(album_id, current_app)
|
|
kept = [p for p in state.photos if p.tag in ("journal", "story")]
|
|
photos_by_day = {}
|
|
for p in kept:
|
|
day = p.local_datetime[:10]
|
|
photos_by_day.setdefault(day, []).append(p)
|
|
return render_template(
|
|
"phase3.html",
|
|
state=state,
|
|
photos_by_day=photos_by_day,
|
|
current_phase="curate",
|
|
album_id=album_id,
|
|
phase_stale=state.phase_stale,
|
|
notes_content=state.notes,
|
|
)
|
|
|
|
|
|
@bp.post("/curate/remove")
|
|
def remove():
|
|
body = request.get_json()
|
|
state = load_state(body["album_id"], current_app)
|
|
photo = next((p for p in state.photos if p.id == body["asset_id"]), None)
|
|
if photo is None:
|
|
return jsonify({"ok": False, "error": "photo not found"}), 404
|
|
photo.tag = "skip"
|
|
save_state(state, current_app)
|
|
return jsonify({"ok": True})
|
|
|
|
|
|
@bp.post("/curate/swap")
|
|
def swap():
|
|
body = request.get_json()
|
|
state = load_state(body["album_id"], current_app)
|
|
photo = next((p for p in state.photos if p.id == body["asset_id"]), None)
|
|
if photo is None:
|
|
return jsonify({"ok": False, "error": "photo not found"}), 404
|
|
photo.tag = "story" if photo.tag == "journal" else "journal"
|
|
save_state(state, current_app)
|
|
return jsonify({"ok": True, "new_tag": photo.tag})
|
|
|
|
|
|
@bp.post("/curate/reorder")
|
|
def reorder():
|
|
body = request.get_json()
|
|
state = load_state(body["album_id"], current_app)
|
|
order_map = {aid: i for i, aid in enumerate(body["order"])}
|
|
for p in state.photos:
|
|
if p.id in order_map:
|
|
p.order = order_map[p.id]
|
|
save_state(state, current_app)
|
|
return jsonify({"ok": True})
|
|
|
|
|
|
@bp.post("/curate/done")
|
|
def done():
|
|
body = request.get_json()
|
|
state = load_state(body["album_id"], current_app)
|
|
if "curate" not in state.phases_completed:
|
|
state.phases_completed.append("curate")
|
|
state.phase = "group"
|
|
save_state(state, current_app)
|
|
return jsonify({"ok": True, "redirect": f"/group?album_id={body['album_id']}"})
|