Working server
This commit is contained in:
parent
929428279c
commit
0c29750cf9
@ -2,6 +2,7 @@ import json
|
||||
from pathlib import Path
|
||||
|
||||
import falcon
|
||||
from falcon_multipart.middleware import MultipartMiddleware
|
||||
|
||||
from .tools import JsonRequest, JsonResponse, error_handler
|
||||
from .controllers import *
|
||||
@ -18,7 +19,9 @@ class AboutResource():
|
||||
resp.body = json.dumps(r, indent=4)
|
||||
|
||||
|
||||
app = application = falcon.API(request_type=JsonRequest, response_type=JsonResponse)
|
||||
app = application = falcon.API(middleware=[MultipartMiddleware()],
|
||||
request_type=JsonRequest,
|
||||
response_type=JsonResponse)
|
||||
app.add_error_handler(ValueError, error_handler)
|
||||
app.add_route("/", AboutResource())
|
||||
|
||||
@ -30,4 +33,5 @@ app.add_route("/Videos/{VideoUuid}/Streams/{StreamId}", StreamCollection())
|
||||
|
||||
FilesStoragePath = Path("files")
|
||||
FilesStoragePath.mkdir(parents=True, exist_ok=True)
|
||||
app.add_route("/File/{FileId}", FileCollection(FilesStoragePath))
|
||||
app.add_route("/Files/{FileId}", FileCollection(FilesStoragePath))
|
||||
app.add_route("/Files", FileCollection(FilesStoragePath))
|
||||
|
@ -1,6 +1,6 @@
|
||||
from enum import IntEnum
|
||||
from pathlib import Path
|
||||
from falcon import HTTPNotFound
|
||||
from falcon import HTTPNotFound, HTTP_CREATED
|
||||
|
||||
class TaskStatus(IntEnum):
|
||||
Created = 0
|
||||
@ -24,9 +24,9 @@ streams = [
|
||||
"StreamId":0,
|
||||
"MimeType":"application/x-shockwave-flash",
|
||||
"Uris":[
|
||||
{"Uri":"http://10.42.0.1:8080/File/00000000.swf"},
|
||||
{"Uri":"http://10.42.0.1:8080/File/00015000.swf"},
|
||||
{"Uri":"http://10.42.0.1:8080/File/00030000.swf"}
|
||||
{"Uri":"http://10.42.0.1:8080/Files/00000000.swf"},
|
||||
{"Uri":"http://10.42.0.1:8080/Files/00015000.swf"},
|
||||
{"Uri":"http://10.42.0.1:8080/Files/00030000.swf"}
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -88,3 +88,9 @@ class FileCollection():
|
||||
resp.body= f.read()
|
||||
except FileNotFoundError:
|
||||
raise HTTPNotFound()
|
||||
def on_post(self, req, resp):
|
||||
f = req.get_param("file")
|
||||
with open(self.path/f.filename, "wb") as fo:
|
||||
fo.write(f.file.read())
|
||||
resp.status = HTTP_CREATED
|
||||
resp.content_location = f"/Files/{f.filename}"
|
||||
|
Loading…
Reference in New Issue
Block a user