diff --git a/hexi/web/src/api/client.ts b/hexi/web/src/api/client.ts index 7846127..1f5fed6 100644 --- a/hexi/web/src/api/client.ts +++ b/hexi/web/src/api/client.ts @@ -58,6 +58,12 @@ export const hubPlugins = async () => await request('/hub/api/plugins') export const hubDashboard = async () => await request('/hub/api/dashboard') export const hubPluginCatalog = async () => await request('/hub/api/plugins/catalog') export const hubGroups = async () => await request('/hub/api/groups') +// 请求取消一个在跑的任务(协作式:任务体在下一个检查点收尾,状态走 SSE 回来) +export const hubTaskCancel = async (id: string) => await request(`/hub/api/tasks/${id}/cancel`, { method: 'POST' }) +// 从任务列表里删掉一条已结束的任务(在跑的服务端会拒绝) +export const hubTaskDismiss = async (id: string) => await request(`/hub/api/tasks/${id}/dismiss`, { method: 'POST' }) +// 清掉所有已结束的任务 +export const hubTasksClear = async () => await request('/hub/api/tasks/clear', { method: 'POST' }) export const hubPluginSetGlobal = async (id: string, body: any) => await request('/hub/api/plugins/' + encodeURIComponent(id) + '/global', { method: 'POST', body }) export const hubPluginSetGroup = async (id: string, gid: string, body: any) => @@ -160,6 +166,21 @@ export function hubLogStream(opts: { }) } +/** 任务槽 SSE:每帧都是全量任务快照(服务端按百分比桶节流后才推)。 */ +export function hubTasksStream(opts: { + onTasks: (tasks: any[]) => void + onStatus?: (s: 'open' | 'reconnecting' | 'closed') => void +}): () => void { + return makeSSEStream({ + url: () => '/hub/api/tasks/stream', + onData: (obj) => { + if (obj && Array.isArray(obj.tasks)) opts.onTasks(obj.tasks) + }, + onStatus: opts.onStatus, + retryMs: 2000, + }) +} + export function hubDashboardStream(opts: { onData: (data: any) => void onStatus?: (s: 'open' | 'reconnecting' | 'closed') => void diff --git a/hexi/web/src/layout/AppLayout.tsx b/hexi/web/src/layout/AppLayout.tsx index 852ce0a..1ac633a 100644 --- a/hexi/web/src/layout/AppLayout.tsx +++ b/hexi/web/src/layout/AppLayout.tsx @@ -11,6 +11,7 @@ import { useAuth } from '../auth/auth' import { hubPlugins } from '../api/client' import { ErrorBoundary } from '../components/ErrorBoundary' import { useConnection } from '../connection' +import { TaskCenterButton } from '../tasks' import { BOT_ACTION_TEXT } from '../lib/botAction' import { BotActionOverlay, useBotAction } from '../botAction' @@ -197,6 +198,7 @@ export function AppLayout() { )}
+ 等效于群里的「/清理temp [天数]」(需管理权限);保留 0 天 = 全部清空。 + 清理在后台线程跑,页面其它操作不受影响。 +
++ 将删除 temp 目录下全部 {st?.files ?? 0} 个文件({st ? fmtBytes(st.bytes) : '—'})。 + 已归档到 S3 的媒体不受影响,但 temp 里这份就没有了 —— 页面上的预览链接会失效。 +
++ {status === 'open' ? '暂无任务。长任务(清缓存、批量下载等)会出现在这里。' : '正在连接任务流…'} +
+ ) : ( +