fix linter errors
Some checks failed
ci/woodpecker/push/lint Pipeline failed
ci/woodpecker/push/build unknown status

Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2024-05-08 14:19:23 +02:00
parent f0db0112b2
commit 547d6865a7

20
app.py
View file

@ -1,14 +1,14 @@
# pylint: disable=C0114
import os
import re
import uuid
from flask import Flask, request, jsonify, send_from_directory, render_template
import datetime
from flasgger import Swagger, swag_from
from flask import Flask, request, jsonify, send_from_directory, render_template
from flasgger import Swagger
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['MAX_CONTENT_LENGTH'] = int(os.environ.get('MAX_CONTENT_LENGTH', '5')) * 1024 * 1024 # in MB # pylint: disable=C0301
app.config['ENABLE_WEBSERVER'] = os.getenv('ENABLE_WEBSERVER', 'True').lower() == 'true'
@ -16,7 +16,7 @@ VALID_FILENAME_REGEX = r'^[a-zA-Z0-9\-_\.]+$'
AUTH_TOKEN = os.environ.get('AUTH_TOKEN', 'myuploadtoken')
def is_valid_filename(filename):
def is_valid_filename(filename): # pylint: disable=C0116
return bool(re.match(VALID_FILENAME_REGEX, filename))
if app.config['ENABLE_WEBSERVER']:
@ -31,7 +31,7 @@ if app.config['ENABLE_WEBSERVER']:
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')
last_modified = datetime.datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S') # pylint: disable=C0301
files.append({
'name': filename,
'size': size,
@ -91,11 +91,11 @@ def upload_file():
return jsonify({'error': 'No file selected for upload'}), 400
if not is_valid_filename(file.filename):
return jsonify({'error': 'Invalid filename. Only alphanumeric characters, hyphens, underscores, and periods are allowed.'}), 400
return jsonify({'error': 'Invalid filename. Only alphanumeric characters, hyphens, underscores, and periods are allowed.'}), 400 # pylint: disable=C0301
filename = file.filename
file.save(os.path.join(app.config['UPLOAD_DIRECTORY'], filename))
return jsonify({'success': 'File \'{}\' successfully uploaded'.format(filename)})
return jsonify({'success': 'File \'{}\' successfully uploaded'.format(filename)}) # pylint: disable=C0209
@app.route('/download/<filename>', methods=['GET'])
def download_file(filename):
@ -154,7 +154,7 @@ def delete_file(filename):
return jsonify({'error': 'File not found'}), 404
os.remove(file_path)
return jsonify({'success': 'File \'{}\' successfully deleted'.format(filename)})
return jsonify({'success': 'File \'{}\' successfully deleted'.format(filename)}) # pylint: disable=C0209
@app.route('/list', methods=['GET'])
@ -188,7 +188,7 @@ def list_files():
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')
last_modified = datetime.datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S') # pylint: disable=C0301
files.append({
'name': filename,
'size': size,