mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Adds delete_file util (#239)
This commit is contained in:
@@ -163,11 +163,8 @@ def admin_files(chalid):
|
|||||||
return jsonify(json_data)
|
return jsonify(json_data)
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if request.form['method'] == "delete":
|
if request.form['method'] == "delete":
|
||||||
f = Files.query.filter_by(id=request.form['file']).first_or_404()
|
utils.delete_file(request.form['file'])
|
||||||
upload_folder = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'])
|
|
||||||
if os.path.exists(os.path.join(upload_folder, f.location)): # Some kind of os.path.isfile issue on Windows...
|
|
||||||
os.unlink(os.path.join(upload_folder, f.location))
|
|
||||||
db.session.delete(f)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
db.session.close()
|
db.session.close()
|
||||||
return '1'
|
return '1'
|
||||||
|
|||||||
@@ -349,6 +349,16 @@ def upload_file(file, chalid):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def delete_file(filename):
|
||||||
|
f = Files.query.filter_by(id=filename).first_or_404()
|
||||||
|
upload_folder = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'])
|
||||||
|
if os.path.exists(os.path.join(upload_folder, f.location)): # Some kind of os.path.isfile issue on Windows...
|
||||||
|
os.unlink(os.path.join(upload_folder, f.location))
|
||||||
|
db.session.delete(f)
|
||||||
|
db.session.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@cache.memoize()
|
@cache.memoize()
|
||||||
def get_config(key):
|
def get_config(key):
|
||||||
config = Config.query.filter_by(key=key).first()
|
config = Config.query.filter_by(key=key).first()
|
||||||
|
|||||||
Reference in New Issue
Block a user