added more logging for the helpers and the frontend

This commit is contained in:
Jan Friedli 2020-08-30 14:44:41 +02:00 committed by jfriedli
parent 7a252eaa90
commit 58709ebca0
2 changed files with 12 additions and 1 deletions

View file

@ -27,8 +27,10 @@ def download_file(key: str, secret: str, filename: str):
file_removal_scheduler.run_file_removal_job(current_app.config['UPLOAD_FOLDER'])
if not os.path.exists(complete_path):
current_app.logger.error('Non existing file requested')
return redirect(url_for('routes.upload_file'))
if hmac.compare_digest(utils.hash_file(complete_path, secret), key) is False:
current_app.logger.error('Non matching digest for file')
return redirect(url_for('routes.upload_file'))
@after_this_request
@ -47,28 +49,33 @@ def upload_file():
if request.method == 'POST':
if 'file' not in request.files: # check if the post request has the file part
flash('No file part')
current_app.logger.error('Missing file part in upload')
return redirect(request.url)
uploaded_file = request.files['file']
if not uploaded_file.filename:
flash('No selected file')
current_app.logger.error('Missing filename in upload')
return redirect(request.url)
try:
filename, filepath = utils.save_file(uploaded_file, current_app.config['UPLOAD_FOLDER'])
except ValueError:
flash('Invalid Filename')
current_app.logger.error('Invalid Filename in upload')
return redirect(request.url)
parser, mime = utils.get_file_parser(filepath)
if parser is None:
flash('The type %s is not supported' % mime)
current_app.logger.error('Unsupported type %s', mime)
return redirect(url_for('routes.upload_file'))
meta = parser.get_meta()
if parser.remove_all() is not True:
flash('Unable to clean %s' % mime)
current_app.logger.error('Unable to clean %s', mime)
return redirect(url_for('routes.upload_file'))
key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER'])