抽出资源落盘判据 isResourceCanvasExportable,资源面板与工具条共用一条口径

- resourceCanvasAssetTransferModel.ts 新增 isResourceCanvasExportable:只有拿得到可落盘本地文件路径的资源(version 为空且 path 非空)才允许保存

- resolveResourceCanvasPanelEntries 的 downloadable 改为调用该判据,去掉内联的同一段表达式

- 纯重构,资源面板行为不变;目的是让画布工具条的下载放行判据与资源面板使用同一个权威口径,不再写第二份
This commit is contained in:
2026-09-10 18:05:02 +08:00
parent c9413fae0c
commit 93ddb841cd
@@ -28,6 +28,19 @@ export type ResourceCanvasPanelEntryInput = {
previewError: string | null;
};
/**
* 资源能否落盘到用户本地。
*
* 保存走的是本地文件复制(原生保存对话框 + Rust 分块拷贝),因此只要求有可读路径;
* 虚拟版本条目没有对应文件,拿不到路径就不放行。资源面板的「下载」与画布工具条的
* 「下载按钮」共用这一条判据,不要在别处再写第二份。
*/
export function isResourceCanvasExportable(
resource: Pick<ProjectResource, 'version' | 'path'>,
) {
return resource.version === undefined && resource.path !== '';
}
export function resolveResourceCanvasPanelEntries(
inputs: readonly ResourceCanvasPanelEntryInput[],
): ResourceCanvasPanelEntry[] {
@@ -39,9 +52,7 @@ export function resolveResourceCanvasPanelEntries(
path: input.resource.path,
mediaType: input.resource.mediaType,
selectable: true,
// 保存走本地文件复制,因此只要求有可读路径;虚拟版本条目没有文件,不能保存。
downloadable:
input.resource.version === undefined && input.resource.path !== '',
downloadable: isResourceCanvasExportable(input.resource),
previewIdentity: input.previewIdentity,
previewSourceUrl: input.previewSourceUrl,
previewStatus: input.previewStatus,