fix(web): support offline driver zip import

This commit is contained in:
t8y2 committed 2026-05-21 11:40:05 +08:00
1 parent 01572ebad7
commit 73117255c6
6 files changed
+96 -14

No files matched your search

@@ -243,15 +243,31 @@ async function uninstallDriver(dbType: string) {
const importingZip = ref(false);
async function importOfflineZip() {
if (isWeb || importingZip.value) return;
const { open } = await import("@tauri-apps/plugin-dialog");
const selected = await open({
title: "选择离线驱动包",
multiple: false,
filters: [{ name: "ZIP", extensions: ["zip"] }],
function chooseWebOfflineZip(): Promise<File | null> {
return new Promise((resolve) => {
const input = document.createElement("input");
input.type = "file";
input.accept = ".zip";
input.onchange = () => resolve(input.files?.[0] ?? null);
input.click();
});
if (typeof selected !== "string") return;
}
async function importOfflineZip() {
if (importingZip.value) return;
let selected: string | File | null = null;
if (isWeb) {
selected = await chooseWebOfflineZip();
} else {
const { open } = await import("@tauri-apps/plugin-dialog");
const path = await open({
title: "选择离线驱动包",
multiple: false,
filters: [{ name: "ZIP", extensions: ["zip"] }],
});
selected = typeof path === "string" ? path : null;
}
if (!selected) return;
importingZip.value = true;
progress.value = null;
try {
+10 -2
View File
@@ -179,8 +179,16 @@ export async function invalidateAgentRegistryCache(): Promise<void> {
await post("/api/agents/invalidate-registry-cache", {});
}
export async function importAgentsFromZip(_path: string): Promise<number> {
throw new Error("Offline ZIP import is only available in the desktop app");
export async function importAgentsFromZip(fileOrPath: string | File): Promise<number> {
if (typeof fileOrPath === "string") {
throw new Error("Offline ZIP import in web mode requires a File object, not a file path");
}
const formData = new FormData();
formData.append("file", fileOrPath);
const res = await fetch("/api/agents/import-offline", { method: "POST", body: formData });
if (!res.ok) throw new Error(await res.text());
const result: { count: number } = await res.json();
return result.count;
}
export async function importAgentJar(_dbType: string, _path: string): Promise<void> {
+4 -1
View File
@@ -389,7 +389,10 @@ export async function invalidateAgentRegistryCache(): Promise<void> {
return invoke("invalidate_agent_registry_cache");
}
export async function importAgentsFromZip(path: string): Promise<number> {
export async function importAgentsFromZip(path: string | File): Promise<number> {
if (typeof path !== "string") {
throw new Error("Desktop offline ZIP import requires a local file path");
}
return invoke("import_agents_from_zip", { path });
}