INNER CODE UNIT · Python
serve_user_file
AnsahMohammad/shots-studio · legacy/web/app.py:124
def serve_user_file(filename):
if ".." in filename:
app.logger.warning(f"serve_user_file: Invalid filename attempt: '{filename}'")
return "Invalid filename", 400
try:
# Ensure we have an absolute path by adding leading / if missing
abs_path = filename if filename.startswith("/") else f"/{filename}"
directory = os.path.dirname(abs_path)
basename = os.path.basename(abs_path)
print(f"Serving file: {abs_path} from directory: {directory}")
return send_from_directory(directory, basename)
except Exception as e:
app.logger.error(f"Error serving file '{filename}': {e}", exc_info=True)
raise
@app.route("/collections", methods=["GET"])