|
import os |
|
from flask import Flask, render_template_string, send_from_directory |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
base_directory = "/home/app/" |
|
|
|
@app.route('/') |
|
def index(): |
|
|
|
files = os.listdir(base_directory) |
|
|
|
|
|
html = """ |
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>Archivos disponibles</title> |
|
</head> |
|
<body> |
|
<h1>Archivos disponibles:</h1> |
|
<ul> |
|
""" |
|
|
|
|
|
for file_name in files: |
|
|
|
html += f'<li><a href="/download/{file_name}">{file_name}</a></li>' |
|
|
|
|
|
html += """ |
|
</ul> |
|
</body> |
|
</html> |
|
""" |
|
|
|
return render_template_string(html) |
|
|
|
@app.route('/download/<path:filename>') |
|
def download_file(filename): |
|
"""Sirve el archivo desde el directorio base.""" |
|
|
|
file_path = os.path.join(base_directory, filename) |
|
if os.path.exists(file_path): |
|
return send_from_directory(base_directory, filename, as_attachment=True) |
|
else: |
|
return "Archivo no encontrado", 404 |
|
|
|
if __name__ == '__main__': |
|
|
|
app.run(host='0.0.0.0', port=7860) |
|
|