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

@@ -7,7 +7,7 @@ import { ref } from 'vue'
import { APIRoot, AccountInfo, FunctionTypes } from './api-models'
import { useRoute } from 'vue-router'
export const ACCOUNT = ref<AccountInfo>()
export const ACCOUNT = ref<AccountInfo>({} as AccountInfo)
export const isLoadingAccount = ref(true)
const route = useRoute()

View File

@@ -30,6 +30,20 @@ export interface UserInfo {
streamerInfo?: StreamerModel
}
}
export interface EventFetcherStateModel {
online: boolean
status: { [errorCode: string]: string }
version?: string
todayReceive: number
useCookie: boolean
type: EventFetcherType
}
export enum EventFetcherType {
Application,
OBS,
Server,
}
export interface AccountInfo extends UserInfo {
isEmailVerified: boolean
isBiliVerified: boolean
@@ -41,11 +55,7 @@ export interface AccountInfo extends UserInfo {
biliAuthCode?: string
biliAuthCodeStatus: BiliAuthCodeStatusType
eventFetcherOnline: boolean
eventFetcherStatus: string
eventFetcherStatusV3: { [errorCode: string]: string }
eventFetcherTodayReceive: number
eventFetcherVersion?: string
eventFetcherState: EventFetcherStateModel
nextSendEmailTime?: number
isServerFetcherOnline: boolean

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>>> {