25 lines
928 B
TypeScript
25 lines
928 B
TypeScript
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)
|
||
}
|