diff --git a/Dockerfile b/Dockerfile index 12d7721..879dcc8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ RUN apt-get update && \ WORKDIR /app +COPY templates/file_list.html ./templates/ COPY requirements.txt . COPY app.py . COPY gunicorn_config.py . diff --git a/app.py b/app.py index dd49463..d21b092 100644 --- a/app.py +++ b/app.py @@ -1,14 +1,16 @@ import os import re import uuid -from flask import Flask, request, jsonify, send_from_directory +from flask import Flask, request, jsonify, send_from_directory, render_template import datetime from flasgger import Swagger, swag_from -app = Flask(__name__) +app = Flask(__name__, template_folder='templates') swagger = Swagger(app) app.config['UPLOAD_DIRECTORY'] = os.environ.get('UPLOAD_DIRECTORY', '/uploads') app.config['MAX_CONTENT_LENGTH'] = int(os.environ.get('MAX_CONTENT_LENGTH', '5')) * 1024 * 1024 # in MB +app.config['ENABLE_WEBSERVER'] = os.getenv('ENABLE_WEBSERVER', 'True').lower() == 'true' + VALID_FILENAME_REGEX = r'^[a-zA-Z0-9\-_\.]+$' @@ -17,6 +19,27 @@ AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken') def is_valid_filename(filename): return bool(re.match(VALID_FILENAME_REGEX, filename)) +if app.config['ENABLE_WEBSERVER']: + @app.route('/', methods=['GET']) + def file_list(): + """ + Endpoint for displaying a list of files in the upload directory. + """ + files = [] + for filename in os.listdir(app.config['UPLOAD_DIRECTORY']): + file_path = os.path.join(app.config['UPLOAD_DIRECTORY'], filename) + if os.path.isfile(file_path): + stats = os.stat(file_path) + size = stats.st_size + last_modified = datetime.datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S') + files.append({ + 'name': filename, + 'size': size, + 'last_modified': last_modified + }) + + return render_template('file_list.html', files=files) + @app.route('/health', methods=['GET']) def health_check(): """ diff --git a/templates/file_list.html b/templates/file_list.html new file mode 100644 index 0000000..bfb8f2c --- /dev/null +++ b/templates/file_list.html @@ -0,0 +1,48 @@ + + + + File List + + + +

File List

+ + + + + + + + + + {% for file in files %} + + + + + {% endfor %} + +
NameSize (KB)Last Modified
{{ file.name }} + {{ '%.2f' % (file.size / 1024) }} KB{{ file.last_modified }}
+ +