From c853fa2cebbfc159fc715860102c4d31af2821ab Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 26 Jul 2026 17:17:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(api):=20=E6=8B=86=E5=88=86=20duplicati?= =?UTF-8?q?on.ts=20=E4=B8=BA=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=EF=BC=88t?= =?UTF-8?q?ypes/duplication/index=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 99 行的 duplication.ts 拆分为目录化结构: - types.ts: 类型定义(查重记录/片段/详情/响应) - duplication.ts: 全部 5 个 API 函数 - index.ts: 统一入口 re-export,保持 @/api/duplication 路径向后兼容 --- apps/web/src/api/duplication/duplication.ts | 38 ++++++++++++++++++ apps/web/src/api/duplication/index.ts | 22 +++++++++++ .../{duplication.ts => duplication/types.ts} | 39 +------------------ 3 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 apps/web/src/api/duplication/duplication.ts create mode 100644 apps/web/src/api/duplication/index.ts rename apps/web/src/api/{duplication.ts => duplication/types.ts} (53%) diff --git a/apps/web/src/api/duplication/duplication.ts b/apps/web/src/api/duplication/duplication.ts new file mode 100644 index 000000000..7cd9be74e --- /dev/null +++ b/apps/web/src/api/duplication/duplication.ts @@ -0,0 +1,38 @@ +/** + * 查重 API 函数 + */ +import apiClient from "../client" +import type { DuplicationDetail, DuplicationRecord, DuplicationUploadResponse } from "./types" + +/** 上传视频进行查重 */ +export const uploadForDuplication = async (file: File): Promise => { + const formData = new FormData() + formData.append("file", file) + const response = await apiClient.post("/duplication/upload", formData, { + headers: { "Content-Type": "multipart/form-data" }, + }) + return response.data +} + +/** 获取查重记录列表 */ +export const getDuplicationRecords = async (): Promise => { + const response = await apiClient.get("/duplication/records") + return response.data +} + +/** 获取查重详情 */ +export const getDuplicationDetail = async (recordId: string): Promise => { + const response = await apiClient.get(`/duplication/records/${recordId}`) + return response.data +} + +/** 删除查重记录 */ +export const deleteDuplicationRecord = async (recordId: string): Promise => { + await apiClient.delete(`/duplication/records/${recordId}`) +} + +/** 重新查重 */ +export const retryDuplication = async (recordId: string): Promise => { + const response = await apiClient.post(`/duplication/records/${recordId}/retry`) + return response.data +} diff --git a/apps/web/src/api/duplication/index.ts b/apps/web/src/api/duplication/index.ts new file mode 100644 index 000000000..21564a8ba --- /dev/null +++ b/apps/web/src/api/duplication/index.ts @@ -0,0 +1,22 @@ +/** + * 查重 API — 目录化入口 + * 保持与原 duplication.ts 相同导出,向后兼容 + */ + +// 类型 +export type { + DuplicationStatus, + DuplicationRecord, + DuplicateSegment, + DuplicationDetail, + DuplicationUploadResponse, +} from "./types" + +// API 函数 +export { + uploadForDuplication, + getDuplicationRecords, + getDuplicationDetail, + deleteDuplicationRecord, + retryDuplication, +} from "./duplication" diff --git a/apps/web/src/api/duplication.ts b/apps/web/src/api/duplication/types.ts similarity index 53% rename from apps/web/src/api/duplication.ts rename to apps/web/src/api/duplication/types.ts index 1135b8163..1566c79a1 100644 --- a/apps/web/src/api/duplication.ts +++ b/apps/web/src/api/duplication/types.ts @@ -1,8 +1,6 @@ /** - * 查重 API 模块 - * 提供视频查重相关接口 + * 查重相关类型定义 */ -import apiClient from "./client" /** 查重记录状态 */ export type DuplicationStatus = "pending" | "processing" | "completed" | "failed" @@ -62,38 +60,3 @@ export interface DuplicationUploadResponse { /** 消息 */ message: string } - -// ============ API 函数 ============ - -/** 上传视频进行查重 */ -export const uploadForDuplication = async (file: File): Promise => { - const formData = new FormData() - formData.append("file", file) - const response = await apiClient.post("/duplication/upload", formData, { - headers: { "Content-Type": "multipart/form-data" }, - }) - return response.data -} - -/** 获取查重记录列表 */ -export const getDuplicationRecords = async (): Promise => { - const response = await apiClient.get("/duplication/records") - return response.data -} - -/** 获取查重详情 */ -export const getDuplicationDetail = async (recordId: string): Promise => { - const response = await apiClient.get(`/duplication/records/${recordId}`) - return response.data -} - -/** 删除查重记录 */ -export const deleteDuplicationRecord = async (recordId: string): Promise => { - await apiClient.delete(`/duplication/records/${recordId}`) -} - -/** 重新查重 */ -export const retryDuplication = async (recordId: string): Promise => { - const response = await apiClient.post(`/duplication/records/${recordId}/retry`) - return response.data -}