task-104(任务与重复分析中心): 实现视频任务详情展示
image-video-model.ts 增加 ImageVideoDetail 与 parseImageVideoDetail(脱敏 request/
submit_response/result + error_message/archived_at),image-video-api.ts 增加
fetchImageVideoTaskDetail(GET /api/admin/image-video-tasks/{id})。
TDD: task-104.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/** 视频任务列表加载适配(任务 103):GET /api/admin/image-video-tasks + 筛选归一与解析。 */
|
||||
/** 视频任务列表/详情适配(任务 103/104):GET /api/admin/image-video-tasks(/detail)。 */
|
||||
import { http } from '@/api/http'
|
||||
import { parseImageVideoPage, type ImageVideoPageResult } from './image-video-model.ts'
|
||||
import { parseImageVideoDetail, parseImageVideoPage, type ImageVideoDetail, type ImageVideoPageResult } from './image-video-model.ts'
|
||||
import { toImageVideoQuery, type ImageVideoFilter } from './image-video-filter.ts'
|
||||
|
||||
export const IMAGE_VIDEO_TASKS_ENDPOINT = '/api/admin/image-video-tasks'
|
||||
@@ -15,3 +15,9 @@ export async function fetchImageVideoTasks(
|
||||
})
|
||||
return parseImageVideoPage(data)
|
||||
}
|
||||
|
||||
/** 查询单任务详情(含脱敏 request/结果 JSON):GET /api/admin/image-video-tasks/{taskId}。 */
|
||||
export async function fetchImageVideoTaskDetail(taskId: string | number): Promise<ImageVideoDetail> {
|
||||
const { data } = await http.get<unknown>(`${IMAGE_VIDEO_TASKS_ENDPOINT}/${taskId}`)
|
||||
return parseImageVideoDetail(data)
|
||||
}
|
||||
|
||||
@@ -139,3 +139,39 @@ export function parseImageVideoPage(payload: unknown): ImageVideoPageResult {
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
|
||||
/** 单任务详情(含脱敏 request/结果 JSON),见任务 104。 */
|
||||
export interface ImageVideoDetail extends ImageVideoRow {
|
||||
errorMessage: string
|
||||
archivedAt?: string
|
||||
request: Record<string, unknown>
|
||||
submitResponse: Record<string, unknown>
|
||||
result: Record<string, unknown>
|
||||
}
|
||||
|
||||
function objectOrEmpty(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : {}
|
||||
}
|
||||
|
||||
/** 解析单任务详情负载(data.item + includeJson 字段);缺 item/无效任务抛可操作错误。 */
|
||||
export function parseImageVideoDetail(payload: unknown): ImageVideoDetail {
|
||||
const core = unwrap<unknown>(payload)
|
||||
const record = core && typeof core === 'object' ? (core as Record<string, unknown>) : {}
|
||||
const itemRaw = record.item
|
||||
if (!itemRaw || typeof itemRaw !== 'object') {
|
||||
throw new Error('视频任务详情响应异常:缺少 item')
|
||||
}
|
||||
const base = toImageVideoRow(itemRaw)
|
||||
if (!base) {
|
||||
throw new Error('视频任务详情响应异常:任务无效')
|
||||
}
|
||||
const detail = base as ImageVideoDetail
|
||||
const r = itemRaw as Record<string, unknown>
|
||||
detail.errorMessage = text(r.error_message ?? r.errorMessage)
|
||||
const archivedAt = text(r.archived_at ?? r.archivedAt)
|
||||
if (archivedAt) detail.archivedAt = archivedAt
|
||||
detail.request = objectOrEmpty(r.request)
|
||||
detail.submitResponse = objectOrEmpty(r.submit_response ?? r.submitResponse)
|
||||
detail.result = objectOrEmpty(r.result)
|
||||
return detail
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user