|
@@ -53,86 +53,21 @@ def send_static(filename):
|
|
|
return static_file(filename, root='rest/static')
|
|
|
|
|
|
|
|
|
-@route('/clip', method=['GET', 'POST'])
|
|
|
-def clip():
|
|
|
-
|
|
|
- if request.method == 'GET':
|
|
|
- _hash = request.params.hash
|
|
|
- if _hash:
|
|
|
- _hash = normalize_base32(_hash)
|
|
|
- content = validate(_hash, 'clip', root='rest/static/files').decode('utf-8')
|
|
|
- else:
|
|
|
- content = None
|
|
|
- link = f'{LOCATION}/clip/{_hash}' if content else f'{LOCATION}/clip'
|
|
|
-
|
|
|
- response.content_type = 'text/html; charset=utf-8'
|
|
|
- form = template(
|
|
|
- 'form-clip',
|
|
|
- action='/clip',
|
|
|
- method='post',
|
|
|
- content=content,
|
|
|
- disabled=True if content else False
|
|
|
- )
|
|
|
- return template(
|
|
|
- 'paste',
|
|
|
- form=form,
|
|
|
- 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
|
|
|
- )
|
|
|
-
|
|
|
- if request.method == 'POST':
|
|
|
- content = validate_parameter(request, 'paste')
|
|
|
- if request.params.copy != 'true':
|
|
|
- _b32 = save(content, 'clip', LOCATION, root='rest/static/files')
|
|
|
- return redirect(f'/clip?hash={_b32}')
|
|
|
-
|
|
|
- response.content_type = 'text/html; charset=utf-8'
|
|
|
- form = template(
|
|
|
- 'form-clip',
|
|
|
- action='/clip',
|
|
|
- method='post',
|
|
|
- content=content,
|
|
|
- disabled=False
|
|
|
- )
|
|
|
- link = f'{LOCATION}/clip'
|
|
|
- return template(
|
|
|
- 'paste',
|
|
|
- form=form,
|
|
|
- qr=f'{LOCATION}/static/clip/qr.svg',
|
|
|
- link=link,
|
|
|
- disabled=False,
|
|
|
- download=None
|
|
|
- )
|
|
|
-
|
|
|
-@route('/<route:re:(clip|upload|goto)>/open')
|
|
|
+@route('/<route:re:(upload|goto)>/open')
|
|
|
def _get_clip(route):
|
|
|
return template('form-open', tool=route, action=f'/{route}', method='get')
|
|
|
|
|
|
-@route('/clip/<filename:path>', method='GET')
|
|
|
-def get_clip(filename):
|
|
|
- ext = 'file'
|
|
|
- if filename and filename.endswith('.qr'):
|
|
|
- filename, ext = filename.split('.', 1)
|
|
|
-
|
|
|
- filename = filename and normalize_base32(filename)
|
|
|
- path = f'{filename}/{filename}.{ext}'
|
|
|
-
|
|
|
- if ext == 'qr':
|
|
|
- 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':
|
|
|
- # TODO: return a form with timeout to a GET instead ?
|
|
|
- return redirect(f'/clip?hash={filename}')
|
|
|
-
|
|
|
- ret = validate(filename, 'clip', root='rest/static/files')
|
|
|
- if isinstance(ret, HTTPError):
|
|
|
- return ret
|
|
|
+@route('/<route:clip/open')
|
|
|
+def _get_clip(route):
|
|
|
+ return redirect(f'/clip/open.sql')
|
|
|
|
|
|
- return static_file(path, root='rest/static/files', download=True)
|
|
|
+@route('/clip', method=['GET', 'POST'])
|
|
|
+def clip():
|
|
|
+ return redirect(f'/clip.sql')
|
|
|
|
|
|
+@route('/clip/<filename:path>', method='GET')
|
|
|
+def get_clip(filename):
|
|
|
+ return redirect(f'/clip.sql?hash={filename}')
|
|
|
|
|
|
@route('/upload', method=['GET', 'POST'])
|
|
|
def upload():
|