From 50f54c81b8fadb939ce2f3ac18c19d31f8eaf5fc Mon Sep 17 00:00:00 2001 From: zihan xu Date: Sat, 13 Jun 2026 23:18:41 +0800 Subject: [PATCH 1/2] feat: support web ui runtime --- auto-imports.d.ts | 5 +- src/APIFetch.ts | 12 +- src/App.vue | 6 +- src/components/AppBackground.vue | 18 +- src/components/BatchDownloadButton.vue | 21 +- src/components/ImageVideoCard.vue | 9 +- src/components/LoginManager.vue | 55 +++-- src/components/LottieAnimationCard.vue | 30 +-- src/components/SVGACard.vue | 30 +-- src/pages/dynamic/[id].vue | 7 +- src/pages/emoji/[id].vue | 2 +- src/pages/liveroom/[id].vue | 2 +- src/pages/lottery.vue | 2 +- src/pages/settings.vue | 18 +- src/pages/space/[id].vue | 2 +- src/pages/suit/[id].vue | 2 +- src/pages/tool/webp.vue | 15 +- src/runtime/environment.ts | 17 ++ src/runtime/files.ts | 305 +++++++++++++++++++++++++ src/runtime/http.ts | 67 ++++++ src/runtime/path.ts | 18 ++ src/runtime/store.ts | 121 ++++++++++ src/runtime/window.ts | 60 +++++ src/store/useWbiStore/api/index.ts | 6 +- src/store/useWbiStore/internal.ts | 6 +- src/utils/cliboardListener.ts | 15 +- src/utils/deviceUtils.ts | 11 +- src/utils/downloadManager.ts | 15 +- src/utils/globalConfig.ts | 6 +- src/utils/image.ts | 6 +- src/utils/linkResolver.ts | 5 +- src/utils/loginManager.ts | 6 +- vite.config.ts | 45 +++- 33 files changed, 818 insertions(+), 127 deletions(-) create mode 100644 src/runtime/environment.ts create mode 100644 src/runtime/files.ts create mode 100644 src/runtime/http.ts create mode 100644 src/runtime/path.ts create mode 100644 src/runtime/store.ts create mode 100644 src/runtime/window.ts diff --git a/auto-imports.d.ts b/auto-imports.d.ts index 0d08853..bbdeab0 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -36,7 +36,6 @@ declare global { const eagerComputed: typeof import('@vueuse/core')['eagerComputed'] const effectScope: typeof import('vue')['effectScope'] const extendRef: typeof import('@vueuse/core')['extendRef'] - const fetch: typeof import('@tauri-apps/plugin-http')['fetch'] const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentScope: typeof import('vue')['getCurrentScope'] const h: typeof import('vue')['h'] @@ -298,6 +297,7 @@ declare global { export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' import('vue') } + // for vue template auto import import { UnwrapRef } from 'vue' declare module 'vue' { @@ -333,7 +333,6 @@ declare module 'vue' { readonly eagerComputed: UnwrapRef readonly effectScope: UnwrapRef readonly extendRef: UnwrapRef - readonly fetch: UnwrapRef readonly getCurrentInstance: UnwrapRef readonly getCurrentScope: UnwrapRef readonly h: UnwrapRef @@ -589,4 +588,4 @@ declare module 'vue' { readonly watchWithFilter: UnwrapRef readonly whenever: UnwrapRef } -} +} \ No newline at end of file diff --git a/src/APIFetch.ts b/src/APIFetch.ts index 1bf441c..ea160ba 100644 --- a/src/APIFetch.ts +++ b/src/APIFetch.ts @@ -1,14 +1,14 @@ -import { LazyStore } from '@tauri-apps/plugin-store'; import { clearLoginCookie, getLoginCookie, userLoggedIn } from "./utils/loginManager.ts"; import { GeneralAPIResponse } from "./types.ts"; import { encWbiWithFetch } from "./utils/wbi.ts"; import { useWbiStore } from "./store/useWbiStore"; import { setDebugInfo } from "./utils/debug.ts"; import md5 from "md5"; -import { ClientOptions, fetch } from "@tauri-apps/plugin-http"; import { globalConfig } from "./utils/globalConfig.ts"; +import { createRuntimeStore } from "./runtime/store.ts"; +import { runtimeFetch } from "./runtime/http.ts"; -const store = new LazyStore('APIResponseCache', { +const store = createRuntimeStore('APIResponseCache', { // 不要持久化请求缓存 autoSave: false }) @@ -94,7 +94,7 @@ async function APIFetch(url: URL | string, init?: RequestInit, extraOptions?: cookie = await getLoginCookie() } - const options: RequestInit & ClientOptions = { + const options: RequestInit = { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0', // 无cookie时,填写这几个参数貌似也能过一些验证 @@ -110,7 +110,7 @@ async function APIFetch(url: URL | string, init?: RequestInit, extraOptions?: let json: GeneralAPIResponse do { - json = await fetch(parsedURL, finalOptions).then(r => r.json()) as GeneralAPIResponse + json = await runtimeFetch(parsedURL, finalOptions).then(r => r.json()) as GeneralAPIResponse if (json.code !== 0) { if ((json.code === -352 || json.code === -403) && retryCount < 1) { @@ -160,4 +160,4 @@ async function clearAPICache() { await store.clear() } -export { APIFetch, clearAPICache } \ No newline at end of file +export { APIFetch, clearAPICache } diff --git a/src/App.vue b/src/App.vue index 23a68f8..b28e237 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,13 +1,13 @@