You've already forked KemoFureApi
uncommited changes
This commit is contained in:
7
modules/JapariSling/classes/construct_level.py
Normal file
7
modules/JapariSling/classes/construct_level.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from typing import List
|
||||
from .construct_serialized import ConstructSerialized
|
||||
|
||||
class ConstructLevel:
|
||||
Name : str
|
||||
Description : str
|
||||
Objects : List[ConstructSerialized]
|
||||
13
modules/JapariSling/classes/construct_serialized.py
Normal file
13
modules/JapariSling/classes/construct_serialized.py
Normal file
@@ -0,0 +1,13 @@
|
||||
class SVector3:
|
||||
x : float
|
||||
y : float
|
||||
z : float
|
||||
|
||||
class ConstructSerialized:
|
||||
Id : int
|
||||
Variant : int
|
||||
Position : SVector3
|
||||
Rotation : SVector3
|
||||
Width : float
|
||||
Height : float
|
||||
Properties : int
|
||||
15
modules/JapariSling/database.py
Normal file
15
modules/JapariSling/database.py
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
from .endpoints.get import Get
|
||||
from .endpoints.upload import Upload
|
||||
|
||||
class Database:
|
||||
|
||||
def __init__(self, api) -> None:
|
||||
app = api.app
|
||||
if "JapariSling" in app.databases:
|
||||
del app.databases["JapariSling"]
|
||||
|
||||
app.databases["JapariSling"] = self
|
||||
|
||||
api.add_resource(Upload, "/JapariSling/Upload")
|
||||
api.add_resource(Get, "/JapariSling/Get")
|
||||
23
modules/JapariSling/endpoints/get.py
Normal file
23
modules/JapariSling/endpoints/get.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import json
|
||||
from flask_restful import Resource
|
||||
from flask import abort, request, current_app as app
|
||||
|
||||
class Get(Resource):
|
||||
def get(self):
|
||||
dir_name = os.path.join(app.root_path, 'data', 'JapariSling')
|
||||
files = [json.loads(read_file(os.path.join(dir_name, f))) for f in os.listdir(dir_name) if os.path.isfile(os.path.join(dir_name, f))]
|
||||
files = files[:10]
|
||||
files = {"levels": files}
|
||||
|
||||
response = app.response_class(
|
||||
response = json.dumps(files),
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
|
||||
def read_file(path):
|
||||
with open(path, 'r') as f:
|
||||
return f.read()
|
||||
29
modules/JapariSling/endpoints/upload.py
Normal file
29
modules/JapariSling/endpoints/upload.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import json
|
||||
from flask_restful import Resource
|
||||
from ..classes.construct_level import ConstructLevel
|
||||
from flask import abort, request, current_app as app
|
||||
|
||||
class Upload(Resource):
|
||||
def post(self):
|
||||
cl = request.content_length
|
||||
if cl is not None and cl > 1024:
|
||||
abort(413)
|
||||
|
||||
content = request.json
|
||||
|
||||
if "Name" not in content:
|
||||
abort(400)
|
||||
|
||||
filename = os.path.join(app.root_path, 'data', 'JapariSling', content["Name"] + '.json')
|
||||
|
||||
with open(filename, "wt") as text_file:
|
||||
text_file.write(json.dumps(content, ensure_ascii=False, indent=1))
|
||||
|
||||
response = app.response_class(
|
||||
response="level uploaded",
|
||||
status=200,
|
||||
mimetype='text/plain'
|
||||
)
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
Reference in New Issue
Block a user