-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhandler.py
More file actions
28 lines (24 loc) · 871 Bytes
/
handler.py
File metadata and controls
28 lines (24 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
import sys
import io
from manifest import manifest
def log(str):
print(str, file=sys.stderr)
def handle(body):
log(f"Body: {body}")
data = {}
if body != '':
data = json.loads(body)
log(f"data: {data}")
if 'view' in data.keys():
view = __import__('views.' + data['view'], fromlist=[None])
return bytes(json.dumps(view.render(data.get('data', []), data.get('props', {}))), 'utf-8')
elif 'listener' in data.keys():
listener = __import__('listeners.' + data['listener'], fromlist=[None])
listener.run(data.get('props', {}), data.get('event', {}), data['api'])
return bytes("", 'utf-8')
elif 'resource' in data.keys():
with open("./resources/" + data['resource'], 'rb') as file:
return file.read()
else:
return bytes(json.dumps(manifest), 'utf-8')