add web-fetcher

This commit is contained in:
2024-02-28 16:28:21 +08:00
parent 40fdc93fec
commit f1c06deffd
18 changed files with 527 additions and 84 deletions

View File

@@ -23,7 +23,7 @@ export async function QueryPostAPIWithParams<T>(
const url = new URL(urlString)
url.search = getParams(params)
headers ??= []
headers?.push(['Authorization', `Bearer ${cookie.value}`])
if (cookie.value) headers?.push(['Authorization', `Bearer ${cookie.value}`])
if (contentType) headers?.push(['Content-Type', contentType])
@@ -55,7 +55,7 @@ export async function QueryGetAPI<T>(
url.search = getParams(params)
if (cookie.value) {
headers ??= []
headers?.push(['Authorization', `Bearer ${cookie.value}`])
if (cookie.value) headers?.push(['Authorization', `Bearer ${cookie.value}`])
}
try {
const data = await fetch(url.toString(), {
@@ -81,6 +81,9 @@ function getParams(params?: [string, string][]) {
if (urlParams.has('as')) {
resultParams.set('as', urlParams.get('as') || '')
}
if (urlParams.has('token')) {
resultParams.set('token', urlParams.get('token') || '')
}
return resultParams.toString()
}
export async function QueryPostPaginationAPI<T>(url: string, body?: unknown): Promise<APIRoot<PaginationResponse<T>>> {