Serve svg tpl when thumbnail not found

This commit is contained in:
ABelliqueux 2022-11-25 14:36:09 +01:00
parent f9191892cf
commit db048b2115
5 changed files with 31 additions and 16 deletions

13
app.py
View File

@ -3,6 +3,7 @@
# abelliqueux <contact@arthus.net> # abelliqueux <contact@arthus.net>
from flask import Flask, flash, request, redirect, url_for, send_file from flask import Flask, flash, request, redirect, url_for, send_file
from flask_httpauth import HTTPBasicAuth from flask_httpauth import HTTPBasicAuth
from io import BytesIO
import gettext import gettext
import os import os
import subprocess import subprocess
@ -235,12 +236,18 @@ def upload_file(over_write=1):
return "OK" return "OK"
@app.route("/thumb/<media>") @app.route("/thumb/<media>")
@auth.login_required @auth.login_required
def get_thumbnail(media): def get_thumbnail(media):
if media and os.path.exists(thumbnails_folder + os.sep + media): if media:
return send_file(thumbnails_folder + os.sep + media + ".jpg", mimetype='image/jpg') media_full_path = thumbnails_folder + os.sep + media + ".jpg"
if os.path.exists(media_full_path):
return send_file(media_full_path, mimetype='image/jpg')
else:
# Return a svg file as bytes, so that we can use gettext on its content
svg = '<svg width="320" height="240" viewBox="0 0 84.6 63.5" version="1.1" id="not_found" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><path id="not_found_x" style="fill:#f00;" d="M 3.076298,0.04960937 H 0.04960937 V 1.5394409 L 40.0389,31.278194 0.04960937,61.017464 v 2.432927 H 1.8076416 L 42.553475,33.148364 83.299825,63.450391 h 1.317232 V 60.691386 L 45.067533,31.278194 84.617057,1.8655192 V 0.04960937 H 82.031169 L 42.553475,29.408541 Z" /><text xml:space="preserve" style="font-size:8px;stroke:#000;stroke-width:2px;" x="50%" y="50%" id="not_found_txt"><tspan id="not_found_span" style="text-align:center;text-anchor:middle;stroke:none;">{}</tspan></text></svg>'.format(_("MEDIA NOT FOUND"))
buf = BytesIO(bytes(svg, "UTF-8"))
return send_file(buf, mimetype="image/svg+xml")
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2022-11-03 12:59+0100\n" "POT-Creation-Date: 2022-11-25 14:13+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -15,35 +15,39 @@ msgstr ""
"Generated-By: pygettext.py 1.5\n" "Generated-By: pygettext.py 1.5\n"
#: ../app.py:25 #: ../app.py:29
msgid "Found configuration file in {}" msgid "Found configuration file in {}"
msgstr "" msgstr ""
#: ../app.py:104 #: ../app.py:178
msgid "Nothing to see here !" msgid "Nothing to see here !"
msgstr "" msgstr ""
#: ../app.py:115 #: ../app.py:192
msgid "Blinkin" msgid "Blinkin"
msgstr "" msgstr ""
#: ../app.py:122 #: ../app.py:200
msgid "Rebooting..." msgid "Rebooting..."
msgstr "" msgstr ""
#: ../app.py:129 #: ../app.py:208
msgid "Shutting down..." msgid "Shutting down..."
msgstr "" msgstr ""
#: ../app.py:139 #: ../app.py:221
msgid "No file part: {}" msgid "No file part: {}"
msgstr "" msgstr ""
#: ../app.py:144 #: ../app.py:226
msgid "No selected file" msgid "No selected file"
msgstr "" msgstr ""
#: ../app.py:148 #: ../app.py:233
msgid "File saved in {}" msgid "File saved in {}"
msgstr "" msgstr ""
#: ../app.py:250
msgid "MEDIA NOT FOUND"
msgstr ""

Binary file not shown.

View File

@ -47,3 +47,6 @@ msgstr "Aucun fichier sélectionné."
msgid "File saved in {}" msgid "File saved in {}"
msgstr "Fichier enregistré dans {}" msgstr "Fichier enregistré dans {}"
#: ../app.py:250
msgid "MEDIA NOT FOUND"
msgstr "MEDIA INTROUVABLE"

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# pygettext ../../../app.py -o template.pot cd "$(dirname "$0")"
#pygettext -p en/LC_MESSAGES/ -o template.pot ../app.py
for locale in */LC_MESSAGES/template.pot; do for locale in */LC_MESSAGES/template.pot; do
/usr/bin/msgfmt -o ${locale%.*}.mo $locale /usr/bin/msgfmt -o ${locale%.*}.mo $locale
done done