2025-03-19 15:49:18 +08:00
|
|
|
// 定义后端服务URL和OAuth2配置
|
2025-12-04 14:43:13 +08:00
|
|
|
const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL
|
2025-03-19 15:49:18 +08:00
|
|
|
const CLIENT_ID = process.env.CLIENT_ID
|
|
|
|
|
const CLIENT_SECRET = process.env.CLIENT_SECRET
|
|
|
|
|
|
|
|
|
|
// 统一的API响应类型
|
2025-04-08 11:21:58 +08:00
|
|
|
type ApiResponse<T = undefined> = {
|
2025-03-19 15:49:18 +08:00
|
|
|
success: false
|
|
|
|
|
status: number
|
|
|
|
|
message: string
|
|
|
|
|
} | {
|
|
|
|
|
success: true
|
|
|
|
|
data: T
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 11:21:58 +08:00
|
|
|
type PageRecord<T = unknown> = {
|
2025-04-07 15:42:09 +08:00
|
|
|
total: number
|
|
|
|
|
page: number
|
|
|
|
|
size: number
|
|
|
|
|
list: T[]
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 14:59:22 +08:00
|
|
|
type ExtraReq<T extends (...args: never) => unknown> = T extends (...args: infer P) => unknown ? P[0] : never
|
|
|
|
|
type ExtraResp<T extends (...args: never) => unknown> = Awaited<ReturnType<T>> extends ApiResponse<infer D> ? D : never
|
2025-04-16 18:51:17 +08:00
|
|
|
|
2025-04-08 11:21:58 +08:00
|
|
|
// 预定义错误
|
|
|
|
|
const UnauthorizedError = new Error('未授权访问')
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
API_BASE_URL,
|
|
|
|
|
CLIENT_ID,
|
|
|
|
|
CLIENT_SECRET,
|
|
|
|
|
type ApiResponse,
|
|
|
|
|
type PageRecord,
|
2025-05-22 14:59:22 +08:00
|
|
|
type ExtraReq,
|
|
|
|
|
type ExtraResp,
|
2025-04-08 11:21:58 +08:00
|
|
|
UnauthorizedError,
|
|
|
|
|
}
|