mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-05 21:01:50 +08:00
feat(tasks): add read-only task file browser (GITHUB-3)
This commit is contained in:
1 parent
873e3a667b
commit
62ed7db7b2
14 files changed
+1567
-21
No files matched your search
+29
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { ChatMention } from "@/lib/chat-mentions";
|
||||
import { MOCK } from "@/lib/mock/enabled";
|
||||
import { mockHandle } from "@/lib/mock/handler";
|
||||
import { mockHandle, mockTaskFileURL } from "@/lib/mock/handler";
|
||||
import type {
|
||||
ActiveFindingRetest,
|
||||
Activity,
|
||||
@@ -98,6 +98,7 @@ import type {
|
||||
TaskAssetScopeMutation,
|
||||
TaskCategory,
|
||||
TaskConstraint,
|
||||
TaskFileListing,
|
||||
TaskGoal,
|
||||
TaskIntelligence,
|
||||
TaskLLMResolutions,
|
||||
@@ -596,6 +597,33 @@ export const api = {
|
||||
// 某资产在本任务里关联的意图 / 事实 / 发现(覆盖图节点抽屉用)。
|
||||
taskAssetRefs: (id: string, assetId: number) => get<CoverageAssetRefs>(`/tasks/${id}/asset-refs?asset_id=${assetId}`),
|
||||
|
||||
taskFiles: (id: string, path = "") => get<TaskFileListing>(`/tasks/${id}/files?path=${encodeURIComponent(path)}`),
|
||||
taskFilesAll: (id: string) => get<TaskFileListing>(`/tasks/${id}/files/all`),
|
||||
taskFileRead: (id: string, path: string) =>
|
||||
get<WorkspaceFile>(`/tasks/${id}/files/read?path=${encodeURIComponent(path)}`),
|
||||
// Browser downloads stream to disk using the same auth cookie as SSE. Avoid
|
||||
// fetching ZIPs into a Blob, which would buffer the entire archive in memory.
|
||||
taskFileDownload: async (id: string, path: string, archive = false) => {
|
||||
const action = archive ? "archive" : "download";
|
||||
if (!MOCK) {
|
||||
const token = getToken();
|
||||
const response = await apiFetch(`/api/tasks/${id}/files/${action}?path=${encodeURIComponent(path)}`, {
|
||||
method: "HEAD",
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
});
|
||||
if (!response.ok) throw new Error(response.status === 404 ? "taskFiles.unavailable" : "taskFiles.failed");
|
||||
}
|
||||
const a = document.createElement("a");
|
||||
a.href = MOCK ? mockTaskFileURL(path, action) : `/api/tasks/${id}/files/${action}?path=${encodeURIComponent(path)}`;
|
||||
a.download = archive ? `${path.split("/").pop() || `task-${id}`}.zip` : path.split("/").pop() || "download";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
if (MOCK && a.href.startsWith("blob:")) setTimeout(() => URL.revokeObjectURL(a.href), 60_000);
|
||||
},
|
||||
taskFilePreview: (id: string, path: string) =>
|
||||
MOCK ? mockTaskFileURL(path, "preview") : `/api/tasks/${id}/files/preview?path=${encodeURIComponent(path)}`,
|
||||
|
||||
// ---- workspace file manager (workDir) ----
|
||||
workspaceList: (path = "") => get<WorkspaceListing>(`/workspace/list?path=${encodeURIComponent(path)}`),
|
||||
workspaceRead: (path: string) => get<WorkspaceFile>(`/workspace/read?path=${encodeURIComponent(path)}`),
|
||||
|
||||
Reference in new issue
Block a user