task-25: applyFilePhaseDefaults 兼容旧 Java 响应的文件阶段字段默认值

This commit is contained in:
2026-08-31 20:01:52 +08:00
parent eaf457c6c0
commit f177a15105
2 changed files with 94 additions and 0 deletions
+20
View File
@@ -35,3 +35,23 @@ export interface TaskProgressBatchVo<T = { taskId: number; status: string }> {
items: T[]
missingTaskIds: number[]
}
/**
* 旧 Java 版本响应缺少文件阶段新字段时补齐默认值,保证页面行为一致。
*/
export function applyFilePhaseDefaults<T extends ResultFilePhase>(item: T | null | undefined): T & ResultFilePhase {
const source = (item ?? {}) as Partial<ResultFilePhase>
const defaults: ResultFilePhase = {
fileReady: false,
fileStatus: 'PENDING',
fileProgress: 0,
fileProgressLabel: '',
fileProgressStage: '',
freshDownloadUrl: null,
}
const merged: ResultFilePhase = { ...defaults, ...source }
if (merged.fileStatus === 'SUCCESS' && source.fileReady === undefined) {
merged.fileReady = true
}
return merged as T & ResultFilePhase
}