fix linter errors
Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
parent
f0db0112b2
commit
547d6865a7
1 changed files with 10 additions and 10 deletions
20
app.py
20
app.py
|
@ -1,14 +1,14 @@
|
||||||
|
# pylint: disable=C0114
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import uuid
|
|
||||||
from flask import Flask, request, jsonify, send_from_directory, render_template
|
|
||||||
import datetime
|
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')
|
app = Flask(__name__, template_folder='templates')
|
||||||
swagger = Swagger(app)
|
swagger = Swagger(app)
|
||||||
app.config['UPLOAD_DIRECTORY'] = os.environ.get('UPLOAD_DIRECTORY', '/uploads')
|
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'
|
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')
|
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))
|
return bool(re.match(VALID_FILENAME_REGEX, filename))
|
||||||
|
|
||||||
if app.config['ENABLE_WEBSERVER']:
|
if app.config['ENABLE_WEBSERVER']:
|
||||||
|
@ -31,7 +31,7 @@ if app.config['ENABLE_WEBSERVER']:
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
stats = os.stat(file_path)
|
stats = os.stat(file_path)
|
||||||
size = stats.st_size
|
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({
|
files.append({
|
||||||
'name': filename,
|
'name': filename,
|
||||||
'size': size,
|
'size': size,
|
||||||
|
@ -91,11 +91,11 @@ def upload_file():
|
||||||
return jsonify({'error': 'No file selected for upload'}), 400
|
return jsonify({'error': 'No file selected for upload'}), 400
|
||||||
|
|
||||||
if not is_valid_filename(file.filename):
|
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
|
filename = file.filename
|
||||||
file.save(os.path.join(app.config['UPLOAD_DIRECTORY'], 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'])
|
@app.route('/download/<filename>', methods=['GET'])
|
||||||
def download_file(filename):
|
def download_file(filename):
|
||||||
|
@ -154,7 +154,7 @@ def delete_file(filename):
|
||||||
return jsonify({'error': 'File not found'}), 404
|
return jsonify({'error': 'File not found'}), 404
|
||||||
|
|
||||||
os.remove(file_path)
|
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'])
|
@app.route('/list', methods=['GET'])
|
||||||
|
@ -188,7 +188,7 @@ def list_files():
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
stats = os.stat(file_path)
|
stats = os.stat(file_path)
|
||||||
size = stats.st_size
|
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({
|
files.append({
|
||||||
'name': filename,
|
'name': filename,
|
||||||
'size': size,
|
'size': size,
|
||||||
|
|
Reference in a new issue