|
@@ -23,6 +23,10 @@ DOMAIN = "shandan.one"
|
|
|
PORT = ""
|
|
|
LOCATION = SCHEME + (f"{HOST}." if HOST else "") + DOMAIN + (f":{PORT}" if PORT else "")
|
|
|
|
|
|
+@route('/static/<filename:path>')
|
|
|
+def send_static(filename):
|
|
|
+ return static_file(filename, root='rest/static')
|
|
|
+
|
|
|
|
|
|
@route('/clip', method=['GET', 'POST'])
|
|
|
def clip():
|
|
@@ -47,7 +51,7 @@ def clip():
|
|
|
return template(
|
|
|
'paste',
|
|
|
form=form,
|
|
|
- qr=f'{LOCATION}/clip/{_hash}.qr' if content else f'{LOCATION}/grocery/static/clip-qr.svg',
|
|
|
+ qr=f'{LOCATION}/clip/{_hash}.qr' if content else f'{LOCATION}/static/clip-qr.svg',
|
|
|
link=link,
|
|
|
disabled=True if content else False,
|
|
|
download=f'/clip/{_hash}' if content else None
|
|
@@ -56,7 +60,7 @@ def clip():
|
|
|
if request.method == 'POST':
|
|
|
content = validate_parameter(request, 'paste')
|
|
|
if request.params.copy != 'true':
|
|
|
- _b32 = save(content, LOCATION)
|
|
|
+ _b32 = save(content, LOCATION, root='rest/static/files')
|
|
|
return redirect(f'/clip?hash={_b32}')
|
|
|
|
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
@@ -71,7 +75,7 @@ def clip():
|
|
|
return template(
|
|
|
'paste',
|
|
|
form=form,
|
|
|
- qr=f'{LOCATION}/grocery/static/clip-qr.svg',
|
|
|
+ qr=f'{LOCATION}/static/clip-qr.svg',
|
|
|
link=link,
|
|
|
disabled=False,
|
|
|
download=None
|
|
@@ -88,7 +92,7 @@ def get_clip(filename):
|
|
|
path = f'{filename}/{filename}.{ext}'
|
|
|
|
|
|
if ext == 'qr':
|
|
|
- return static_file(path, root='rest/static', mimetype='image/svg+xml')
|
|
|
+ return static_file(path, root='rest/static/files', mimetype='image/svg+xml')
|
|
|
|
|
|
filename = filename and normalize_base32(filename)
|
|
|
if not request.params.raw.lower() == 'true':
|
|
@@ -99,7 +103,7 @@ def get_clip(filename):
|
|
|
if isinstance(ret, HTTPError):
|
|
|
return ret
|
|
|
|
|
|
- return static_file(path, root='rest/static')
|
|
|
+ return static_file(path, root='rest/static/files')
|
|
|
|
|
|
|
|
|
@route('/upload', method=['GET', 'POST'])
|
|
@@ -113,8 +117,9 @@ def upload():
|
|
|
size = get_file_size(_hash)
|
|
|
name = get_filename(_hash)
|
|
|
mimetype = get_file_mimetype(name)
|
|
|
+ validate_file(_hash, root='rest/static/files', download=True, mimetype=mimetype)
|
|
|
if mimetype is not True and mimetype.startswith('text'):
|
|
|
- mimetype = None if size > CLIP_SIZE_LIMIT else mimetype
|
|
|
+ mimetype = None if size and size > CLIP_SIZE_LIMIT else mimetype
|
|
|
|
|
|
link = f'{LOCATION}/upload/{_hash}' if _hash else f'{LOCATION}/upload'
|
|
|
response.content_type = 'text/html; charset=utf-8'
|
|
@@ -124,7 +129,7 @@ def upload():
|
|
|
return template(
|
|
|
'upload',
|
|
|
form=form,
|
|
|
- qr=f'{LOCATION}/upload/{_hash}.qr' if _hash else f'{LOCATION}/grocery/static/upload-qr.svg',
|
|
|
+ qr=f'{LOCATION}/upload/{_hash}.qr' if _hash else f'{LOCATION}/static/upload-qr.svg',
|
|
|
link=link,
|
|
|
mimetype=mimetype,
|
|
|
disabled=disabled
|
|
@@ -139,7 +144,7 @@ def upload():
|
|
|
if len(upload.file.read()) == 0:
|
|
|
return abort(400, "File is empty")
|
|
|
|
|
|
- _b32 = save_upload(upload.raw_filename, LOCATION, upload.file, root='rest/static')
|
|
|
+ _b32 = save_upload(upload.raw_filename, LOCATION, upload.file, root='rest/static/files')
|
|
|
return redirect(f'/upload?hash={_b32}')
|
|
|
|
|
|
|
|
@@ -153,7 +158,7 @@ def get_upload(filename):
|
|
|
path = f'{filename}/{filename}.{ext}'
|
|
|
|
|
|
if ext == 'qr':
|
|
|
- return static_file(path, root='rest/static', mimetype='image/svg+xml')
|
|
|
+ return static_file(path, root='rest/static/files', mimetype='image/svg+xml')
|
|
|
|
|
|
download = True
|
|
|
mimetype = True
|
|
@@ -161,7 +166,7 @@ def get_upload(filename):
|
|
|
download = False
|
|
|
mimetype = request.params.mimetype or None
|
|
|
|
|
|
- return validate_file(filename, download=download, mimetype=mimetype)
|
|
|
+ return validate_file(filename, root='rest/static/files', download=download, mimetype=mimetype)
|
|
|
|
|
|
|
|
|
@route('/goto', method=['GET', 'POST'])
|
|
@@ -171,7 +176,7 @@ def goto():
|
|
|
_hash = request.params.hash
|
|
|
if _hash:
|
|
|
_hash = normalize_base32(_hash)
|
|
|
- content = validate(_hash).decode('utf-8')
|
|
|
+ content = validate(_hash, root='rest/static/files').decode('utf-8')
|
|
|
else:
|
|
|
content = None
|
|
|
|
|
@@ -203,7 +208,7 @@ def goto():
|
|
|
return template(
|
|
|
'goto',
|
|
|
form=form,
|
|
|
- qr=f'{LOCATION}/goto/{_hash}.qr' if content else f'{LOCATION}/grocery/static/goto-qr.svg',
|
|
|
+ qr=f'{LOCATION}/goto/{_hash}.qr' if content else f'{LOCATION}/static/goto-qr.svg',
|
|
|
link=link,
|
|
|
disabled=disabled,
|
|
|
preview=preview,
|
|
@@ -211,7 +216,7 @@ def goto():
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
content = validate_parameter(request, 'url')
|
|
|
- _b32 = save(content, LOCATION)
|
|
|
+ _b32 = save(content, LOCATION, root='rest/static/files')
|
|
|
|
|
|
|
|
|
_ = validate_url(content.decode('utf-8'))
|
|
@@ -228,7 +233,7 @@ def redirect_goto(filename):
|
|
|
path = f'{filename}/{filename}.{ext}'
|
|
|
|
|
|
if ext == 'qr':
|
|
|
- return static_file(path, root='rest/static', mimetype='image/svg+xml')
|
|
|
+ return static_file(path, root='rest/static/files', mimetype='image/svg+xml')
|
|
|
|
|
|
return redirect(f'/goto?hash={filename}&go=true')
|
|
|
|