From 23c079abc1187e84cbde486a013a9cfce41a26ca Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 24 Oct 2021 23:38:37 +0200 Subject: [PATCH] app: Added API endpoint to update all collections and specific ones --- server/app.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/app.py b/server/app.py index 1c50df1..6af4f61 100644 --- a/server/app.py +++ b/server/app.py @@ -20,7 +20,7 @@ from pony import orm from entertainment_decider import common from entertainment_decider.models import db, MediaCollection, MediaCollectionLink, MediaElement -from entertainment_decider.extractors.collection import collection_extract_uri +from entertainment_decider.extractors.collection import collection_extract_uri, collection_update from entertainment_decider.extractors.media import media_extract_uri @@ -230,6 +230,23 @@ def show_media(media_id): return make_response(f"Not found", 404) return render_template("media_element.htm", element=element) + +@flask_app.route("/api/refresh/collections") +def refresh_collections(): + collections: List[MediaCollection] = orm.select(c for c in MediaCollection if c.keep_updated) + for coll in collections: + collection_update(coll) + return redirect_back_or_okay() + +@flask_app.route("/api/refresh/collection/") +def force_refresh_collection(collection_id: int): + coll: MediaCollection = MediaCollection.get(id=collection_id) + if coll is None: + return "404 Not Found", 404 + collection_update(coll) + return redirect_back_or_okay() + + @flask_app.route("/stats") def show_stats(): elements: List[MediaElement] = MediaElement.select()