Add thumbnail support!
This commit is contained in:
parent
44b79518a5
commit
d73c7e44d5
6 changed files with 146 additions and 9 deletions
|
@ -1,4 +1,16 @@
|
|||
import uvicorn
|
||||
import signal
|
||||
|
||||
config = uvicorn.Config("customiwmserver.main:app", host="0.0.0.0", port=8001, reload=True)
|
||||
server = uvicorn.Server(config)
|
||||
|
||||
def exit_now(signum, frame):
|
||||
global server
|
||||
print("STOPPING")
|
||||
server.handle_exit(signum, frame)
|
||||
|
||||
signal.signal(signal.SIGINT, exit_now)
|
||||
signal.signal(signal.SIGTERM, exit_now)
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("customiwmserver.main:app", host="0.0.0.0", port=8001, reload=True)
|
||||
server.run()
|
||||
|
|
|
@ -11,7 +11,7 @@ from . import data_types as types
|
|||
from . import database as db
|
||||
from . import hook_system
|
||||
from . import hooks
|
||||
|
||||
from . import object_storage
|
||||
import pymongo
|
||||
|
||||
app = FastAPI()
|
||||
|
@ -28,8 +28,7 @@ async def http_exception_handler(request, exc):
|
|||
return PlainTextResponse(
|
||||
f"[{exc.status_code}] {str(exc.detail)}", status_code=exc.status_code
|
||||
)
|
||||
|
||||
|
||||
|
||||
## Users
|
||||
|
||||
|
||||
|
@ -323,6 +322,7 @@ async def upload_map(
|
|||
userData = types.User(**authcheck[1])
|
||||
ID = len(list(db.maps_collection.find({}))) + 1
|
||||
MapCode = db.id_to_mapcode(ID)
|
||||
await object_storage.upload_thumbnail(file, ID)
|
||||
db.maps_collection.insert_one(
|
||||
{
|
||||
**types.Map(
|
||||
|
@ -369,6 +369,7 @@ async def upload_map(
|
|||
],
|
||||
).dict()
|
||||
}
|
||||
|
||||
)
|
||||
return {"MapCode": MapCode}
|
||||
# raise HTTPException(501)
|
||||
|
@ -587,9 +588,10 @@ async def featuredlist():
|
|||
async def followcheck():
|
||||
"""Check, if creators that the user follows uploaded new levels."""
|
||||
# FIXME: Stub
|
||||
raise HTTPException(404, detail="Not available due to follows not being implemented.")
|
||||
|
||||
return 0
|
||||
|
||||
def start():
|
||||
"""Launched with `poetry run start` at root level"""
|
||||
uvicorn.run("customiwmserver.main:app", host="0.0.0.0", port=8001, reload=True)
|
||||
from . import __main__
|
||||
__main__.server.run()
|
||||
# uvicorn.run("customiwmserver.main:app", host="0.0.0.0", port=8001, reload=True)
|
||||
|
|
29
customiwmserver/object_storage.py
Normal file
29
customiwmserver/object_storage.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from minio import Minio
|
||||
from os import getenv
|
||||
import json
|
||||
import io
|
||||
|
||||
print("---")
|
||||
print(getenv("S3_ENDPOINT"),
|
||||
getenv("S3_ACCESS_KEY"),
|
||||
getenv("S3_SECRET_KEY"),
|
||||
json.loads(getenv("S3_IS_SECURE", "false")), sep="\n"
|
||||
)
|
||||
print("---")
|
||||
|
||||
client = Minio(
|
||||
getenv("S3_ENDPOINT"),
|
||||
access_key=getenv("S3_ACCESS_KEY"),
|
||||
secret_key=getenv("S3_SECRET_KEY"),
|
||||
secure=json.loads(getenv("S3_IS_SECURE", "false")),
|
||||
)
|
||||
|
||||
ThumbsBucket = "iwm-user-thumbnails"
|
||||
|
||||
if not client.bucket_exists(ThumbsBucket):
|
||||
client.make_bucket(ThumbsBucket)
|
||||
|
||||
async def upload_thumbnail(data, levelID):
|
||||
# file = io.BytesIO(await data.read())
|
||||
client.put_object(ThumbsBucket, f"{levelID}.png", data.file, length=-1, part_size=10*1024*1024)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue