47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import {
|
|
preparePerformanceSurveyImagesInBrowser,
|
|
type PerformanceSurveyBrowserProcessedImage,
|
|
} from '@/lib/performance-survey-image-browser'
|
|
|
|
export type TaskDetailAssetKind = 'main' | 'sku' | 'detail'
|
|
|
|
export type TaskDetailBrowserPreview = PerformanceSurveyBrowserProcessedImage & {
|
|
sourceIndex: number
|
|
}
|
|
|
|
/**
|
|
* 在用户浏览器中逐张生成任务-详情预览。
|
|
*
|
|
* 这里故意一次只传一张源图,避免把整批原图和 Blob 同时留在内存里。
|
|
* 详情长图只上传切片;普通主图/SKU图和短详情图上传一张预览。
|
|
*/
|
|
export async function prepareTaskDetailImagePreview(
|
|
file: File,
|
|
assetKind: TaskDetailAssetKind,
|
|
onProgress?: (label: string) => void,
|
|
options: {
|
|
signal?: AbortSignal
|
|
timeoutMs?: number
|
|
} = {},
|
|
): Promise<TaskDetailBrowserPreview[]> {
|
|
const processed = await preparePerformanceSurveyImagesInBrowser(
|
|
[file],
|
|
onProgress,
|
|
{
|
|
profile: assetKind === 'detail' ? 'task_detail_detail' : 'task_detail_preview',
|
|
signal: options.signal,
|
|
timeoutMs: options.timeoutMs,
|
|
},
|
|
)
|
|
|
|
if (assetKind === 'detail' && processed.some((item) => item.sliceCount > 1)) {
|
|
return processed.filter((item) => item.kind === 'slice')
|
|
}
|
|
|
|
const preview = processed.filter((item) => item.kind === 'preview')
|
|
if (preview.length > 0) return preview
|
|
|
|
// 极旧浏览器/worker 兼容:没有 preview 时至少保留第一张切片,不能因预览缺失阻断原图上传。
|
|
return processed.filter((item) => item.kind === 'slice').slice(0, 1)
|
|
}
|