feat(project): init
This commit is contained in:
139
components/label/api/label/index.ts
Normal file
139
components/label/api/label/index.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import httpFetch from "@/api/fetch"
|
||||
import {
|
||||
LabelResult,
|
||||
LoginInfo,
|
||||
RequestLabelResult,
|
||||
ServerResponse,
|
||||
} from "./typing"
|
||||
import { usePermissionStore } from "../../store/auth"
|
||||
|
||||
export const BASE_LABEL_API = "https://label.cowarobot.com"
|
||||
|
||||
// 获取标注结果
|
||||
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",
|
||||
headerAttr: {
|
||||
["Token"]: usePermissionStore.getState().token,
|
||||
["Refresh-Token"]: usePermissionStore.getState().refresh_token,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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-点云
|
||||
*/
|
||||
data_type: number
|
||||
flag?: number
|
||||
project_id: number
|
||||
}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
httpFetch<ServerResponse>({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/data/list",
|
||||
method: "post",
|
||||
body: JSON.stringify(data),
|
||||
headerAttr: {
|
||||
["Token"]: usePermissionStore.getState().token,
|
||||
["Refresh-Token"]: usePermissionStore.getState().refresh_token,
|
||||
},
|
||||
}).then((res) => {
|
||||
if (res.proxy) {
|
||||
reject({ proxy: res.proxy, params: data })
|
||||
} else {
|
||||
if (res.data_list && res.data_list.length) {
|
||||
const { image_data } = res.data_list[0]
|
||||
resolve({ image_data })
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(({ image_data }: any) => {
|
||||
return image_data
|
||||
})
|
||||
.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 }),
|
||||
headerAttr: {
|
||||
["Token"]: usePermissionStore.getState().token,
|
||||
["Refresh-Token"]: usePermissionStore.getState().refresh_token,
|
||||
},
|
||||
})
|
||||
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 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),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user