Files
TaskPool/web/src/api/index.ts
T

810 lines
28 KiB
TypeScript
Raw Normal View History

2026-01-13 18:18:50 +08:00
// 获取 base URL(从后端注入的全局变量)
const BASE_URL = (window as any).__BASE_URL__ || ''
const API_VERSION = (window as any).__API_VERSION__ || '/api/v1'
const API_BASE_URL = BASE_URL + API_VERSION
2025-12-20 09:30:16 +08:00
interface ApiResponse<T> {
code: number
msg: string
data: T
}
export interface MonitorStats {
env: {
os: string
arch: string
go_version: string
num_cpu: number
goroutines: number
}
host: {
cpu_percent: number
mem_total: number
mem_used: number
mem_percent: number
disk_total: number
disk_used: number
disk_percent: number
uptime: number
platform: string
}
mem: {
alloc: number
total_alloc: number
sys: number
lookups: number
mallocs: number
frees: number
}
heap: {
heap_alloc: number
heap_sys: number
heap_idle: number
heap_inuse: number
heap_released: number
heap_objects: number
}
gc: {
next_gc: number
last_gc: number
pause_total_ns: number
num_gc: number
}
scheduler: {
scheduled: number
running: number
queue_size: number
worker_count: number
workers: {
id: number
status: string
task_id?: string
task_name?: string
start_time?: number
duration?: number
}[]
}
}
2026-06-25 20:06:38 +08:00
export let activeInterconnectNodeId = localStorage.getItem('activeInterconnectNodeId') || ''
2026-06-25 20:06:38 +08:00
export function setActiveInterconnectNodeId(id: string) {
activeInterconnectNodeId = id
localStorage.removeItem('site_settings_cache')
if (id) {
localStorage.setItem('activeInterconnectNodeId', id)
document.cookie = `active_interconnect_node_id=${id}; path=/; max-age=${7 * 24 * 3600}`
} else {
localStorage.removeItem('activeInterconnectNodeId')
document.cookie = `active_interconnect_node_id=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC`
}
}
export async function request<T>(url: string, options?: RequestInit): Promise<T> {
let res: Response
try {
res = await fetch(`${API_BASE_URL}${url}`, {
...options,
credentials: 'include', // 携带 Cookie
headers: {
'Content-Type': 'application/json',
...options?.headers
}
})
} catch (err: any) {
throw err
}
2026-02-07 21:44:09 +08:00
2025-12-20 09:30:16 +08:00
const json: ApiResponse<T> = await res.json()
2026-02-07 21:44:09 +08:00
2025-12-20 09:30:16 +08:00
if (json.code === 401) {
// 未登录或登录过期,跳转到登录页
2026-01-13 18:18:50 +08:00
window.location.href = BASE_URL + '/login'
2025-12-20 09:30:16 +08:00
throw new Error(json.msg || '请先登录')
}
2026-02-07 21:44:09 +08:00
2025-12-20 09:30:16 +08:00
if (json.code !== 200) {
throw new Error(json.msg || '请求失败')
}
2026-02-07 21:44:09 +08:00
2025-12-20 09:30:16 +08:00
return json.data
}
// 检查登录状态(不触发自动跳转)
export async function checkAuth(): Promise<boolean> {
try {
2026-01-13 18:18:50 +08:00
const res = await fetch(`${API_BASE_URL}/auth/me`, {
2025-12-20 09:30:16 +08:00
credentials: 'include',
headers: { 'Content-Type': 'application/json' }
})
const json: ApiResponse<{ username: string }> = await res.json()
return json.code === 200
} catch {
return false
}
}
export const api = {
auth: {
login: (data: { username: string; password: string }) =>
request<{ user: string }>('/auth/login', { method: 'POST', body: JSON.stringify(data) }),
logout: () => request('/auth/logout', { method: 'POST' }),
2026-03-12 10:40:25 +08:00
me: () => request<{ username: string; role: string }>('/auth/me'),
2025-12-20 09:30:16 +08:00
register: (data: { username: string; password: string; email: string }) =>
request('/auth/register', { method: 'POST', body: JSON.stringify(data) })
},
tasks: {
2026-03-03 17:25:38 +08:00
list: (params?: { page?: number; page_size?: number; name?: string; agent_id?: string; tags?: string; type?: string }) => {
2025-12-20 09:30:16 +08:00
const query = new URLSearchParams()
if (params?.page) query.set('page', String(params.page))
if (params?.page_size) query.set('page_size', String(params.page_size))
if (params?.name) query.set('name', params.name)
2026-02-26 20:29:20 +08:00
if (params?.tags) query.set('tags', params.tags)
2026-03-03 17:25:38 +08:00
if (params?.agent_id) query.set('agent_id', params.agent_id)
2026-02-27 09:02:00 +08:00
if (params?.type) query.set('type', params.type)
2025-12-20 09:30:16 +08:00
return request<TaskListResponse>(`/tasks?${query}`)
},
create: (data: Partial<Task>) => request<Task>('/tasks', { method: 'POST', body: JSON.stringify(data) }),
2026-03-03 17:25:38 +08:00
update: (id: string, data: Partial<Task>) => request<Task>(`/tasks/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
2026-05-06 18:02:35 +08:00
delete: (id: string, params?: { delete_files?: boolean }) => {
const query = new URLSearchParams()
if (params?.delete_files !== undefined) query.set('delete_files', String(params.delete_files))
const queryString = query.toString()
return request(`/tasks/${id}${queryString ? '?' + queryString : ''}`, { method: 'DELETE' })
},
2026-03-19 11:06:45 +08:00
batchDelete: (ids: string[]) => request<{ count: number }>('/tasks/batch-delete', { method: 'POST', body: JSON.stringify({ ids }) }),
batchDeleteByQuery: (params?: { name?: string, agent_id?: string, tags?: string, type?: string }) => {
const query = new URLSearchParams()
if (params?.name) query.append('name', params.name)
if (params?.agent_id) query.append('agent_id', params.agent_id)
if (params?.tags) query.append('tags', params.tags)
if (params?.type && params.type !== 'all') query.append('type', params.type)
return request<{ count: number }>(`/tasks/batch-by-query?${query.toString()}`, { method: 'DELETE' })
},
2026-03-03 17:25:38 +08:00
execute: (id: string) => request<ExecutionResult>(`/execute/task/${id}`, { method: 'POST' }),
2026-04-24 19:47:37 +08:00
stop: (logID: string) => request(`/tasks/stop/${logID}`, { method: 'POST' }),
tags: () => request<string[]>('/tasks/tags')
2025-12-20 09:30:16 +08:00
},
scripts: {
list: () => request<Script[]>('/scripts'),
create: (data: Partial<Script>) => request<Script>('/scripts', { method: 'POST', body: JSON.stringify(data) }),
2026-03-03 17:25:38 +08:00
update: (id: string, data: Partial<Script>) => request<Script>(`/scripts/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
delete: (id: string) => request(`/scripts/${id}`, { method: 'DELETE' })
2025-12-20 09:30:16 +08:00
},
env: {
list: (params?: { page?: number; page_size?: number; name?: string; type?: string; tags?: string }) => {
2025-12-20 09:30:16 +08:00
const query = new URLSearchParams()
if (params?.page) query.set('page', String(params.page))
if (params?.page_size) query.set('page_size', String(params.page_size))
if (params?.name) query.set('name', params.name)
2026-03-27 14:51:29 +08:00
if (params?.type && params.type !== 'all') query.set('type', params.type)
if (params?.tags) query.set('tags', params.tags)
2025-12-20 09:30:16 +08:00
return request<EnvListResponse>(`/env?${query}`)
},
tags: () => request<string[]>('/env/tags'),
2026-03-27 14:51:29 +08:00
secretStatus: () => request<boolean>('/env/secret-status'),
2025-12-21 23:34:34 +08:00
all: () => request<EnvVar[]>('/env/all'),
2026-03-05 12:02:56 +08:00
tasks: (id: string) => request<Task[]>(`/env/${id}/tasks`),
2025-12-20 09:30:16 +08:00
create: (data: Partial<EnvVar>) => request<EnvVar>('/env', { method: 'POST', body: JSON.stringify(data) }),
2026-03-03 17:25:38 +08:00
update: (id: string, data: Partial<EnvVar>) => request<EnvVar>(`/env/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
2026-03-05 12:02:56 +08:00
delete: (id: string, force?: boolean) => {
const query = force ? '?force=true' : ''
return fetch(`${API_BASE_URL}/env/${id}${query}`, {
method: 'DELETE',
credentials: 'include'
}).then(res => res.json() as Promise<ApiResponse<any>>)
}
2025-12-20 09:30:16 +08:00
},
execute: {
command: (command: string) => request('/execute/command', { method: 'POST', body: JSON.stringify({ command }) }),
results: () => request('/execute/results')
},
logs: {
2026-03-03 17:25:38 +08:00
list: (params?: { page?: number; page_size?: number; task_id?: string; task_name?: string; status?: string }) => {
2025-12-20 09:30:16 +08:00
const query = new URLSearchParams()
if (params?.page) query.set('page', String(params.page))
if (params?.page_size) query.set('page_size', String(params.page_size))
2026-03-03 17:25:38 +08:00
if (params?.task_id) query.set('task_id', params.task_id)
2025-12-20 09:30:16 +08:00
if (params?.task_name) query.set('task_name', params.task_name)
2026-02-28 08:40:14 +08:00
if (params?.status) query.set('status', params.status)
2025-12-20 09:30:16 +08:00
return request<LogListResponse>(`/logs?${query}`)
},
2026-03-03 17:25:38 +08:00
get: (id: string) => request<LogDetail>(`/logs/${id}`),
detail: (id: string) => request<LogDetail>(`/logs/${id}`),
delete: (id: string) => request(`/logs/${id}`, { method: 'DELETE' }),
clear: (taskId?: string) => request('/logs/clear', { method: 'POST', body: JSON.stringify({ task_id: taskId }) })
2025-12-20 09:30:16 +08:00
},
dashboard: {
2025-12-20 12:00:08 +08:00
stats: () => request<Stats>('/stats'),
2025-12-21 21:49:34 +08:00
sentence: () => request<{ sentence: string }>('/sentence'),
2025-12-25 20:28:20 +08:00
sendStats: (days?: number) => request<DailyStats[]>(`/sendstats${days ? `?days=${days}` : ''}`),
taskStats: (days?: number) => request<TaskStatsItem[]>(`/taskstats${days ? `?days=${days}` : ''}`)
2025-12-20 09:30:16 +08:00
},
settings: {
getMonitor: () => request<MonitorStats>('/monitor'),
2026-03-12 10:40:25 +08:00
changePassword: (data: { old_username?: string; username?: string; old_password: string; new_password?: string }) =>
2025-12-20 09:30:16 +08:00
request('/settings/password', { method: 'POST', body: JSON.stringify(data) }),
2025-12-20 12:00:08 +08:00
getSite: () => request<SiteSettings>('/settings/site'),
2025-12-25 21:46:06 +08:00
getPublicSite: () => request<{ title: string; subtitle: string; icon: string; demo_mode: boolean }>('/settings/public'),
2025-12-20 12:00:08 +08:00
updateSite: (data: SiteSettings) =>
request('/settings/site', { method: 'PUT', body: JSON.stringify(data) }),
2026-03-05 22:22:46 +08:00
generateOpenapiToken: () => request<{ token: string }>('/settings/site/openapi-token/generate', { method: 'POST' }),
2025-12-22 16:05:07 +08:00
getScheduler: () => request<SchedulerSettings>('/settings/scheduler'),
updateScheduler: (data: SchedulerSettings) =>
request('/settings/scheduler', { method: 'PUT', body: JSON.stringify(data) }),
getPaths: () => request<{ scripts_dir: string }>('/settings/paths'),
2025-12-21 10:23:25 +08:00
getAbout: () => request<AboutInfo>('/settings/about'),
2026-03-19 11:06:45 +08:00
getChangelog: () => request<string>('/settings/changelog'),
2026-03-04 21:45:43 +08:00
get: (section: string, key: string) => request<string>(`/settings/${section}/${key}`),
2026-04-07 21:34:36 +08:00
getSection: (section: string) => request<Record<string, string>>(`/settings/${section}`),
setSection: (section: string, values: Record<string, string>) =>
request(`/settings/${section}`, { method: 'PUT', body: JSON.stringify(values) }),
2026-03-04 21:45:43 +08:00
generateToken: (section: string, key: string) =>
request<string>(`/settings/${section}/${key}/generate`, { method: 'POST' }),
2025-12-21 10:23:25 +08:00
getLoginLogs: (params?: { page?: number; page_size?: number; username?: string }) => {
const query = new URLSearchParams()
if (params?.page) query.set('page', String(params.page))
if (params?.page_size) query.set('page_size', String(params.page_size))
if (params?.username) query.set('username', params.username)
2025-12-21 14:30:59 +08:00
return request<LoginLogListResponse>(`/settings/loginlogs?${query}`)
2025-12-22 11:10:46 +08:00
},
createBackup: () => request('/settings/backup', { method: 'POST' }),
getBackupStatus: () => request<{ has_backup: boolean; backup_time: string }>('/settings/backup/status'),
2026-01-13 18:18:50 +08:00
downloadBackup: () => `${API_BASE_URL}/settings/backup/download`,
2025-12-22 11:10:46 +08:00
restoreBackup: async (file: File) => {
const formData = new FormData()
formData.append('file', file)
2026-01-13 18:18:50 +08:00
const res = await fetch(`${API_BASE_URL}/settings/restore`, {
2025-12-22 11:10:46 +08:00
method: 'POST',
credentials: 'include',
body: formData
})
const json: ApiResponse<null> = await res.json()
if (json.code === 401) {
2026-01-13 18:18:50 +08:00
window.location.href = BASE_URL + '/login'
2025-12-22 11:10:46 +08:00
throw new Error('请先登录')
}
if (json.code !== 200) throw new Error(json.msg || '恢复失败')
2025-12-21 10:23:25 +08:00
}
2025-12-20 09:30:16 +08:00
},
files: {
tree: () => request<FileNode[]>('/files/tree'),
getContent: (path: string) => request<{ path: string; content: string }>(`/files/content?path=${encodeURIComponent(path)}`),
2026-02-09 18:28:14 +08:00
download: (path: string) => `${API_BASE_URL}/files/download?path=${encodeURIComponent(path)}`,
downloadZip: (path: string) => `${API_BASE_URL}/files/download-zip?path=${encodeURIComponent(path)}`,
2025-12-20 09:30:16 +08:00
saveContent: (path: string, content: string) => request('/files/content', { method: 'POST', body: JSON.stringify({ path, content }) }),
create: (path: string, isDir: boolean) => request('/files/create', { method: 'POST', body: JSON.stringify({ path, isDir }) }),
delete: (path: string) => request('/files/delete', { method: 'POST', body: JSON.stringify({ path }) }),
rename: (oldPath: string, newPath: string) => request('/files/rename', { method: 'POST', body: JSON.stringify({ oldPath, newPath }) }),
2026-02-10 14:12:15 +08:00
move: (oldPath: string, newPath: string) => request('/files/move', { method: 'POST', body: JSON.stringify({ oldPath, newPath }) }),
2026-02-26 20:29:20 +08:00
copy: (sourcePath: string, targetPath: string) => request('/files/copy', { method: 'POST', body: JSON.stringify({ sourcePath, targetPath }) }),
2025-12-20 09:30:16 +08:00
uploadArchive: async (file: File, targetPath?: string) => {
const formData = new FormData()
formData.append('file', file)
if (targetPath) formData.append('path', targetPath)
2026-02-07 21:44:09 +08:00
2026-01-13 18:18:50 +08:00
const res = await fetch(`${API_BASE_URL}/files/upload`, {
2025-12-20 09:30:16 +08:00
method: 'POST',
credentials: 'include',
body: formData
})
const json: ApiResponse<null> = await res.json()
if (json.code === 401) {
2026-01-13 18:18:50 +08:00
window.location.href = BASE_URL + '/login'
2025-12-20 09:30:16 +08:00
throw new Error('请先登录')
}
if (json.code !== 200) throw new Error(json.msg || '上传失败')
},
uploadFiles: async (files: FileList, paths: string[], targetPath?: string) => {
const formData = new FormData()
for (let i = 0; i < files.length; i++) {
const file = files[i]
if (file) {
formData.append('files', file)
formData.append('paths', paths[i] || file.name)
}
}
if (targetPath) formData.append('path', targetPath)
2026-02-07 21:44:09 +08:00
2026-01-13 18:18:50 +08:00
const res = await fetch(`${API_BASE_URL}/files/uploadfiles`, {
2025-12-20 09:30:16 +08:00
method: 'POST',
credentials: 'include',
body: formData
})
const json: ApiResponse<null> = await res.json()
if (json.code === 401) {
2026-01-13 18:18:50 +08:00
window.location.href = BASE_URL + '/login'
2025-12-20 09:30:16 +08:00
throw new Error('请先登录')
}
if (json.code !== 200) throw new Error(json.msg || '上传失败')
}
2025-12-22 00:09:40 +08:00
},
2025-12-23 23:02:47 +08:00
deps: {
2026-02-13 17:27:55 +08:00
list: (params?: { language?: string; lang_version?: string }) => {
const query = new URLSearchParams()
if (params?.language) query.set('language', params.language)
if (params?.lang_version) query.set('lang_version', params.lang_version)
return request<Dependency[]>(`/deps?${query}`)
2025-12-23 23:02:47 +08:00
},
2026-02-13 17:27:55 +08:00
create: (data: { name: string; version?: string; language: string; lang_version?: string; remark?: string }) =>
2025-12-23 23:02:47 +08:00
request<Dependency>('/deps', { method: 'POST', body: JSON.stringify(data) }),
2026-03-03 17:25:38 +08:00
delete: (id: string) => request(`/deps/${id}`, { method: 'DELETE' }),
2026-02-13 17:27:55 +08:00
install: (data: any) => request<any>('/deps/install', { method: 'POST', body: JSON.stringify(data) }),
getInstallCmd: (data: any) => request<{ command: string }>('/deps/install-cmd', { method: 'POST', body: JSON.stringify(data) }),
2026-03-31 18:25:05 +08:00
uninstall: (id: string, force?: boolean) => {
const query = force ? '?force=true' : ''
return request<any>(`/deps/uninstall/${id}${query}`, { method: 'POST' })
},
2026-03-03 17:25:38 +08:00
reinstall: (id: string) => request(`/deps/reinstall/${id}`, { method: 'POST' }),
2026-02-13 17:27:55 +08:00
reinstallAll: (language: string, lang_version?: string) => {
const query = new URLSearchParams({ language })
if (lang_version) query.set('lang_version', lang_version)
return request(`/deps/reinstall-all?${query}`, { method: 'POST' })
},
getReinstallAllCmd: (language: string, lang_version?: string) => {
const query = new URLSearchParams({ language })
if (lang_version) query.set('lang_version', lang_version)
return request<{ command: string }>(`/deps/reinstall-all-cmd?${query}`, { method: 'POST' })
},
getBatchInstallCmd: (data: { items: { name: string; version?: string; language: string; lang_version?: string }[] }) =>
request<{ command: string }>('/deps/batch-install-cmd', { method: 'POST', body: JSON.stringify(data) }),
import: (data: { language: string; lang_version?: string; content: string; import_db?: boolean }) =>
request<{ dependencies: Dependency[]; command: string }>('/deps/import', { method: 'POST', body: JSON.stringify(data) }),
2026-02-13 17:27:55 +08:00
getInstalled: (language: string, lang_version?: string) => {
const query = new URLSearchParams({ language })
if (lang_version) query.set('lang_version', lang_version)
return request<Dependency[]>(`/deps/installed?${query}`)
}
2025-12-27 19:59:15 +08:00
},
agents: {
list: () => request<Agent[]>('/agents'),
getVersion: () => request<{ version: string; platforms: { os: string; arch: string; filename: string }[] }>('/agents/version'),
update: (id: string, data: { name: string; description?: string; enabled: boolean; scheduler_config: SchedulerConfig | null }) =>
2025-12-27 19:59:15 +08:00
request('/agents/' + id, { method: 'PUT', body: JSON.stringify(data) }),
2026-03-03 17:25:38 +08:00
delete: (id: string) => request('/agents/' + id, { method: 'DELETE' }),
forceUpdate: (id: string) => request('/agents/' + id + '/update', { method: 'POST' }),
2026-01-13 18:18:50 +08:00
downloadUrl: (os: string, arch: string) => `${API_BASE_URL}/agent/download?os=${os}&arch=${arch}`,
2025-12-28 11:42:58 +08:00
// 令牌管理
2025-12-30 20:29:04 +08:00
listTokens: () => request<AgentToken[]>('/agents/tokens'),
createToken: (data: { remark?: string; max_uses?: number; expires_at?: string }) =>
request<AgentToken>('/agents/tokens', { method: 'POST', body: JSON.stringify(data) }),
2026-04-02 20:31:20 +08:00
deleteToken: (id: string) => request('/agents/tokens/' + id, { method: 'DELETE' }),
updateToken: (id: string, data: { remark?: string; max_uses?: number; expires_at?: string }) =>
request<AgentToken>('/agents/tokens/' + id, { method: 'PUT', body: JSON.stringify(data) })
2026-02-13 17:27:55 +08:00
},
mise: {
list: () => request<MiseLanguage[]>('/mise/ls'),
sync: () => request<void>('/mise/sync', { method: 'POST' }),
plugins: () => request<string[]>('/mise/plugins'),
2026-02-13 21:16:51 +08:00
versions: (plugin: string) => request<string[]>(`/mise/versions?plugin=${plugin}`),
2026-03-17 11:58:32 +08:00
verifyCommand: (plugin: string, version: string) => request<{ command: string }>(`/mise/verify-cmd?plugin=${plugin}&version=${version}`),
2026-03-17 14:38:20 +08:00
useGlobal: (plugin: string, version: string) => request<void>('/mise/use-global', { method: 'POST', body: JSON.stringify({ plugin, version }) }),
2026-03-18 10:53:41 +08:00
unsetGlobal: (plugin: string, version: string) => request<void>('/mise/unset-global', { method: 'POST', body: JSON.stringify({ plugin, version }) }),
getEnvs: () => request<Record<string, string>>('/mise/envs'),
setEnv: (key: string, value: string) => request<void>('/mise/envs', { method: 'POST', body: JSON.stringify({ key, value }) }),
unsetEnv: (key: string) => request<void>(`/mise/envs?key=${key}`, { method: 'DELETE' })
2026-02-27 23:08:44 +08:00
},
terminal: {
cmds: () => request<{ name: string, description: string }[]>('/terminal/cmds')
2026-03-04 21:45:43 +08:00
},
notify: {
getTypes: () => request<{ channel_types: ChannelType[]; event_types: EventType[] }>('/notify/types'),
getChannels: () => request<NotifyChannel[]>('/notify/channels'),
saveChannel: (data: Partial<NotifyChannel>) =>
request('/notify/channels', { method: 'POST', body: JSON.stringify(data) }),
deleteChannel: (id: string) => request('/notify/channels/' + id, { method: 'DELETE' }),
testChannel: (data: Partial<NotifyChannel>) =>
request<NotifyResult>('/notify/channels/test', { method: 'POST', body: JSON.stringify(data) }),
getBindings: () => request<NotifyBinding[]>('/notify/bindings'),
saveBinding: (data: Partial<NotifyBinding>) =>
request<NotifyBinding>('/notify/bindings', { method: 'POST', body: JSON.stringify(data) }),
2026-03-25 07:31:45 +08:00
saveBindingsBatch: (data: { type: string; data_id: string; bindings: Partial<NotifyBinding>[] }) =>
request('/notify/bindings/batch', { method: 'POST', body: JSON.stringify(data) }),
2026-03-04 21:45:43 +08:00
deleteBinding: (id: string) => request('/notify/bindings/' + id, { method: 'DELETE' }),
send: (data: { channel_id: string; title: string; text: string }) =>
request<NotifyResult>('/notify/send', { method: 'POST', body: JSON.stringify(data) })
2026-03-09 18:10:23 +08:00
},
appLogs: {
list: (params?: { page?: number; page_size?: number; category?: string; status?: string; level?: string; keyword?: string }) => {
const query = new URLSearchParams()
if (params?.page) query.set('page', String(params.page))
if (params?.page_size) query.set('page_size', String(params.page_size))
if (params?.category) query.set('category', params.category)
if (params?.status) query.set('status', params.status)
if (params?.level) query.set('level', params.level)
if (params?.keyword) query.set('keyword', params.keyword)
return request<AppLogListResponse>(`/app-logs?${query}`)
},
markAsRead: (data: { id?: string; category?: string }) => request('/app-logs/read', { method: 'POST', body: JSON.stringify(data) }),
clear: (category: string) => request('/app-logs/clear', { method: 'POST', body: JSON.stringify({ category }) })
},
webui: {
list: () => request<WebUI[]>('/webui'),
upload: async (file: File) => {
const formData = new FormData()
formData.append('file', file)
const res = await fetch(`${API_BASE_URL}/webui/upload`, {
method: 'POST',
credentials: 'include',
body: formData
})
const json: ApiResponse<{ message: string, theme: string }> = await res.json()
if (json.code === 401) {
window.location.href = BASE_URL + '/login'
throw new Error('请先登录')
}
if (json.code !== 200) throw new Error(json.msg || '上传失败')
return json.data
},
setActive: (name: string) => request<{ message: string }>('/webui/active', { method: 'PUT', body: JSON.stringify({ name }) }),
delete: (name: string) => request<{ message: string }>(`/webui/${name}`, { method: 'DELETE' })
2025-12-20 09:30:16 +08:00
}
}
export interface WebUI {
name: string
version: string
author: string
description: string
min_panel_version: string
}
2025-12-20 09:30:16 +08:00
export interface FileNode {
name: string
path: string
isDir: boolean
modTime: number
2025-12-20 09:30:16 +08:00
children?: FileNode[]
}
export interface Task {
2026-03-03 17:25:38 +08:00
id: string
2025-12-20 09:30:16 +08:00
name: string
2026-04-02 20:36:24 +08:00
remark: string
2025-12-20 09:30:16 +08:00
command: string
2026-05-08 20:18:00 +08:00
pre_command: string
post_command: string
2026-02-26 20:29:20 +08:00
tags: string
2025-12-25 17:55:54 +08:00
type: string
trigger_type: string
2025-12-25 17:55:54 +08:00
config: string
2025-12-20 09:30:16 +08:00
schedule: string
timeout: number
2025-12-23 23:31:08 +08:00
work_dir: string
2025-12-21 22:19:55 +08:00
clean_config: string
2025-12-21 23:34:34 +08:00
envs: string
2026-02-28 14:44:32 +08:00
retry_count: number
retry_interval: number
2026-03-02 18:29:07 +08:00
random_range: number
2026-04-29 18:02:43 +08:00
pin_type: 'none' | 'top'
2026-02-13 19:26:20 +08:00
languages: { name: string; version: string }[]
2026-03-03 17:25:38 +08:00
agent_id: string | null
2025-12-20 09:30:16 +08:00
enabled: boolean
last_run: string
next_run: string
2026-04-30 15:44:45 +08:00
running_status?: string
2026-03-06 14:13:37 +08:00
created_at?: string
updated_at?: string
2025-12-20 09:30:16 +08:00
}
2025-12-25 17:55:54 +08:00
export interface RepoConfig {
source_type: string
source_url: string
target_path: string
branch: string
sparse_path: string
single_file: boolean
proxy: string
proxy_url: string
auth_token: string
2026-03-16 10:50:07 +08:00
whitelist_paths?: string
2026-03-19 11:06:45 +08:00
blacklist?: string
dependence?: string
extensions?: string
auto_add_cron?: boolean
2026-05-06 18:02:35 +08:00
commenttotask?: string
2026-02-07 21:44:09 +08:00
concurrency?: number
2026-03-19 11:06:45 +08:00
repo_source?: string
repo_dir_name?: string
2026-02-07 21:44:09 +08:00
}
export interface ExecutionResult {
2026-04-30 16:08:22 +08:00
task_id: string
log_id?: string
success: boolean
status?: string
output?: string
error?: string
duration?: number
exit_code?: number
start_time?: string
end_time?: string
2025-12-25 17:55:54 +08:00
}
2025-12-20 09:30:16 +08:00
export interface TaskListResponse {
2026-03-06 08:53:22 +08:00
data: Task[]
2025-12-20 09:30:16 +08:00
total: number
page: number
page_size: number
}
export interface Script {
2026-03-03 17:25:38 +08:00
id: string
2025-12-20 09:30:16 +08:00
name: string
content: string
}
export interface EnvVar {
2026-03-03 17:25:38 +08:00
id: string
2025-12-20 09:30:16 +08:00
name: string
value: string
remark: string
2026-03-27 14:51:29 +08:00
type: string
2026-02-10 15:02:52 +08:00
hidden: boolean
2026-03-13 14:09:43 +08:00
enabled: boolean
tags: string
2026-04-17 22:04:05 +08:00
created_at?: string
updated_at?: string
2025-12-20 09:30:16 +08:00
}
export interface EnvListResponse {
2026-03-06 08:53:22 +08:00
data: EnvVar[]
2025-12-20 09:30:16 +08:00
total: number
page: number
page_size: number
}
export interface Stats {
tasks: number
2025-12-24 10:48:23 +08:00
today_execs: number
2025-12-20 09:30:16 +08:00
envs: number
logs: number
scheduled: number
running: number
}
export interface TaskLog {
2026-03-03 17:25:38 +08:00
id: string
task_id: string
2025-12-20 09:30:16 +08:00
task_name: string
2025-12-25 19:16:58 +08:00
task_type: string
2025-12-20 09:30:16 +08:00
command: string
status: string
duration: number
2026-02-08 11:03:11 +08:00
error: string | null
2026-01-01 14:42:33 +08:00
start_time: string | null
end_time: string | null
2025-12-20 09:30:16 +08:00
created_at: string
}
export interface LogListResponse {
2026-03-06 08:53:22 +08:00
data: TaskLog[]
2025-12-20 09:30:16 +08:00
total: number
page: number
page_size: number
}
export interface LogDetail {
2026-03-03 17:25:38 +08:00
id: string
task_id: string
2025-12-20 09:30:16 +08:00
command: string
output: string
2026-02-08 11:03:11 +08:00
error: string | null
2025-12-20 09:30:16 +08:00
status: string
duration: number
2026-01-01 14:42:33 +08:00
start_time: string | null
end_time: string | null
2025-12-20 09:30:16 +08:00
created_at: string
}
export interface AboutInfo {
version: string
2026-03-19 11:06:45 +08:00
remote_version?: string
2025-12-20 09:30:16 +08:00
build_time: string
mem_usage: string
2025-12-27 13:54:20 +08:00
goroutines: number
2025-12-20 09:30:16 +08:00
uptime: string
task_count: number
log_count: number
env_count: number
}
2025-12-20 12:00:08 +08:00
export interface SiteSettings {
title: string
subtitle: string
icon: string
page_size: string
cookie_days: string
2026-03-05 22:22:46 +08:00
openapi_enabled?: boolean
openapi_token?: string
openapi_token_expire?: string
2026-03-09 19:16:28 +08:00
system_notice_days?: string
system_notice_max_count?: string
push_log_days?: string
push_log_max_count?: string
2026-03-09 21:46:11 +08:00
login_log_days?: string
login_log_max_count?: string
2026-05-14 17:49:59 +08:00
scheduler_log_days?: string
scheduler_log_max_count?: string
active_webui?: string
2025-12-20 12:00:08 +08:00
}
2025-12-21 10:23:25 +08:00
2025-12-22 16:05:07 +08:00
export interface SchedulerSettings {
worker_count: string
queue_size: string
rate_interval: string
}
2025-12-21 10:23:25 +08:00
export interface LoginLog {
2026-03-03 17:25:38 +08:00
id: string
2025-12-21 10:23:25 +08:00
username: string
ip: string
user_agent: string
status: string
message: string
created_at: string
}
export interface LoginLogListResponse {
2026-03-06 08:53:22 +08:00
data: LoginLog[]
2025-12-21 10:23:25 +08:00
total: number
page: number
page_size: number
}
2025-12-21 21:49:34 +08:00
export interface DailyStats {
day: string
total: number
success: number
failed: number
}
export interface TaskStatsItem {
2026-03-03 17:25:38 +08:00
task_id: string
2025-12-21 21:49:34 +08:00
task_name: string
count: number
}
2025-12-22 00:09:40 +08:00
2025-12-23 23:02:47 +08:00
export interface Dependency {
2026-03-03 17:25:38 +08:00
id: string
2025-12-22 00:09:40 +08:00
name: string
version: string
2026-02-13 17:27:55 +08:00
language: string
lang_version: string
2025-12-23 23:02:47 +08:00
remark: string
2025-12-23 23:10:42 +08:00
log: string
2025-12-23 23:02:47 +08:00
created_at: string
updated_at: string
2025-12-22 00:09:40 +08:00
}
2025-12-27 19:59:15 +08:00
export interface Agent {
2026-03-03 17:25:38 +08:00
id: string
2025-12-27 19:59:15 +08:00
name: string
token: string
2025-12-28 11:42:58 +08:00
machine_id: string
2025-12-27 19:59:15 +08:00
description: string
status: string
last_seen: string
ip: string
version: string
build_time: string
hostname: string
2025-12-28 11:42:58 +08:00
os: string
arch: string
2025-12-27 19:59:15 +08:00
enabled: boolean
scheduler_config: SchedulerConfig | null
2025-12-27 19:59:15 +08:00
created_at: string
updated_at: string
}
2025-12-28 11:42:58 +08:00
export interface SchedulerConfig {
worker_count: number
queue_size: number
rate_interval: number
verbose: boolean
strict_queue: boolean
}
2025-12-30 20:29:04 +08:00
export interface AgentToken {
2026-03-03 17:25:38 +08:00
id: string
2025-12-30 20:29:04 +08:00
token: string
2025-12-28 11:42:58 +08:00
remark: string
max_uses: number
used_count: number
expires_at: string | null
enabled: boolean
created_at: string
}
2026-02-13 17:27:55 +08:00
export interface MiseLanguage {
plugin: string
version: string
source: { type?: string; path?: string } | string
2026-03-17 11:58:32 +08:00
is_global: boolean
2026-02-13 17:27:55 +08:00
install_path?: string
installed_at?: string // 安装日期
}
2026-03-04 21:45:43 +08:00
export interface ChannelType {
type: string
label: string
}
export interface EventType {
type: string
label: string
binding_type?: string
}
export interface NotifyChannel {
id: string
name: string
type: string
enabled: boolean
2026-03-04 22:02:50 +08:00
created_at?: string
2026-03-04 21:45:43 +08:00
config: Record<string, string>
}
export interface NotifyBinding {
id: string
type: string
event: string
way_id: string
data_id: string
2026-03-25 07:31:45 +08:00
extra?: string
2026-03-04 21:45:43 +08:00
created_at?: string
updated_at?: string
}
2026-03-25 07:31:45 +08:00
export interface BindingExtra {
enable_log: boolean
log_limit: number
}
2026-03-04 21:45:43 +08:00
export interface NotifyResult {
success: boolean
error?: string
}
2026-03-09 18:10:23 +08:00
export interface AppLog {
id: string
category: string
title: string
content: string
level: string
status: string
ref_id: string
2026-03-09 22:30:05 +08:00
channel_name?: string
2026-03-09 18:10:23 +08:00
error_msg: string
created_at: string
read_at: string | null
}
export interface AppLogListResponse {
data: AppLog[]
total: number
}
export const LOG_CATEGORY = {
SYSTEM_NOTICE: 'system_notice',
2026-03-09 22:08:25 +08:00
PUSH_LOG: 'push_log',
2026-05-14 17:49:59 +08:00
LOGIN_LOG: 'login_log',
SCHEDULER_LOG: 'scheduler_log'
2026-03-09 18:10:23 +08:00
} as const
export const LOG_LEVEL = {
INFO: 'info',
WARNING: 'warning',
ERROR: 'error'
} as const
export const LOG_STATUS = {
UNREAD: 'unread',
READ: 'read',
SUCCESS: 'success',
FAILED: 'failed'
} as const