From f1c06deffd9fc7739f3c05ba48a51191d7dfa47d Mon Sep 17 00:00:00 2001 From: Megghy Date: Wed, 28 Feb 2024 16:28:21 +0800 Subject: [PATCH] add web-fetcher --- package.json | 2 + src/api/account.ts | 2 +- src/api/api-models.ts | 20 ++- src/api/query.ts | 7 +- src/components/EventFetcherStatusCard.vue | 23 ++- src/data/DanmakuClient.ts | 102 ++++++++--- src/data/chat/ChatClientDirectOpenLive.js | 8 + src/data/chat/ChatClientOfficialBase/index.js | 10 +- src/data/constants.ts | 54 +++--- src/main.ts | 4 +- src/router/obs.ts | 8 + src/store/useWebFetcher.ts | 150 ++++++++++++++++ src/views/ManageLayout.vue | 2 +- src/views/manage/DanmakuLayout.vue | 2 +- src/views/obs/QuestionDisplayOBS.vue | 15 +- src/views/obs/WebFetcherOBS.vue | 41 +++++ src/views/others | 0 yarn.lock | 161 +++++++++++++++++- 18 files changed, 527 insertions(+), 84 deletions(-) create mode 100644 src/store/useWebFetcher.ts create mode 100644 src/views/obs/WebFetcherOBS.vue create mode 100644 src/views/others diff --git a/package.json b/package.json index 8d3ee9b..310e146 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "prepare": "husky" }, "dependencies": { + "@microsoft/signalr": "^8.0.0", + "@microsoft/signalr-protocol-msgpack": "^8.0.0", "@types/node": "^20.11.19", "@typescript-eslint/eslint-plugin": "^7.0.1", "@vicons/fluent": "^0.12.0", diff --git a/src/api/account.ts b/src/api/account.ts index 66a5e36..8ab864f 100644 --- a/src/api/account.ts +++ b/src/api/account.ts @@ -7,7 +7,7 @@ import { ref } from 'vue' import { APIRoot, AccountInfo, FunctionTypes } from './api-models' import { useRoute } from 'vue-router' -export const ACCOUNT = ref() +export const ACCOUNT = ref({} as AccountInfo) export const isLoadingAccount = ref(true) const route = useRoute() diff --git a/src/api/api-models.ts b/src/api/api-models.ts index 8a70cf2..fce7147 100644 --- a/src/api/api-models.ts +++ b/src/api/api-models.ts @@ -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 diff --git a/src/api/query.ts b/src/api/query.ts index a4970c5..977cbc0 100644 --- a/src/api/query.ts +++ b/src/api/query.ts @@ -23,7 +23,7 @@ export async function QueryPostAPIWithParams( 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( 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(url: string, body?: unknown): Promise>> { diff --git a/src/components/EventFetcherStatusCard.vue b/src/components/EventFetcherStatusCard.vue index 15aafeb..4214173 100644 --- a/src/components/EventFetcherStatusCard.vue +++ b/src/components/EventFetcherStatusCard.vue @@ -1,17 +1,18 @@