import type { PlatformApiClient } from "../api/client"; import type { ServerFileDownloadResponse } from "../api/types"; import { downloadArtifactReference, safeArtifactFilename, saveArtifactBlob } from "./artifactTransfer"; export async function downloadServerFileResult(client: PlatformApiClient, result: ServerFileDownloadResponse): Promise { if (result.status !== "ready") { return result.reason ?? "文件读取任务已派发,完成后可再次下载。"; } if (result.content !== undefined) { saveArtifactBlob(new Blob([result.content], { type: result.contentType ?? "text/plain;charset=utf-8" }), result.filename || "server-file.txt"); return `下载已开始:${result.filename || result.key}`; } if (!result.artifact) { return "文件内容尚未可用。"; } await downloadArtifactReference(result.artifact, (artifactId) => client.downloadArtifactContent(artifactId)); return `下载已开始:${safeArtifactFilename(result.filename || result.artifact.filename)}`; }