|
@@ -43,20 +43,20 @@ URL_MUST_ESCAPE = bytes([
|
|
|
URL_SAFE = bytes(( i for i in range(int('0xff',0)+1) if i not in map(int, URL_MUST_ESCAPE) ))
|
|
|
|
|
|
CLIP_SIZE_LIMIT = 65535
|
|
|
-def validate(filename: str, root='rest/static/files') -> bytes:
|
|
|
+def validate(filename: str, tool: str, root='rest/static/files') -> bytes:
|
|
|
ret = static_file('/'.join([filename,]*2) + '.file', root=root)
|
|
|
if isinstance(ret, HTTPError):
|
|
|
- return abort(404, f"No such paste: {filename}")
|
|
|
+ return abort(404, f"No such `{tool.title()}`: {filename}")
|
|
|
|
|
|
if ret.content_length > CLIP_SIZE_LIMIT:
|
|
|
- return abort(418, f"Paste size exceeds {CLIP_SIZE_LIMIT}")
|
|
|
+ return abort(418, f"{tool.title()} size exceeds {CLIP_SIZE_LIMIT}")
|
|
|
|
|
|
content: bytes = ret.body.read() if isinstance(ret.body, BufferedReader) else ret.body.encode('utf-8')
|
|
|
|
|
|
- _bytes = blake(content, person='clip'.encode('utf-8'))
|
|
|
+ _bytes = blake(content, person=tool.encode('utf-8'))
|
|
|
_b32 = bytes_to_base32(_bytes)
|
|
|
if _b32 != filename:
|
|
|
- return abort(410, f"Paste content differs")
|
|
|
+ return abort(410, f"{tool.title()} content differs")
|
|
|
return content
|
|
|
|
|
|
|
|
@@ -86,9 +86,14 @@ def validate_file(filename: str, root: str = 'rest/static/files', download=True,
|
|
|
name = get_filename(filename)
|
|
|
mimetype = mimetype if mimetype and mimetype is not True else get_file_mimetype(name)
|
|
|
|
|
|
- ret = static_file(f'{path}.file', root=root, download=name if name and download else download, mimetype=mimetype)
|
|
|
+ ret = static_file(
|
|
|
+ f'{path}.file',
|
|
|
+ root=root,
|
|
|
+ download=name if name and download else download,
|
|
|
+ mimetype='auto' if mimetype is True else mimetype
|
|
|
+ )
|
|
|
if isinstance(ret, HTTPError):
|
|
|
- return abort(404, f"No such upload: {filename}")
|
|
|
+ return abort(404, f"No such `Upload`: {filename}")
|
|
|
|
|
|
_bytes = blake_file(f'{path}.file', person='upload'.encode('utf-8'), root=root)
|
|
|
_b32 = bytes_to_base32(_bytes)
|