52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
/**
|
|
* 素材批量操作 API
|
|
*/
|
|
import apiClient from "../client"
|
|
import type { BatchOperationResult } from "./types"
|
|
|
|
/** 统一批量操作结果归一化,防御后端字段缺失或格式不一致 */
|
|
export const normalizeBatchResult = (raw: Record<string, unknown>): BatchOperationResult => {
|
|
const succeeded = Array.isArray(raw.succeeded) ? (raw.succeeded as string[]) : []
|
|
const failed = Array.isArray(raw.failed) ? (raw.failed as string[]) : []
|
|
const success_count = typeof raw.success_count === "number" ? raw.success_count : succeeded.length
|
|
const failure_count = typeof raw.failure_count === "number" ? raw.failure_count : failed.length
|
|
const total = typeof raw.total === "number" ? raw.total : success_count + failure_count
|
|
return { succeeded, failed, total, success_count, failure_count }
|
|
}
|
|
|
|
/** 批量删除素材 */
|
|
export const batchDeleteAssets = async (assetIds: string[]): Promise<BatchOperationResult> => {
|
|
const response = await apiClient.post("/assets/batch-delete", {
|
|
asset_ids: assetIds,
|
|
})
|
|
return normalizeBatchResult((response.data || {}) as Record<string, unknown>)
|
|
}
|
|
|
|
/** 批量打标签 */
|
|
export const batchTagAssets = async (data: {
|
|
asset_ids: string[]
|
|
tags: string[]
|
|
mode: "add" | "replace"
|
|
}): Promise<BatchOperationResult> => {
|
|
const response = await apiClient.post("/assets/batch-tag", data)
|
|
return normalizeBatchResult((response.data || {}) as Record<string, unknown>)
|
|
}
|
|
|
|
/** 批量改分类 */
|
|
export const batchClassifyAssets = async (data: {
|
|
asset_ids: string[]
|
|
category: string
|
|
}): Promise<BatchOperationResult> => {
|
|
const response = await apiClient.post("/assets/batch-classify", data)
|
|
return normalizeBatchResult((response.data || {}) as Record<string, unknown>)
|
|
}
|
|
|
|
/** 批量智能标记 */
|
|
export const batchMarkAssets = async (data: {
|
|
asset_ids: string[]
|
|
smart_view: "recommended" | "caution" | "high_risk"
|
|
}): Promise<BatchOperationResult> => {
|
|
const response = await apiClient.post("/assets/batch-mark", data)
|
|
return normalizeBatchResult((response.data || {}) as Record<string, unknown>)
|
|
}
|