Download src/lib/api/class-session-progress.ts from asnannp/DocDoeAI: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/asnannp/DocDoeAI/resolve/main/src/lib/api/class-session-progress.ts
- Command line
-
hf download hf://spaces/asnannp/DocDoeAI/src/lib/api/class-session-progress.ts
-
curl -L -o class-session-progress.ts https://huggingface.co/spaces/asnannp/DocDoeAI/resolve/main/src/lib/api/class-session-progress.ts
1.55 kB
| import { apiGet, apiPost } from "@/lib/api/client"; | |
| import { hasLiveSession } from "@/lib/api/mode"; | |
| import type { ClassSessionProgressState } from "@/components/tuition/chapter-dashboard/classSessionProgress"; | |
| /** | |
| * Backend sync for tuition class session progress. | |
| * | |
| * localStorage (classSessionProgress.ts) gives instant refresh-restore on the | |
| * same device; this makes progress survive a device change / re-login. Both | |
| * helpers are best-effort and no-op when logged out. | |
| */ | |
| type ClassSessionProgressRemote = { | |
| class_session_id: string; | |
| data: ClassSessionProgressState; | |
| updated_at: string; | |
| }; | |
| /** Returns true when the progress was persisted to the backend. */ | |
| export async function saveClassSessionProgressRemote( | |
| id: string, | |
| state: ClassSessionProgressState, | |
| ): Promise<boolean> { | |
| if (!hasLiveSession()) return false; | |
| try { | |
| await apiPost<ClassSessionProgressRemote, { class_session_id: string; data: ClassSessionProgressState }>( | |
| "/class-session-progress", | |
| { class_session_id: id, data: state }, | |
| ); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| /** Returns the saved progress for one class session, or null. */ | |
| export async function getClassSessionProgressRemote(id: string): Promise<ClassSessionProgressState | null> { | |
| if (!hasLiveSession()) return null; | |
| try { | |
| const rows = await apiGet<ClassSessionProgressRemote[]>("/class-session-progress"); | |
| const row = (rows ?? []).find((item) => item.class_session_id === id); | |
| return row?.data ?? null; | |
| } catch { | |
| return null; | |
| } | |
| } | |