-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.py
More file actions
44 lines (36 loc) · 1.3 KB
/
index.py
File metadata and controls
44 lines (36 loc) · 1.3 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from fastapi import FastAPI, Request, Response
from .auth import validate_session, validate_token,signin,signout
from .records import (
create_record,
get_all_records,
find_record,
update_record,
delete_record,
upload_container,
fetch_layouts
)
# List of method names that do not require token/session validation.
controllers_to_skip_validation = ["signin"]
# Mapping of method names to their corresponding handler functions
METHOD_HANDLERS = {
"createRecord": create_record,
"getAllRecords": get_all_records,
"findRecord": find_record,
"updateRecord": update_record,
"deleteRecord": delete_record,
"signin": signin,
"signout" : signout,
"uploadContainer":upload_container,
"fetchLayouts": fetch_layouts
}
async def data_api(req: Request, res: Response):
method = req.state.body.get("method")
if method not in METHOD_HANDLERS:
return {"error": f"Invalid method ${method}"}
if method not in controllers_to_skip_validation:
# If the method is not in the skip list, apply the validateToken first
await validate_token(req)
# After token validation, apply the validateSession middleware
await validate_session(req)
handler = METHOD_HANDLERS[method]
return await handler(req)