|
@@ -4,19 +4,29 @@
|
|
|
|
|
|
|
|
|
from io import BytesIO
|
|
|
+import time
|
|
|
from bottle import (
|
|
|
+ Bottle,
|
|
|
+ default_app,
|
|
|
route, request, response,
|
|
|
redirect, abort,
|
|
|
template, static_file,
|
|
|
+ HTTPResponse,
|
|
|
)
|
|
|
from linkpreview import link_preview
|
|
|
|
|
|
from .validate import CLIP_SIZE_LIMIT, get_file_mimetype, get_file_size, get_filename, validate_file
|
|
|
-from .hash_util import normalize_base32, blake, bytes_to_base32
|
|
|
+from .hash_util import B32REGEX, normalize_base32, blake, bytes_to_base32
|
|
|
from .save import save_upload
|
|
|
from .qr import get_qr_code
|
|
|
from json import dumps, load
|
|
|
|
|
|
+app = default_app()
|
|
|
+from bottle.ext import sqlite
|
|
|
+from sqlite3 import Row
|
|
|
+plugin = sqlite.Plugin(dbfile='/tmp/test.db')
|
|
|
+app.install(plugin)
|
|
|
+
|
|
|
SCHEME = "https://"
|
|
|
HOST = ""
|
|
|
DOMAIN = "shandan.one"
|
|
@@ -82,6 +92,41 @@ def clip(route):
|
|
|
def get_clip(route, filename):
|
|
|
return redirect(f'/{route}.sql?hash={filename}&go=true')
|
|
|
|
|
|
+@app.route(f'/upload/<hash:re:{B32REGEX}{{1,5}}>', method='GET')
|
|
|
+def get_upload(hash, db=None):
|
|
|
+ hash = hash and normalize_base32(hash)
|
|
|
+ ret: Row = db.execute(f"""
|
|
|
+SELECT content
|
|
|
+FROM clip
|
|
|
+WHERE hash = '{hash}'
|
|
|
+LIMIT 1;
|
|
|
+""").fetchall()[0]
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ download = True
|
|
|
+ mimetype = True
|
|
|
+ if request.params.download == "false":
|
|
|
+ download = False
|
|
|
+ mimetype = request.params.mimetype or None
|
|
|
+ response.body = ret
|
|
|
+ headers = {}
|
|
|
+ headers['Content-Length'] = len(ret)
|
|
|
+ fname = 'noddy'
|
|
|
+ headers['Content-Disposition'] = 'attachment; filename="%s"' % fname
|
|
|
+ headers['Content-Encoding'] = 'application/octet-stream'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return HTTPResponse(ret[0].encode('utf8'), **headers)
|
|
|
+
|
|
|
@route('/upload', method=['GET', 'POST'])
|
|
|
def upload():
|
|
|
|
|
@@ -124,25 +169,25 @@ def upload():
|
|
|
return redirect(f'/upload?hash={_b32}')
|
|
|
|
|
|
|
|
|
-@route('/upload/<filename:path>', method='GET')
|
|
|
-def get_upload(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')
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- download = True
|
|
|
- mimetype = True
|
|
|
- if request.params.download == "false":
|
|
|
- download = False
|
|
|
- mimetype = request.params.mimetype or None
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- return validate_file(filename, root='rest/static/files', download=download, mimetype=mimetype)
|
|
|
+
|
|
|
|
|
|
|
|
|
@route('/<any>/', method='GET')
|