new short expiring url for files
This commit is contained in:
65
code/app.py
65
code/app.py
@@ -13,7 +13,7 @@ from revprox import ReverseProxied
|
||||
from utils import *
|
||||
|
||||
|
||||
__FLEES_VERSION__ = "20191024.0"
|
||||
__FLEES_VERSION__ = "20191031.0"
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(__name__)
|
||||
config_values = read_config(app)
|
||||
@@ -30,7 +30,8 @@ if 'notifier' in config_values:
|
||||
|
||||
app.secret_key = config_values['app_secret_key']
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
|
||||
with app.app_context():
|
||||
expire_database_create()
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
@@ -351,6 +352,42 @@ def file_delete(name, token, filename):
|
||||
return "OK", 200
|
||||
|
||||
|
||||
@app.route('/file/expiring/<name>/<token>/<expire>/<path:filename>', methods=['GET'])
|
||||
def file_expiring(name, token, expire, filename):
|
||||
(ok,share) = get_share(name, token = token)
|
||||
if not ok:
|
||||
return share
|
||||
full_path = os.path.join(
|
||||
share['path'],
|
||||
secure_filename_hidden(filename)
|
||||
)
|
||||
if not os.path.exists(full_path):
|
||||
return "-1", 403
|
||||
allow_direct = get_or_none('direct_links', share) if get_or_none('pass_hash', share) else False
|
||||
if not allow_direct:
|
||||
return "-1", 403
|
||||
expires = 24 * 3600 * float(expire) + time.time()
|
||||
return set_expiring_file(share, full_path, expires), 200
|
||||
|
||||
|
||||
@app.route('/file/expiring_remove/<name>/<token>/<path:filename>', methods=['GET'])
|
||||
def file_expiring_remove(name, token, filename):
|
||||
(ok,share) = get_share(name, token = token)
|
||||
if not ok:
|
||||
return share
|
||||
full_path = os.path.join(
|
||||
share['path'],
|
||||
secure_filename_hidden(filename)
|
||||
)
|
||||
if not os.path.exists(full_path):
|
||||
return "-1", 403
|
||||
allow_direct = get_or_none('direct_links', share) if get_or_none('pass_hash', share) else False
|
||||
if not allow_direct:
|
||||
return "-1", 403
|
||||
remove_expiring_file(share, full_path)
|
||||
return "OK", 200
|
||||
|
||||
|
||||
@app.route('/file/direct/<name>/<token>/<path:filename>', methods=['GET'])
|
||||
def file_direct(name, token, filename):
|
||||
(ok,share) = get_share(name, token = token)
|
||||
@@ -485,6 +522,27 @@ def logout(name):
|
||||
)
|
||||
|
||||
|
||||
@app.route('/e/<ehash>', methods=['GET'])
|
||||
@app.route('/e/<ehash>/<filename>', methods=['GET'])
|
||||
def download_expiring(ehash, filename = None):
|
||||
file_path, expiring = get_expiring_file(ehash)
|
||||
if not os.path.exists(file_path):
|
||||
return 'No such file', 404
|
||||
if expiring - time.time() < 0:
|
||||
return 'Expired', 404
|
||||
notify({
|
||||
"filename": file_path,
|
||||
"operation": "expiring_download"
|
||||
})
|
||||
if filename == None:
|
||||
filename = os.path.basename(file_path)
|
||||
return send_file(
|
||||
file_path,
|
||||
as_attachment = True,
|
||||
attachment_filename = filename
|
||||
)
|
||||
|
||||
|
||||
@app.route('/direct/<name>/<token>/<path:filename>', methods=['GET'])
|
||||
def download_direct(name,token,filename):
|
||||
(ok,share) = get_share(name, require_auth = False)
|
||||
@@ -932,9 +990,10 @@ def zip_clean():
|
||||
os.remove(os.path.join(app.config['ZIP_FOLDER'],file))
|
||||
|
||||
|
||||
zip_clean()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
zip_clean()
|
||||
app.run(debug=True)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user