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/') 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//') 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)