- User balance low notification: email alert when balance drops below configurable threshold (user email + verified extra emails) - Account quota notification: broadcast email to admin-configured recipients when daily/weekly/total quota usage exceeds alert threshold - Admin settings: global enable/disable, default threshold, quota notification email list (Email Settings tab) - User profile: enable/disable, custom threshold, add/remove extra notification emails with verification code flow - Account quota: per-dimension alert toggle and threshold in quota control card - Trigger logic: first-crossing only (old >= threshold && new < threshold for balance; old < threshold && new >= threshold for quota), naturally prevents duplicate notifications without Redis dedup
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
/**
|
|
* User API endpoints
|
|
* Handles user profile management and password changes
|
|
*/
|
|
|
|
import { apiClient } from './client'
|
|
import type { User, ChangePasswordRequest } from '@/types'
|
|
|
|
/**
|
|
* Get current user profile
|
|
* @returns User profile data
|
|
*/
|
|
export async function getProfile(): Promise<User> {
|
|
const { data } = await apiClient.get<User>('/user/profile')
|
|
return data
|
|
}
|
|
|
|
/**
|
|
* Update current user profile
|
|
* @param profile - Profile data to update
|
|
* @returns Updated user profile data
|
|
*/
|
|
export async function updateProfile(profile: {
|
|
username?: string
|
|
balance_notify_enabled?: boolean
|
|
balance_notify_threshold?: number | null
|
|
balance_notify_extra_emails?: string[]
|
|
}): Promise<User> {
|
|
const { data } = await apiClient.put<User>('/user', profile)
|
|
return data
|
|
}
|
|
|
|
/**
|
|
* Change current user password
|
|
* @param passwords - Old and new password
|
|
* @returns Success message
|
|
*/
|
|
export async function changePassword(
|
|
oldPassword: string,
|
|
newPassword: string
|
|
): Promise<{ message: string }> {
|
|
const payload: ChangePasswordRequest = {
|
|
old_password: oldPassword,
|
|
new_password: newPassword
|
|
}
|
|
|
|
const { data } = await apiClient.put<{ message: string }>('/user/password', payload)
|
|
return data
|
|
}
|
|
|
|
/**
|
|
* Send verification code for adding a notify email
|
|
* @param email - Email address to verify
|
|
*/
|
|
export async function sendNotifyEmailCode(email: string): Promise<void> {
|
|
await apiClient.post('/user/notify-email/send-code', { email })
|
|
}
|
|
|
|
/**
|
|
* Verify and add a notify email
|
|
* @param email - Email address to add
|
|
* @param code - Verification code
|
|
*/
|
|
export async function verifyNotifyEmail(email: string, code: string): Promise<void> {
|
|
await apiClient.post('/user/notify-email/verify', { email, code })
|
|
}
|
|
|
|
/**
|
|
* Remove a notify email
|
|
* @param email - Email address to remove
|
|
*/
|
|
export async function removeNotifyEmail(email: string): Promise<void> {
|
|
await apiClient.delete('/user/notify-email', { data: { email } })
|
|
}
|
|
|
|
export const userAPI = {
|
|
getProfile,
|
|
updateProfile,
|
|
changePassword,
|
|
sendNotifyEmailCode,
|
|
verifyNotifyEmail,
|
|
removeNotifyEmail
|
|
}
|
|
|
|
export default userAPI
|