add delete endpoint

This commit is contained in:
Michael Grote 2023-04-13 12:19:27 +02:00
parent f9dda355fb
commit a69875aa32

16
app.py
View file

@ -43,9 +43,25 @@ def download_file(filename):
except FileNotFoundError:
return jsonify({'error': 'File not found'}), 404
@app.route('/delete/<filename>', methods=['DELETE'])
def delete_file(filename):
if 'token' not in request.headers:
return jsonify({'error': 'No token supplied'}), 401
if request.headers['token'] != AUTH_TOKEN:
return jsonify({'error': 'Invalid token supplied'}), 401
path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
try:
os.remove(path)
return jsonify({'success': 'File \'{}\' successfully deleted'.format(filename)})
except FileNotFoundError:
return jsonify({'error': 'File not found'}), 404
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
# Upload
# touch ../hallowelt && curl -X POST -H "token: myuploadtoken" -F "file=@../hallowelt" http://docker10.grote.lan:5040/upload
# Download