You've already forked DataMate
- 移除前端手动创建 a 标签下载文件的方式 - 将文件名参数传递给后端 API 函数 - 利用 download 函数内置的下载处理机制 - 简化 ExportAnnotationDialog 组件中的导出流程 - 更新 annotation.api.ts 中的 downloadAnnotationsUsingGet 函数签名 - 直接通过 API 调用完成文件下载和命名
122 lines
3.4 KiB
TypeScript
122 lines
3.4 KiB
TypeScript
import { get, post, put, del, download } from "@/utils/request";
|
|
|
|
// 导出格式类型
|
|
export type ExportFormat = "json" | "jsonl" | "csv" | "coco" | "yolo";
|
|
|
|
// 标注任务管理相关接口
|
|
export function queryAnnotationTasksUsingGet(params?: any) {
|
|
return get("/api/annotation/project", params);
|
|
}
|
|
|
|
export function createAnnotationTaskUsingPost(data: any) {
|
|
return post("/api/annotation/project", data);
|
|
}
|
|
|
|
export function syncAnnotationTaskUsingPost(data: any) {
|
|
return post(`/api/annotation/task/sync`, data);
|
|
}
|
|
|
|
export function deleteAnnotationTaskByIdUsingDelete(mappingId: string) {
|
|
// Backend expects mapping UUID as path parameter
|
|
return del(`/api/annotation/project/${mappingId}`);
|
|
}
|
|
|
|
export function getAnnotationTaskByIdUsingGet(taskId: string) {
|
|
return get(`/api/annotation/project/${taskId}`);
|
|
}
|
|
|
|
export function updateAnnotationTaskByIdUsingPut(taskId: string, data: any) {
|
|
return put(`/api/annotation/project/${taskId}`, data);
|
|
}
|
|
|
|
// 标签配置管理
|
|
export function getTagConfigUsingGet() {
|
|
return get("/api/annotation/tags/config");
|
|
}
|
|
|
|
// 标注模板管理
|
|
export function queryAnnotationTemplatesUsingGet(params?: any) {
|
|
return get("/api/annotation/template", params);
|
|
}
|
|
|
|
export function createAnnotationTemplateUsingPost(data: any) {
|
|
return post("/api/annotation/template", data);
|
|
}
|
|
|
|
export function updateAnnotationTemplateByIdUsingPut(
|
|
templateId: string | number,
|
|
data: any
|
|
) {
|
|
return put(`/api/annotation/template/${templateId}`, data);
|
|
}
|
|
|
|
export function deleteAnnotationTemplateByIdUsingDelete(
|
|
templateId: string | number
|
|
) {
|
|
return del(`/api/annotation/template/${templateId}`);
|
|
}
|
|
|
|
|
|
// =====================
|
|
// Label Studio Editor(内嵌版)
|
|
// =====================
|
|
|
|
export function getEditorProjectInfoUsingGet(projectId: string) {
|
|
return get(`/api/annotation/editor/projects/${projectId}`);
|
|
}
|
|
|
|
export function listEditorTasksUsingGet(projectId: string, params?: any) {
|
|
return get(`/api/annotation/editor/projects/${projectId}/tasks`, params);
|
|
}
|
|
|
|
export function getEditorTaskUsingGet(
|
|
projectId: string,
|
|
fileId: string,
|
|
params?: { segmentIndex?: number }
|
|
) {
|
|
return get(`/api/annotation/editor/projects/${projectId}/tasks/${fileId}`, params);
|
|
}
|
|
|
|
export function upsertEditorAnnotationUsingPut(
|
|
projectId: string,
|
|
fileId: string,
|
|
data: {
|
|
annotation: any;
|
|
expectedUpdatedAt?: string;
|
|
segmentIndex?: number;
|
|
}
|
|
) {
|
|
return put(`/api/annotation/editor/projects/${projectId}/tasks/${fileId}/annotation`, data);
|
|
}
|
|
|
|
// =====================
|
|
// 标注数据导出
|
|
// =====================
|
|
|
|
export interface ExportStatsResponse {
|
|
projectId: string;
|
|
projectName: string;
|
|
totalFiles: number;
|
|
annotatedFiles: number;
|
|
exportFormat: string;
|
|
}
|
|
|
|
export function getExportStatsUsingGet(projectId: string) {
|
|
return get(`/api/annotation/export/projects/${projectId}/stats`);
|
|
}
|
|
|
|
export function downloadAnnotationsUsingGet(
|
|
projectId: string,
|
|
format: ExportFormat = "json",
|
|
onlyAnnotated: boolean = true,
|
|
includeData: boolean = false,
|
|
filename?: string
|
|
) {
|
|
const params = new URLSearchParams({
|
|
format,
|
|
only_annotated: String(onlyAnnotated),
|
|
include_data: String(includeData),
|
|
});
|
|
return download(`/api/annotation/export/projects/${projectId}/download?${params.toString()}`, null, filename);
|
|
}
|