Download desktop/src/api/hahaOpenAIOAuth.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 916 Bytes
-
https://huggingface.co/chenbhao/codev/resolve/e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/api/hahaOpenAIOAuth.ts
- Command line
-
hf download hf://chenbhao/codev@e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/api/hahaOpenAIOAuth.ts
-
curl -L -o hahaOpenAIOAuth.ts https://huggingface.co/chenbhao/codev/resolve/e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/api/hahaOpenAIOAuth.ts
916 Bytes
| // desktop/src/api/hahaOpenAIOAuth.ts | |
| import { api, getBaseUrl } from './client' | |
| export type HahaOpenAIOAuthStatus = | |
| | { loggedIn: false } | |
| | { | |
| loggedIn: true | |
| expiresAt: number | null | |
| email: string | null | |
| accountId: string | null | |
| } | |
| function currentServerPort(): number { | |
| const port = new URL(getBaseUrl()).port | |
| const parsed = Number.parseInt(port, 10) | |
| if (!Number.isFinite(parsed) || parsed <= 0) { | |
| throw new Error(`Cannot determine server port from baseUrl: ${getBaseUrl()}`) | |
| } | |
| return parsed | |
| } | |
| export const hahaOpenAIOAuthApi = { | |
| start() { | |
| return api.post<{ authorizeUrl: string; state: string }>( | |
| '/api/haha-openai-oauth/start', | |
| { serverPort: currentServerPort() }, | |
| ) | |
| }, | |
| status() { | |
| return api.get<HahaOpenAIOAuthStatus>('/api/haha-openai-oauth') | |
| }, | |
| logout() { | |
| return api.delete<{ ok: true }>('/api/haha-openai-oauth') | |
| }, | |
| } | |