| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- import { api } from '@/lib/api'
- import type {
- ApiResponse,
- UserProfile,
- UpdateUserRequest,
- UpdateUserSettingsRequest,
- DeleteAccountRequest,
- CheckinStatusResponse,
- CheckinResponse,
- } from './types'
- // ============================================================================
- // User Profile APIs
- // ============================================================================
- /**
- * Get current user profile
- */
- export async function getUserProfile(): Promise<ApiResponse<UserProfile>> {
- const res = await api.get('/api/user/self')
- return res.data
- }
- /**
- * Update user profile
- */
- export async function updateUserProfile(
- data: UpdateUserRequest
- ): Promise<ApiResponse> {
- const res = await api.put('/api/user/self', data)
- return res.data
- }
- /**
- * Update user settings
- */
- export async function updateUserSettings(
- data: UpdateUserSettingsRequest
- ): Promise<ApiResponse> {
- const res = await api.put('/api/user/setting', data)
- return res.data
- }
- /**
- * Delete user account
- */
- export async function deleteUserAccount(
- data?: DeleteAccountRequest
- ): Promise<ApiResponse> {
- const res = await api.delete('/api/user/self', { data })
- return res.data
- }
- /**
- * Generate/regenerate system access token
- */
- export async function generateAccessToken(): Promise<ApiResponse<string>> {
- const res = await api.get('/api/user/token')
- return res.data
- }
- // ============================================================================
- // Account Binding APIs
- // ============================================================================
- /**
- * Send email verification code
- */
- export async function sendEmailVerification(
- email: string,
- turnstileToken?: string
- ): Promise<ApiResponse> {
- const params = new URLSearchParams({ email })
- if (turnstileToken) {
- params.append('turnstile', turnstileToken)
- }
- const res = await api.get(`/api/verification?${params}`)
- return res.data
- }
- /**
- * Bind email account
- */
- export async function bindEmail(
- email: string,
- code: string
- ): Promise<ApiResponse> {
- const res = await api.post('/api/oauth/email/bind', {
- email,
- code,
- })
- return res.data
- }
- /**
- * Bind WeChat account
- */
- export async function bindWeChat(code: string): Promise<ApiResponse> {
- const res = await api.get(`/api/oauth/wechat/bind?code=${code}`)
- return res.data
- }
- // ============================================================================
- // Custom OAuth Binding APIs
- // ============================================================================
- export interface CustomOAuthBinding {
- provider_id: string
- provider_name: string
- external_id?: string
- }
- /**
- * Get current user's custom OAuth bindings
- */
- export async function getSelfOAuthBindings(): Promise<
- ApiResponse<CustomOAuthBinding[]>
- > {
- const res = await api.get('/api/user/oauth/bindings')
- return res.data
- }
- /**
- * Unbind a custom OAuth provider for current user
- */
- export async function unbindCustomOAuth(
- providerId: string
- ): Promise<ApiResponse> {
- const res = await api.delete(`/api/user/oauth/bindings/${providerId}`)
- return res.data
- }
- // ============================================================================
- // Checkin APIs
- // ============================================================================
- /**
- * Get checkin status for a specific month
- */
- export async function getCheckinStatus(
- month: string
- ): Promise<ApiResponse<CheckinStatusResponse>> {
- const res = await api.get(`/api/user/checkin?month=${month}`)
- return res.data
- }
- /**
- * Perform daily checkin
- */
- export async function performCheckin(
- turnstileToken?: string
- ): Promise<ApiResponse<CheckinResponse>> {
- const url = turnstileToken
- ? `/api/user/checkin?turnstile=${encodeURIComponent(turnstileToken)}`
- : '/api/user/checkin'
- const res = await api.post(url)
- return res.data
- }
|