Files
WebDrop/web/src/core-bridge/account.ts
T
justme d66c93fe98
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was successful
feat(web): avatar thumbnails with original preview, registration avatar, pure-JS crypto fallback for http [CI]
2026-10-17 14:35:42 +08:00

28 lines
2.2 KiB
TypeScript

import { callWorker } from './workerClient';
import type { AccountDeviceBody, InvitationBody } from './generated/api';
import type { AvatarChange, PersonalProfile } from './protocol/account';
const API_BASE = import.meta.env.VITE_WEBDROP_API_URL ?? '/api/v1';
export interface AccountStatus { username: string | null; revision: number; remembered?: boolean; personal?: PersonalProfile; error?: string; unlockUsername?: string }
export type AccountDevice = AccountDeviceBody;
export type AccountInvitation = InvitationBody & { channelName?: string; invitedBy?: string };
export const accountApi = {
register: (username: string, password: string, remember = true) => callWorker<AccountStatus>('registerAccount', { username, password, remember, apiBase: API_BASE }),
login: (username: string, password: string, remember = true) => callWorker<AccountStatus>('loginAccount', { username, password, remember, apiBase: API_BASE }),
savedLogin: () => callWorker<{ username: string; password: string; saved: boolean }>('savedLogin', { apiBase: API_BASE }),
clearSavedLogin: () => callWorker<AccountStatus>('clearSavedLogin', { apiBase: API_BASE }),
status: () => callWorker<AccountStatus>('accountStatus', { apiBase: API_BASE }),
logout: () => callWorker<void>('logoutAccount', { apiBase: API_BASE }),
sync: () => callWorker<AccountStatus>('syncAccount', { apiBase: API_BASE }),
invitations: () => callWorker<AccountInvitation[]>('accountInvitations', { apiBase: API_BASE }),
acceptInvitation: (id: string) => callWorker<void>('acceptInvitation', { id, apiBase: API_BASE }),
/** 默认是有损的缩略图;full 为 true 取原图(预览时) */
avatar: (username: string, version: number, full = false) => callWorker<string | undefined>('getAvatar', { username, version, full, apiBase: API_BASE }),
updatePersonal: (displayName: string, avatar?: AvatarChange) => callWorker<AccountStatus>('updatePersonal', { displayName, avatar, apiBase: API_BASE }),
devices: () => callWorker<AccountDevice[]>('accountDevices', { apiBase: API_BASE }),
renameDevice: (id: string, name: string) => callWorker<void>('renameAccountDevice', { id, name, apiBase: API_BASE }),
revokeDevice: (id: string) => callWorker<AccountStatus>('revokeAccountDevice', { id, apiBase: API_BASE }),
};