front/src/api/plugin/index.ts

25 lines
928 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { axiosInstance } from '@/api/rbac'
import { assertBusinessOk, omsUrl } from '@/api/oms/common'
function unwrapData<T = any>(body: any): T {
assertBusinessOk(body)
// 兼容 {code,data} 包裹,以及直接返回 JSON 字符串/对象
if (body != null && typeof body === 'object' && ('data' in body || 'Data' in body)) {
const nested = body.data ?? body.Data
if (nested !== undefined) return nested as T
}
return body as T
}
/** 读取采集草稿(key 来自插件 add) */
export async function getPluginPackage(key: string) {
const res = await axiosInstance.get(omsUrl('/plugin/browser/getPackage'), { params: { key } })
return unwrapData<string>(res.data)
}
/** 插件确认页默认仓库 */
export async function getPluginWhseInfo() {
const res = await axiosInstance.get(omsUrl('/plugin/browser/getPluginWhseInfo'))
return unwrapData<{ id: number; name: string } | null>(res.data)
}