Download src/services/accountService.ts from AZILS/gemini: direct link, hf CLI and curl.
- Browser
- Download file 3.23 kB
-
https://huggingface.co/spaces/AZILS/gemini/resolve/main/src/services/accountService.ts
- Command line
-
hf download hf://spaces/AZILS/gemini/src/services/accountService.ts
-
curl -L -o accountService.ts https://huggingface.co/spaces/AZILS/gemini/resolve/main/src/services/accountService.ts
3.23 kB
| import { api } from './api'; | |
| import { Account, QuotaData } from '../types/account'; | |
| /** | |
| * List all accounts | |
| */ | |
| export async function listAccounts(): Promise<Account[]> { | |
| return await api.get<Account[]>('/api/accounts'); | |
| } | |
| /** | |
| * Get current account | |
| */ | |
| export async function getCurrentAccount(): Promise<Account | null> { | |
| return await api.get<Account | null>('/api/accounts/current'); | |
| } | |
| /** | |
| * Add account using refresh token | |
| */ | |
| export async function addAccount(email: string, refreshToken: string): Promise<Account> { | |
| return await api.post<Account>('/api/accounts', { email, refresh_token: refreshToken }); | |
| } | |
| /** | |
| * Delete account | |
| */ | |
| export async function deleteAccount(accountId: string): Promise<void> { | |
| return await api.delete<void>(`/api/accounts/${accountId}`); | |
| } | |
| /** | |
| * Delete multiple accounts | |
| */ | |
| export async function deleteAccounts(accountIds: string[]): Promise<void> { | |
| // Delete sequentially | |
| for (const id of accountIds) { | |
| await deleteAccount(id); | |
| } | |
| } | |
| /** | |
| * Set current account (cloud version - no IDE sync) | |
| */ | |
| export async function switchAccount(accountId: string): Promise<void> { | |
| return await api.post<void>(`/api/accounts/${accountId}/set-current`); | |
| } | |
| /** | |
| * Fetch account quota | |
| */ | |
| export async function fetchAccountQuota(accountId: string): Promise<QuotaData> { | |
| return await api.post<QuotaData>(`/api/accounts/${accountId}/quota`); | |
| } | |
| export interface RefreshStats { | |
| total: number; | |
| success: number; | |
| failed: number; | |
| details: string[]; | |
| } | |
| /** | |
| * Refresh all account quotas | |
| */ | |
| export async function refreshAllQuotas(): Promise<RefreshStats> { | |
| return await api.post<RefreshStats>('/api/accounts/refresh-all'); | |
| } | |
| // ======================================== | |
| // Cloud-incompatible functions (stubs) | |
| // ======================================== | |
| /** | |
| * OAuth login - Not supported in cloud version | |
| * Users should add accounts via Refresh Token | |
| */ | |
| export async function startOAuthLogin(): Promise<Account> { | |
| throw new Error('OAuth login is not supported in cloud version. Please add accounts using Refresh Token.'); | |
| } | |
| /** | |
| * Complete OAuth login - Not supported | |
| */ | |
| export async function completeOAuthLogin(): Promise<Account> { | |
| throw new Error('OAuth login is not supported in cloud version.'); | |
| } | |
| /** | |
| * Cancel OAuth login - Not supported | |
| */ | |
| export async function cancelOAuthLogin(): Promise<void> { | |
| // No-op | |
| } | |
| /** | |
| * Import V1 accounts - Not supported in cloud version | |
| */ | |
| export async function importV1Accounts(): Promise<Account[]> { | |
| throw new Error('V1 import is not supported in cloud version.'); | |
| } | |
| /** | |
| * Import from DB - Not supported in cloud version | |
| */ | |
| export async function importFromDb(): Promise<Account> { | |
| throw new Error('DB import is not supported in cloud version.'); | |
| } | |
| /** | |
| * Import from custom DB - Not supported in cloud version | |
| */ | |
| export async function importFromCustomDb(_path: string): Promise<Account> { | |
| throw new Error('Custom DB import is not supported in cloud version.'); | |
| } | |
| /** | |
| * Sync account from DB - Not supported in cloud version | |
| */ | |
| export async function syncAccountFromDb(): Promise<Account | null> { | |
| // Return null silently (used in background tasks) | |
| return null; | |
| } | |