PCv5/app/routes/development.py

26 lines
873 B
Python
Raw Normal View History

from flask import send_file, redirect, url_for, abort
from werkzeug.utils import secure_filename
from app import app
from config import V5Config
import os
# These routes are used in development
# In production, those files should be served by the web server (nginx)
@app.route('/avatar/<filename>')
def avatar(filename):
filename = secure_filename(filename) # No h4ckers allowed
filepath = os.path.join(V5Config.DATA_FOLDER, "avatars", filename)
if os.path.isfile(filepath):
return send_file(filepath)
return redirect(url_for('static', filename='images/default_avatar.png'))
@app.route('/fichiers/<path>/<name>')
def attachment(path, name):
file = os.path.join(V5Config.DATA_FOLDER, "attachments",
secure_filename(path), secure_filename(name))
if os.path.isfile(file):
return send_file(file)
else:
abort(404)