Browse Source

Allow uploading files

tags/1.8.8
Leonie 3 months ago
parent
commit
21646754b8
2 changed files with 30 additions and 1 deletions
  1. +28
    -0
      backend.py
  2. +2
    -1
      requirements.txt

+ 28
- 0
backend.py View File

@@ -12,6 +12,7 @@ import uuid
import requests
import subprocess
import urllib.parse
from PIL import Image

r = redis.StrictRedis(host='localhost', port=6379, db=0)

@@ -505,4 +506,31 @@ def setreversed(adminkey):
else:
return "{\"action\": \"error\"}"

@post("/api/v1/admin/banner/<adminkey>")
def uploadbanner(adminkey):
response.headers['Access-Control-Allow-Origin'] = '*'
response.content_type = "application/json"
banner = request.files.get("banner") # pylint: disable=no-member
name, ext = os.path.splitext(banner.filename) # pylint: disable=unused-variable
if ext not in ('.jpg'):
return "{\"action\": \"error\"}"
else:
if adminkey == ADMINKEY:
try:
banner.save("banners/")
im = Image.open("banners/"+filename+"."+ext)
width, height = im.size
if width == 299 and height == 118:
return json.dumps({"login": "ok", "action": "success"})
else:
try:
os.remove("banners/"+filename+"."+ext)
except:
pass
return "{\"action\": \"error\"}"
except:
return "{\"action\": \"error\"}"
else:
return "{\"action\": \"error\"}"

run(server="tornado",port=9000,host="0.0.0.0")

+ 2
- 1
requirements.txt View File

@@ -3,4 +3,5 @@ tornado
feedparser
Mastodon.py
redis
colorthief
colorthief
Pillow

Loading…
Cancel
Save