更新前后端代码
This commit is contained in:
@@ -0,0 +1,330 @@
|
||||
import http from './request'
|
||||
import type { ApiResp, PageData } from './request'
|
||||
|
||||
// ---------- 类型定义 ----------
|
||||
|
||||
export interface Role {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
description: string
|
||||
is_system: boolean
|
||||
status: number
|
||||
permissions?: Permission[]
|
||||
}
|
||||
|
||||
export interface Permission {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
module: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: number
|
||||
username: string
|
||||
email: string
|
||||
role_id: number
|
||||
role?: Role
|
||||
status: number
|
||||
storage_used: number
|
||||
storage_limit: number
|
||||
last_login_at?: string
|
||||
last_login_ip?: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: number
|
||||
user_id: number
|
||||
name: string
|
||||
description: string
|
||||
storage_used: number
|
||||
storage_limit: number
|
||||
status: number
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface FileItem {
|
||||
id: number
|
||||
project_id: number
|
||||
user_id: number
|
||||
filename: string
|
||||
size: number
|
||||
mime_type: string
|
||||
md5: string
|
||||
visibility: number
|
||||
download_count: number
|
||||
status: number
|
||||
created_at?: string
|
||||
project?: Project
|
||||
}
|
||||
|
||||
export interface TempLink {
|
||||
token: string
|
||||
url: string
|
||||
expires_at: string
|
||||
has_password: boolean
|
||||
max_count: number
|
||||
}
|
||||
|
||||
export interface APIKey {
|
||||
id: number
|
||||
access_key: string
|
||||
name: string
|
||||
status: number
|
||||
last_used_at?: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface Webhook {
|
||||
id: number
|
||||
project_id?: number
|
||||
url: string
|
||||
events: string
|
||||
status: number
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface OperationLog {
|
||||
id: number
|
||||
user_id?: number
|
||||
username: string
|
||||
action: string
|
||||
resource_type: string
|
||||
resource_id: number
|
||||
resource_name: string
|
||||
ip: string
|
||||
request_path: string
|
||||
request_method: string
|
||||
status: number
|
||||
error_message: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface SystemLog {
|
||||
id: number
|
||||
level: string
|
||||
module: string
|
||||
message: string
|
||||
request_id: string
|
||||
ip: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface SystemSetting {
|
||||
id: number
|
||||
key: string
|
||||
value: string
|
||||
description: string
|
||||
group_name: string
|
||||
}
|
||||
|
||||
// ---------- 认证 ----------
|
||||
|
||||
export const authApi = {
|
||||
register(data: { username: string; email: string; password: string }) {
|
||||
return http.post<any, ApiResp>('/auth/register', data)
|
||||
},
|
||||
login(data: { account: string; password: string }) {
|
||||
return http.post<any, ApiResp<{ token: string; user: User }>>('/auth/login', data)
|
||||
},
|
||||
createAPIKey(name: string) {
|
||||
return http.post<any, ApiResp<APIKey & { secret_key: string }>>('/auth/apikeys', { name })
|
||||
},
|
||||
listAPIKeys() {
|
||||
return http.get<any, ApiResp<APIKey[]>>('/auth/apikeys')
|
||||
},
|
||||
deleteAPIKey(id: number) {
|
||||
return http.delete<any, ApiResp>(`/auth/apikeys/${id}`)
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- 用户资料 ----------
|
||||
|
||||
export const userApi = {
|
||||
getProfile() {
|
||||
return http.get<any, ApiResp<User>>('/user/profile')
|
||||
},
|
||||
updateProfile(email: string) {
|
||||
return http.put<any, ApiResp>('/user/profile', { email })
|
||||
},
|
||||
changePassword(oldPassword: string, newPassword: string) {
|
||||
return http.put<any, ApiResp>('/user/password', {
|
||||
old_password: oldPassword,
|
||||
new_password: newPassword,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- 项目 ----------
|
||||
|
||||
export const projectApi = {
|
||||
create(data: { name: string; description?: string; storage_limit?: number }) {
|
||||
return http.post<any, ApiResp<Project>>('/projects', data)
|
||||
},
|
||||
list(params: { page?: number; page_size?: number; keyword?: string }) {
|
||||
return http.get<any, ApiResp<PageData<Project>>>('/projects', { params })
|
||||
},
|
||||
get(id: number) {
|
||||
return http.get<any, ApiResp<Project>>(`/projects/${id}`)
|
||||
},
|
||||
update(id: number, data: { name?: string; description?: string; storage_limit?: number }) {
|
||||
return http.put<any, ApiResp<Project>>(`/projects/${id}`, data)
|
||||
},
|
||||
remove(id: number) {
|
||||
return http.delete<any, ApiResp>(`/projects/${id}`)
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- 文件 ----------
|
||||
|
||||
export interface FileListParams {
|
||||
project_id?: number
|
||||
filename?: string
|
||||
prefix?: string
|
||||
trash?: boolean
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
export const fileApi = {
|
||||
upload(formData: FormData) {
|
||||
return http.post<any, ApiResp<FileItem>>('/files/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: 300000,
|
||||
})
|
||||
},
|
||||
list(params: FileListParams) {
|
||||
return http.get<any, ApiResp<PageData<FileItem>>>('/files', { params })
|
||||
},
|
||||
info(id: number) {
|
||||
return http.get<any, ApiResp<FileItem>>(`/files/${id}`)
|
||||
},
|
||||
// 下载为blob(需认证头)
|
||||
download(id: number) {
|
||||
return http.get(`/files/${id}/download`, { responseType: 'blob', timeout: 300000 })
|
||||
},
|
||||
remove(id: number, permanent = false) {
|
||||
return http.delete<any, ApiResp>(`/files/${id}`, { params: permanent ? { permanent: 'true' } : {} })
|
||||
},
|
||||
restore(id: number) {
|
||||
return http.post<any, ApiResp>(`/files/${id}/restore`)
|
||||
},
|
||||
createTempLink(id: number, data: { password?: string; max_count?: number; expires_in?: number }) {
|
||||
return http.post<any, ApiResp<TempLink>>(`/files/${id}/temp-link`, data)
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- 统计 ----------
|
||||
|
||||
export const statsApi = {
|
||||
user() {
|
||||
return http.get<any, ApiResp>('/stats/user')
|
||||
},
|
||||
project(id: number) {
|
||||
return http.get<any, ApiResp>(`/stats/project/${id}`)
|
||||
},
|
||||
traffic(days = 30) {
|
||||
return http.get<any, ApiResp>('/stats/traffic', { params: { days } })
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- Webhook ----------
|
||||
|
||||
export const webhookApi = {
|
||||
create(data: { url: string; events: string; project_id?: number; secret?: string }) {
|
||||
return http.post<any, ApiResp<Webhook>>('/webhooks', data)
|
||||
},
|
||||
list() {
|
||||
return http.get<any, ApiResp<Webhook[]>>('/webhooks')
|
||||
},
|
||||
update(id: number, data: { url?: string; events?: string; status?: number }) {
|
||||
return http.put<any, ApiResp<Webhook>>(`/webhooks/${id}`, data)
|
||||
},
|
||||
remove(id: number) {
|
||||
return http.delete<any, ApiResp>(`/webhooks/${id}`)
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- 管理后台 ----------
|
||||
|
||||
export const adminApi = {
|
||||
// 用户管理
|
||||
listUsers(params: { page?: number; page_size?: number; keyword?: string; role_id?: number; status?: string }) {
|
||||
return http.get<any, ApiResp<PageData<User>>>('/admin/users', { params })
|
||||
},
|
||||
createUser(data: { username: string; email: string; password: string; role_id?: number; storage_limit?: number }) {
|
||||
return http.post<any, ApiResp<User>>('/admin/users', data)
|
||||
},
|
||||
updateUser(id: number, data: { email?: string; role_id?: number; storage_limit?: number }) {
|
||||
return http.put<any, ApiResp<User>>(`/admin/users/${id}`, data)
|
||||
},
|
||||
deleteUser(id: number) {
|
||||
return http.delete<any, ApiResp>(`/admin/users/${id}`)
|
||||
},
|
||||
setUserStatus(id: number, status: number) {
|
||||
return http.put<any, ApiResp>(`/admin/users/${id}/status`, { status })
|
||||
},
|
||||
assignRole(id: number, roleId: number) {
|
||||
return http.put<any, ApiResp>(`/admin/users/${id}/role`, { role_id: roleId })
|
||||
},
|
||||
resetPassword(id: number, password: string) {
|
||||
return http.post<any, ApiResp>(`/admin/users/${id}/reset-password`, { password })
|
||||
},
|
||||
// 角色权限
|
||||
listRoles() {
|
||||
return http.get<any, ApiResp<Role[]>>('/admin/roles')
|
||||
},
|
||||
createRole(data: { name: string; code: string; description?: string; permissions?: number[] }) {
|
||||
return http.post<any, ApiResp<Role>>('/admin/roles', data)
|
||||
},
|
||||
updateRole(id: number, data: { name?: string; description?: string; permissions?: number[] }) {
|
||||
return http.put<any, ApiResp<Role>>(`/admin/roles/${id}`, data)
|
||||
},
|
||||
deleteRole(id: number) {
|
||||
return http.delete<any, ApiResp>(`/admin/roles/${id}`)
|
||||
},
|
||||
setRolePermissions(id: number, permissions: number[]) {
|
||||
return http.put<any, ApiResp>(`/admin/roles/${id}/permissions`, { permissions })
|
||||
},
|
||||
listPermissions() {
|
||||
return http.get<any, ApiResp<{ module: string; permissions: Permission[] }[]>>('/admin/permissions')
|
||||
},
|
||||
// 系统设置
|
||||
getSettings() {
|
||||
return http.get<any, ApiResp<Record<string, SystemSetting[]>>>('/admin/settings')
|
||||
},
|
||||
updateSettings(values: Record<string, string>) {
|
||||
return http.put<any, ApiResp>('/admin/settings', values)
|
||||
},
|
||||
// 日志
|
||||
listOperationLogs(params: { page?: number; page_size?: number; username?: string; action?: string; days?: number }) {
|
||||
return http.get<any, ApiResp<PageData<OperationLog>>>('/admin/logs/operation', { params })
|
||||
},
|
||||
listSystemLogs(params: { page?: number; page_size?: number; level?: string; module?: string; days?: number }) {
|
||||
return http.get<any, ApiResp<PageData<SystemLog>>>('/admin/logs/system', { params })
|
||||
},
|
||||
cleanupLogs(days: number) {
|
||||
return http.delete<any, ApiResp>('/admin/logs/cleanup', { params: { days } })
|
||||
},
|
||||
// 备份
|
||||
backup() {
|
||||
return http.post<any, ApiResp<{ name: string }>>('/admin/backup')
|
||||
},
|
||||
listBackups() {
|
||||
return http.get<any, ApiResp<{ name: string; size: number; time: string }[]>>('/admin/backups')
|
||||
},
|
||||
downloadBackup(name: string) {
|
||||
return http.get('/admin/backups/download', { params: { name }, responseType: 'blob', timeout: 300000 })
|
||||
},
|
||||
}
|
||||
|
||||
// ---------- 站点状态(公开) ----------
|
||||
|
||||
export const siteApi = {
|
||||
status() {
|
||||
return http.get<any, ApiResp>('/status')
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user