Spaces:
Running
Running
Download src/resource-deletion.ts from Shoraky/Sporalize-api: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/src/resource-deletion.ts
- Command line
-
hf download hf://spaces/Shoraky/Sporalize-api/src/resource-deletion.ts
-
curl -L -o resource-deletion.ts https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/src/resource-deletion.ts
1.14 kB
| import { env } from "./config.js"; | |
| import { supabaseAdmin } from "./supabase.js"; | |
| export async function deleteStoredSession(sessionId: string, actorId: string, isAdmin: boolean) { | |
| const response = await fetch(new URL(`/api/sessions/${sessionId}`, env.ANALYSIS_API_URL), { | |
| method: "DELETE", | |
| headers: { | |
| "x-sporalize-proxy-secret": env.ANALYSIS_PROXY_SECRET, | |
| "x-sporalize-user-id": actorId, | |
| ...(isAdmin ? { "x-sporalize-admin": "true" } : {}), | |
| }, | |
| }); | |
| if (!response.ok) { | |
| const payload = await response.json().catch(() => ({})) as { detail?: string; error?: string }; | |
| throw new Error(payload.detail || payload.error || `Unable to delete session ${sessionId} (${response.status}).`); | |
| } | |
| } | |
| export async function refundAdminUsage(userId: string | null, players: number, sessions: number) { | |
| if (!userId || (players <= 0 && sessions <= 0)) return; | |
| const { error } = await supabaseAdmin.rpc("adjust_subscription_usage", { | |
| p_user_id: userId, | |
| p_players: players, | |
| p_sessions: sessions, | |
| }); | |
| if (error) throw new Error(`Unable to restore deleted resource quota: ${error.message}`); | |
| } | |