29 lines
860 B
Python
29 lines
860 B
Python
|
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
|