Download frontend/src/utils/request.js from leowuming/rag: direct link, hf CLI and curl.
- Browser
- Download file 762 Bytes
-
https://huggingface.co/spaces/leowuming/rag/resolve/main/frontend/src/utils/request.js
- Command line
-
hf download hf://spaces/leowuming/rag/frontend/src/utils/request.js
-
curl -L -o request.js https://huggingface.co/spaces/leowuming/rag/resolve/main/frontend/src/utils/request.js
762 Bytes
| import { AUTH_TOKEN, AUTH_USER } from "./constants"; | |
| // Sets up the base headers for all authenticated requests so that we are able to prevent | |
| // basic spoofing since a valid token is required and that cannot be spoofed | |
| export function userFromStorage() { | |
| try { | |
| const userString = window.localStorage.getItem(AUTH_USER); | |
| if (!userString) return null; | |
| return JSON.parse(userString); | |
| } catch {} | |
| return {}; | |
| } | |
| export function baseHeaders(providedToken = null) { | |
| const token = providedToken || window.localStorage.getItem(AUTH_TOKEN); | |
| return { | |
| Authorization: token ? `Bearer ${token}` : null, | |
| }; | |
| } | |
| export function safeJsonParse(jsonString, fallback = null) { | |
| try { | |
| return JSON.parse(jsonString); | |
| } catch {} | |
| return fallback; | |
| } | |