Added API endpoint media/extract and simple UI page

master
Felix Stupp 3 years ago
parent e37bbd60f0
commit 6e002db353
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -235,6 +235,10 @@ def list_media():
media_list=list(itertools.islice(get_considerable(), 100))
)
@flask_app.route("/media/extract")
def extract_media():
return render_template("media_extract.htm")
@flask_app.route("/media/length")
def get_media_length():
c = len(MediaElement.select())
@ -365,6 +369,20 @@ def api_media_list():
} for media in media_list],
}, 200
@flask_app.route("/api/media/extract", methods=["POST"])
def api_media_extract():
data = request.form.to_dict()
if "uri" not in data:
return {
"status": False,
"error": f"Missing uri value to extract",
}
m = media_extract_uri(data["uri"])
orm.flush()
if m and environ_bool(data.get("redirect_to_object", False)):
return redirect(m.info_link)
return redirect_back_or_okay()
@flask_app.route("/api/media/<int:media_id>", methods=["GET", "POST"])
def api_media_element(media_id: int):
element: MediaElement = MediaElement.get(id=media_id)

@ -0,0 +1,24 @@
{% import "macros.htm" as macros %}
<!DOCTYPE html>
<html>
{% set title = "Extract Media" %}
<head>
<meta charset="utf-8"/>
<title>{{ title }}</title>
{{ macros.shared_style() }}
</head>
<body>
<a href="/media">&lt;- back to list</a>
<h1>{{ title }}</h1>
<form method="post" action="/api/media/extract">
{{ macros.hidden_redirect_back() }}
<input type="text" name="uri" style="width: 40em;" />
<button type="submit" name="redirect_to_object" value="true">
extract
</button>
<button type="submit" name="redirect_to_object" value="false">
extract & more
</button>
</form>
</body>
</html>
Loading…
Cancel
Save