ffebaa7249
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 57s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m9s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m37s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 3m44s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m44s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m35s
CI/CD Pipeline / Build Staging API Image (push) Successful in 6m46s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m13s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 38s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 1m24s
CI/CD Pipeline / Integration Tests (push) Successful in 4m8s
CI/CD Pipeline / Unit Tests (push) Successful in 11m20s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / CI Gate (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m26s
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
/**
|
|
* 素材库 API(对接 /assets 接口,映射为 MediaAsset 类型)
|
|
*/
|
|
import apiClient from "../client"
|
|
import type { AssetItem } from "../assets"
|
|
import type { MediaAsset } from "./types"
|
|
|
|
const inferMediaType = (mimeType: string): "video" | "image" | "audio" => {
|
|
if (mimeType.startsWith("video/")) return "video"
|
|
if (mimeType.startsWith("image/")) return "image"
|
|
return "audio"
|
|
}
|
|
|
|
const mapAssetToMediaAsset = (asset: AssetItem): MediaAsset => {
|
|
const metaDuration =
|
|
typeof asset.metadata?.duration === "number" ? asset.metadata.duration : undefined
|
|
return {
|
|
id: asset.id,
|
|
name: asset.name,
|
|
type: inferMediaType(asset.mime_type || ""),
|
|
source_url: asset.file_url,
|
|
thumbnail_url: asset.thumbnail_url,
|
|
duration: asset.duration ?? metaDuration,
|
|
size: asset.file_size ?? undefined,
|
|
tags: [],
|
|
created_at: asset.created_at ?? "",
|
|
quality_score: asset.quality_score ?? undefined,
|
|
classification_status: asset.classification_status ?? undefined,
|
|
}
|
|
}
|
|
|
|
/** 获取素材库列表 */
|
|
export async function getMediaAssets(libraryId?: string): Promise<MediaAsset[]> {
|
|
const response = await apiClient.get("/assets", {
|
|
params: libraryId ? { library_id: libraryId } : undefined,
|
|
})
|
|
const items: AssetItem[] = response.data.items || []
|
|
return items.map(mapAssetToMediaAsset)
|
|
}
|
|
|
|
/** 获取单个素材 */
|
|
export async function getMediaAsset(id: string): Promise<MediaAsset> {
|
|
const response = await apiClient.get(`/assets/${id}`)
|
|
return mapAssetToMediaAsset(response.data)
|
|
}
|