Capital/utils/request.ts
2025-03-17 20:58:36 +08:00

27 lines
704 B
TypeScript

export async function solarFetch(input: string, init?: RequestInit) {
const auth = useUserinfo()
const config = useRuntimeConfig()
if (!input.startsWith("http")) {
input = `${config.public.solarNetworkApi}${input}`
}
return await fetch(input, {
...init,
headers: {
...init?.headers,
Authorization: `Bearer ${await auth.getAtk()}`,
},
})
}
export function getAttachmentUrl(identifier: string | undefined): string | undefined {
if (identifier == null || identifier.length == 0) {
return undefined
}
if (identifier.startsWith("http")) {
return identifier
}
return `${useRuntimeConfig().public.solarNetworkApi}/cgi/uc/attachments/${identifier}`
}