diff --git a/README.md b/README.md index efd77da..abde889 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,88 @@ biliresourcedownloader_版本号_x64-setup.exe` ## 文档 -WIP +### Web UI 本机部署 + +Web UI 适合在浏览器中临时使用本项目功能,不需要安装桌面端。由于浏览器不能直接跨域访问 B 站接口,也不能直接设置 `Cookie` 请求头,Web UI 必须通过本项目内置的 Vite 本地代理运行,不建议将 `dist` 目录直接部署到普通静态站点。 + +1. 安装依赖 + + ```bash + npm install + ``` + + 如果本机使用 Yarn,也可以执行: + + ```bash + yarn install + ``` + +2. 开发模式运行 + + ```bash + npm run dev -- --host 127.0.0.1 + ``` + + 默认端口为 `1420`。浏览器打开终端输出的本地地址即可使用。 + +3. 构建并以预览模式部署 + + ```bash + npm run build + npm run preview -- --host 127.0.0.1 --port 4173 + ``` + + 访问 `http://127.0.0.1:4173/`。 + +4. 登录与下载说明 + + - Web UI 的扫码登录依赖本地代理转发登录 Cookie,请保持页面从 `127.0.0.1` 或 `localhost` 的 Vite 服务访问。 + - 批量下载目录选择依赖浏览器的 File System Access API。支持该 API 的 Chromium 系浏览器可以选择本地目录并按资源结构写入文件;不支持时会回退到浏览器默认下载目录。 + - 桌面端 Tauri 版本仍然支持原生文件选择、下载和本地存储能力,长期使用建议优先使用桌面版。 + +### 桌面 App 打包 + +桌面端使用 Tauri v2 打包。打包前请先安装对应系统的 Tauri 前置依赖,包括 Rust、平台 WebView 依赖和系统构建工具;本项目的 Tauri 配置会在打包前执行 `bun run build`,因此还需要安装 Bun。 + +1. 安装前置工具 + + - 安装 [Rust](https://www.rust-lang.org/tools/install) + - 按照 [Tauri v2 前置依赖文档](https://v2.tauri.app/start/prerequisites/) 安装当前系统所需依赖 + - 安装 [Bun](https://bun.sh/) + +2. 安装前端依赖 + + ```bash + bun install + ``` + + 如果使用 npm 管理依赖,也可以执行: + + ```bash + npm install + ``` + +3. 打包 App + + ```bash + npm run buildAll + ``` + + 该脚本等价于: + + ```bash + npm run tauri build -b + ``` + +4. 查看产物 + + 打包完成后,安装包和可执行文件会输出到: + + ```text + src-tauri/target/release/bundle/ + ``` + + 当前配置的 `bundle.targets` 为 `all`,Tauri 会为当前操作系统生成可用的安装包格式。跨平台安装包通常需要在对应系统上分别打包。 ## 主要技术栈 @@ -51,4 +132,4 @@ WIP ## 开源协议 -本项目基于 [MIT协议](./LICENSE) 进行开源 \ No newline at end of file +本项目基于 [MIT协议](./LICENSE) 进行开源 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 @@