style: remove extension from stored files' names

This commit is contained in:
2025-01-05 22:00:12 +03:00
parent ff13997bbd
commit 844ad5452e
4 changed files with 29 additions and 16 deletions
+25 -12
View File
@@ -401,47 +401,60 @@ def files_delete():
return jsonify({"status": False, "error": str(e).split('\n')[0]})
@app.route("/static/files/<file_id>.<ext>", methods=["GET"])
def file_full(file_id=None, ext=None):
@app.route("/static/files/<file_id>", methods=["GET"])
def file_full(file_id=None):
try:
ts = tfm_api.TSession(session.get("id"))
except Exception as e:
logout()
abort(404)
try:
if not ts.get_file(file_id):
file = ts.get_file(file_id)
if not file:
raise RuntimeError("File does not exist")
return send_file(join(tfm_api.conf["Paths"]["Files"], "%s.%s" % (file_id, ext)))
return send_file(
join(tfm_api.conf["Paths"]["Files"], file_id),
mimetype=file["mime_name"],
download_name=(file["orig_name"] if file["orig_name"] else "%s.%s" % (file_id, file["extension"]))
)
except:
abort(404)
@app.route("/static/thumbs/<file_id>.<ext>", methods=["GET"])
def thumb(file_id=None, ext=None):
@app.route("/static/thumbs/<file_id>", methods=["GET"])
def thumb(file_id=None):
try:
ts = tfm_api.TSession(session.get("id"))
except Exception as e:
logout()
abort(404)
try:
if not ts.get_file(file_id):
file = ts.get_file(file_id)
if not file:
raise RuntimeError("File does not exist")
return send_file(tfm_api.previewer.get_jpeg_preview(join(tfm_api.conf["Paths"]["Files"], "%s.%s" % (file_id, ext)), height=160, width=160))
return send_file(
tfm_api.previewer.get_jpeg_preview(join(tfm_api.conf["Paths"]["Files"], file_id), height=160, width=160),
mimetype=file["mime_name"]
)
except:
abort(404)
@app.route("/static/previews/<file_id>.<ext>", methods=["GET"])
def preview(file_id=None, ext=None):
@app.route("/static/previews/<file_id>", methods=["GET"])
def preview(file_id=None):
try:
ts = tfm_api.TSession(session.get("id"))
except Exception as e:
logout()
abort(404)
try:
if not ts.get_file(file_id):
file = ts.get_file(file_id)
if not file:
raise RuntimeError("File does not exist")
return send_file(tfm_api.previewer.get_jpeg_preview(join(tfm_api.conf["Paths"]["Files"], "%s.%s" % (file_id, ext)), height=1080, width=1920))
return send_file(
tfm_api.previewer.get_jpeg_preview(join(tfm_api.conf["Paths"]["Files"], file_id), height=1080, width=1920),
mimetype=file["mime_name"]
)
except:
abort(404)