You've already forked DataMate
- 将 useNewVersionUsingPost 重命名为 applyNewVersionUsingPost - 添加 fileVersionCheckSeqRef 避免版本检查竞态条件 - 移除 checkingFileVersion 状态变量的渲染依赖 - 在文件版本信息中添加 annotationVersionUnknown 字段 - 修复前端文件版本比较显示的 JSX 语法 - 添加历史标注缺少版本信息的提示显示 - 配置 Alembic 异步数据库迁移环境支持 aiomysql - 添加文件版本未知状态的后端判断逻辑 - 实现标注清除时的段落注释清理功能 - 添加知识库同步钩子到版本更新流程
157 lines
4.4 KiB
TypeScript
157 lines
4.4 KiB
TypeScript
import { get, post, put, del, download } from "@/utils/request";
|
|
|
|
// 导出格式类型
|
|
export type ExportFormat = "json" | "jsonl" | "csv" | "coco" | "yolo";
|
|
|
|
type RequestParams = Record<string, unknown>;
|
|
type RequestPayload = Record<string, unknown>;
|
|
|
|
// 标注任务管理相关接口
|
|
export function queryAnnotationTasksUsingGet(params?: RequestParams) {
|
|
return get("/api/annotation/project", params);
|
|
}
|
|
|
|
export function createAnnotationTaskUsingPost(data: RequestPayload) {
|
|
return post("/api/annotation/project", data);
|
|
}
|
|
|
|
export function syncAnnotationTaskUsingPost(data: RequestPayload) {
|
|
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: RequestPayload) {
|
|
return put(`/api/annotation/project/${taskId}`, data);
|
|
}
|
|
|
|
// 标签配置管理
|
|
export function getTagConfigUsingGet() {
|
|
return get("/api/annotation/tags/config");
|
|
}
|
|
|
|
// 标注模板管理
|
|
export function queryAnnotationTemplatesUsingGet(params?: RequestParams) {
|
|
return get("/api/annotation/template", params);
|
|
}
|
|
|
|
export function createAnnotationTemplateUsingPost(data: RequestPayload) {
|
|
return post("/api/annotation/template", data);
|
|
}
|
|
|
|
export function updateAnnotationTemplateByIdUsingPut(
|
|
templateId: string | number,
|
|
data: RequestPayload
|
|
) {
|
|
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?: RequestParams) {
|
|
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 getEditorTaskSegmentUsingGet(
|
|
projectId: string,
|
|
fileId: string,
|
|
params: { segmentIndex: number }
|
|
) {
|
|
return get(`/api/annotation/editor/projects/${projectId}/tasks/${fileId}/segments`, params);
|
|
}
|
|
|
|
export function upsertEditorAnnotationUsingPut(
|
|
projectId: string,
|
|
fileId: string,
|
|
data: {
|
|
annotation: Record<string, unknown>;
|
|
expectedUpdatedAt?: string;
|
|
segmentIndex?: number;
|
|
}
|
|
) {
|
|
return put(`/api/annotation/editor/projects/${projectId}/tasks/${fileId}/annotation`, data);
|
|
}
|
|
|
|
export interface FileVersionCheckResponse {
|
|
fileId: string;
|
|
currentFileVersion: number;
|
|
annotationFileVersion: number | null;
|
|
annotationVersionUnknown: boolean;
|
|
hasNewVersion: boolean;
|
|
}
|
|
|
|
export function checkFileVersionUsingGet(projectId: string, fileId: string) {
|
|
return get(`/api/annotation/editor/projects/${projectId}/files/${fileId}/version`);
|
|
}
|
|
|
|
export interface UseNewVersionResponse {
|
|
fileId: string;
|
|
previousFileVersion: number | null;
|
|
currentFileVersion: number;
|
|
message: string;
|
|
}
|
|
|
|
export function applyNewVersionUsingPost(projectId: string, fileId: string) {
|
|
return post(`/api/annotation/editor/projects/${projectId}/files/${fileId}/use-new-version`, {});
|
|
}
|
|
|
|
|
|
// =====================
|
|
// 标注数据导出
|
|
// =====================
|
|
|
|
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);
|
|
}
|