162 lines
4.0 KiB
TypeScript
162 lines
4.0 KiB
TypeScript
import httpFetch from "@/api/fetch"
|
|
import { BASE_LABEL_API } from "../const"
|
|
import {
|
|
LabelResult,
|
|
LoginInfo,
|
|
RequestLabelResult,
|
|
ServerResponse,
|
|
} from "./typing"
|
|
|
|
// 获取标注结果
|
|
export const getLabelResult = (task_id: number) => {
|
|
return httpFetch<{
|
|
task_id: number
|
|
results: LabelResult[]
|
|
}>({
|
|
url:
|
|
BASE_LABEL_API +
|
|
`/api/v1/label_server/task/label_result?task_id=${task_id}`,
|
|
method: "GET",
|
|
})
|
|
}
|
|
|
|
export const saveLabelResult = (data: RequestLabelResult) => {
|
|
return httpFetch({
|
|
url: BASE_LABEL_API + "/api/v1/label_server/task/label_result",
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
})
|
|
}
|
|
|
|
export const getServerImage = async (data: {
|
|
data_names: string[]
|
|
/**
|
|
* 0-图片 1-点云 2-视频
|
|
*/
|
|
data_type: number
|
|
flag?: number
|
|
project_id: number
|
|
}) => {
|
|
const res = await httpFetch<ServerResponse>({
|
|
url: BASE_LABEL_API + "/api/v1/label_server/data/list",
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
})
|
|
|
|
if (res.proxy) {
|
|
throw new Error(`get_data_list requires proxy=${res.proxy}`)
|
|
}
|
|
|
|
const first = res.data_list?.[0]
|
|
if (!first) {
|
|
throw new Error(
|
|
`get_data_list empty data_list, data_name=${data.data_names?.[0] || ""}`
|
|
)
|
|
}
|
|
|
|
const payload =
|
|
data.data_type === 0
|
|
? first.image_data
|
|
: data.data_type === 2
|
|
? first.video_data
|
|
: first.pointcloud_data
|
|
|
|
if (payload == null) {
|
|
throw new Error(
|
|
`get_data_list missing payload type=${data.data_type}, data_name=${first.data_name || data.data_names?.[0] || ""}`
|
|
)
|
|
}
|
|
if (typeof payload === "string" && !payload.trim()) {
|
|
throw new Error(
|
|
`get_data_list empty payload type=${data.data_type}, data_name=${first.data_name || data.data_names?.[0] || ""}`
|
|
)
|
|
}
|
|
|
|
return payload
|
|
// .catch(async ({ proxy, params }) => {
|
|
// try {
|
|
// const res = await httpFetch<ServerResponse>({
|
|
// url: `/http://${proxy}:9112/api/v1/label_sync/get_data_list`,
|
|
// method: "POST",
|
|
// body: JSON.stringify(params),
|
|
// })
|
|
// return res.data.data_list?.[0].image_data || ""
|
|
// } catch (error: unknown) {
|
|
// console.log(error)
|
|
// const res = await httpFetch<ServerResponse>({
|
|
// url: BASE_LABEL_API + "/api/v1/label_server/data/list",
|
|
// method: "POST",
|
|
// body: JSON.stringify({ ...params, flag: 1 }),
|
|
// })
|
|
// return res.data_list?.[0].image_data || ""
|
|
// }
|
|
// })
|
|
}
|
|
|
|
// 获取标注图片
|
|
export const getLabelImage = (activeImage: string, path: string) => {
|
|
return httpFetch<any>({
|
|
url:
|
|
BASE_LABEL_API +
|
|
`/api/v1/label_server/data/image?data_name=${encodeURIComponent(
|
|
activeImage
|
|
)}&project_path=${encodeURIComponent(path)}`,
|
|
method: "GET",
|
|
headerAttr: {
|
|
responseType: "blob",
|
|
},
|
|
})
|
|
}
|
|
|
|
// 辅助标注
|
|
export const getAuxiliaryAnnotation = (data: any) => {
|
|
return httpFetch<any>({
|
|
url: BASE_LABEL_API + "/api/model_server/sam2/sa",
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
headerAttr: {
|
|
responseType: "arraybuffer",
|
|
},
|
|
})
|
|
}
|
|
|
|
export const getAuxiliaryAnnotation2 = (data: {
|
|
project_id: string
|
|
image_name: string
|
|
prompt: {
|
|
foreground_points?: Array<[number, number]>
|
|
background_points?: Array<[number, number]>
|
|
boxes?: Array<[number, number, number, number]>
|
|
}
|
|
}) => {
|
|
return httpFetch<{
|
|
contours: Array<Array<[[number, number]]>>
|
|
hollows: Array<boolean>
|
|
}>({
|
|
url: "http://172.30.21.211:9000/image_predictor",
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
})
|
|
}
|
|
|
|
// 模型标注 追踪
|
|
export const getTrackingAuxiliaryAnnotation = (data: any) => {
|
|
return httpFetch<any>({
|
|
url: BASE_LABEL_API + "/api/model_server/sam2/vos",
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
headerAttr: {
|
|
responseType: "arraybuffer",
|
|
},
|
|
})
|
|
}
|
|
|
|
// 用户登录
|
|
export const userLogin = (data: { name: string; password: string }) => {
|
|
return httpFetch<LoginInfo>({
|
|
url: BASE_LABEL_API + "/api/v1/label_server/user/login",
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
})
|
|
}
|