diff options
| author | altaf-creator <dev@altafcreator.com> | 2025-12-02 16:19:10 +0700 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2025-12-02 16:19:10 +0700 |
| commit | b8155a7854182bbf1bf750226bb62fc38b6bbcaf (patch) | |
| tree | e3d045a02b815f64d5582e5485b747b9e3c7c5db | |
| parent | a4541c9585f926aeb07ab390a8e40cead1eed817 (diff) | |
API /info use cookie
| -rw-r--r-- | backend/main.py | 7 | ||||
| -rw-r--r-- | frontend/main.js | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/backend/main.py b/backend/main.py index 9b4ac1c..20078d3 100644 --- a/backend/main.py +++ b/backend/main.py @@ -386,8 +386,10 @@ def finish_laundry(data: FinishRequestData, response: fastapi.Response, session_ # --- get information from uri search query @app.post("/info") def uri_to_information(data: InformationRequestData, response: fastapi.Response, auth_block: Annotated[str | None, fastapi.Cookie()] = None): + info = None try: - info = URI_TO_MACHINES[data.machine_id] + if data.machine_id: + info = URI_TO_MACHINES[data.machine_id] except KeyError: response.status_code = fastapi.status.HTTP_404_NOT_FOUND return "INVALID machine ID/URI" @@ -396,6 +398,9 @@ def uri_to_information(data: InformationRequestData, response: fastapi.Response, if auth_block != info[0]: response.status_code = fastapi.status.HTTP_403_FORBIDDEN return "UNAUTHORISED to view information" + if not info: + info = [auth_block, None] + else: authenticate_block(response, block=info[0]) diff --git a/frontend/main.js b/frontend/main.js index 65a1d93..0e084ab 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -74,7 +74,7 @@ async function information(urlParam = null) { headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ "machine_id": urlParam ? urlParam : await cookieStore.get({name: "auth_block", url: API_URL}) }) + body: JSON.stringify({ "machine_id": urlParam ? urlParam : null }), }); const block = await response.json()["block"]; |
