Browse Source

bottle-sqlite not working - could be python version

Pi 4 months ago
parent
commit
1b65f75153
3 changed files with 10 additions and 13 deletions
  1. 1 0
      docker-compose.yml
  2. 9 12
      rest/pyapi.py
  3. 0 1
      rest/requirements.txt

+ 1 - 0
docker-compose.yml

@@ -89,6 +89,7 @@ services:
       context: .
       dockerfile: rest/Dockerfile
     volumes:
+      - ./util-sqlpage/util.db:/usr/src/app/util.db:ro
       - ./files:/usr/src/app/rest/static/files
     expose:
       - 6772

+ 9 - 12
rest/pyapi.py

@@ -21,11 +21,7 @@ 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)
+from sqlite3 import connect, Row
 
 SCHEME = "https://"
 HOST = ""
@@ -92,24 +88,25 @@ 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')
+@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"""
+    con = connect('util.db')
+    try:
+        ret: Row = con.cursor().execute(f"""
 SELECT content
 FROM clip
 WHERE hash = '{hash}'
 LIMIT 1;
-""").fetchall()[0]
-    # if len(ret):
-    #     print(ret[0].keys())
+""").fetchall()[0][0].encode('utf-8')
+    finally:
+        con.close()
    
     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'
@@ -125,7 +122,7 @@ LIMIT 1;
     #     headers['Content-Type'] = mimetype
     #lm = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(created))
     #headers['Last-Modified'] = lm
-    return HTTPResponse(ret[0].encode('utf8'), **headers)
+    return HTTPResponse(ret, **headers)
 
 @route('/upload', method=['GET', 'POST'])
 def upload():

+ 0 - 1
rest/requirements.txt

@@ -1,5 +1,4 @@
 bottle
-bottle-sqlite
 cherrypy
 base32-lib
 lxml