feat: 将工具更名为 VideosDownTools,并完善黄豆登录与清单
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>RaptDrama Download Tools</title>
|
||||
<title>VideosDownTools</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
Generated
+2
-2
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "raptdrama-ui",
|
||||
"name": "videosdowntools-ui",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "raptdrama-ui",
|
||||
"name": "videosdowntools-ui",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2",
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "raptdrama-ui",
|
||||
"name": "videosdowntools-ui",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
|
||||
+297
-12
@@ -30,6 +30,7 @@ interface Profile {
|
||||
balance?: string | number;
|
||||
is_vip?: string | number;
|
||||
has_login?: string;
|
||||
host?: string;
|
||||
country?: string;
|
||||
language?: string;
|
||||
native?: string;
|
||||
@@ -51,6 +52,12 @@ interface SavedAccount {
|
||||
uid: string;
|
||||
}
|
||||
|
||||
interface HuangdouAccount {
|
||||
username: string;
|
||||
password: string;
|
||||
nickname: string;
|
||||
}
|
||||
|
||||
interface DeviceProfile {
|
||||
brand: string;
|
||||
model: string;
|
||||
@@ -92,6 +99,9 @@ const SESSION_DEVICE_KEY = "rapt-device";
|
||||
const ACCOUNTS_KEY = "rapt-accounts";
|
||||
const PLATFORM_KEY = "rapt-platform";
|
||||
const DRAMABOX_LANG_KEY = "dramabox-language";
|
||||
const HUANGDOU_HOST_KEY = "huangdou-host";
|
||||
const HUANGDOU_ACCOUNTS_KEY = "huangdou-accounts";
|
||||
const HUANGDOU_REMEMBER_KEY = "huangdou-remember";
|
||||
const DRAMABOX_DEVICE_KEY = "dramabox-device";
|
||||
|
||||
const themeOverrides: GlobalThemeOverrides = {
|
||||
@@ -113,11 +123,19 @@ const apiBase = computed(() => {
|
||||
return "/api";
|
||||
});
|
||||
const platformLabel = computed(() => {
|
||||
const name = platforms.find((item) => item.key === platform.value)?.label || "RaptDrama";
|
||||
const name = platforms.find((item) => item.key === platform.value)?.label || "VideosDownTools";
|
||||
if (platform.value === "dramabox" && profile.value?.nickname) return `${name} · ${profile.value.nickname}`;
|
||||
return name;
|
||||
});
|
||||
const dramaboxLang = ref("th");
|
||||
const huangdouHost = ref(readHuangdouHost());
|
||||
const huangdouUser = ref("");
|
||||
const huangdouPassword = ref("");
|
||||
const huangdouRemember = ref(readHuangdouRemember());
|
||||
const huangdouAccounts = ref<HuangdouAccount[]>([]);
|
||||
const huangdouSelected = ref<string | null>(null);
|
||||
const huangdouFingerprintBusy = ref(false);
|
||||
const huangdouFingerprintNote = ref("");
|
||||
const dramaboxLangs = ref<{ label: string; value: string }[]>([]);
|
||||
const accountBusy = ref(false);
|
||||
const activeProxyUrl = ref("");
|
||||
@@ -193,6 +211,68 @@ const menuValue = computed(() => {
|
||||
return page.value;
|
||||
});
|
||||
|
||||
function currentBrowserFingerprint() {
|
||||
const ua = navigator.userAgent || "";
|
||||
let browserName = "Chrome";
|
||||
if (ua.includes("Edg/")) browserName = "Edge";
|
||||
else if (ua.includes("Firefox/")) browserName = "Firefox";
|
||||
else if (ua.includes("Safari/") && !ua.includes("Chrome/")) browserName = "Safari";
|
||||
return {
|
||||
browserName,
|
||||
language: navigator.language || "zh-CN",
|
||||
userAgent: ua,
|
||||
platform: navigator.platform || "Win32",
|
||||
};
|
||||
}
|
||||
|
||||
async function sendHuangdouFingerprint() {
|
||||
try {
|
||||
await fetch("/api/huangdou/fingerprint", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(currentBrowserFingerprint()),
|
||||
});
|
||||
} catch {
|
||||
// 首次指纹沿用代码里的默认值
|
||||
}
|
||||
}
|
||||
|
||||
async function rollHuangdouFingerprint() {
|
||||
huangdouFingerprintNote.value = "";
|
||||
error.value = "";
|
||||
huangdouFingerprintBusy.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/huangdou/fingerprint/roll", { method: "POST" });
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "更换失败");
|
||||
}
|
||||
huangdouFingerprintNote.value = "已更换设备指纹";
|
||||
} catch (exc) {
|
||||
error.value = exc instanceof Error ? exc.message : "更换失败";
|
||||
} finally {
|
||||
huangdouFingerprintBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function readHuangdouRemember() {
|
||||
try {
|
||||
return localStorage.getItem(HUANGDOU_REMEMBER_KEY) !== "0";
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function readHuangdouHost() {
|
||||
try {
|
||||
const value = localStorage.getItem(HUANGDOU_HOST_KEY) || "";
|
||||
if (value.trim()) return value.trim();
|
||||
} catch {
|
||||
// 沿用默认域名
|
||||
}
|
||||
return "https://pmihlvee.cc";
|
||||
}
|
||||
|
||||
function readPlatform(): Platform {
|
||||
try {
|
||||
const value = localStorage.getItem(PLATFORM_KEY);
|
||||
@@ -212,6 +292,7 @@ function selectPlatform(key: string) {
|
||||
void loadDramaboxLanguages();
|
||||
void loadDevices();
|
||||
}
|
||||
if (key === "huangdou") void sendHuangdouFingerprint();
|
||||
}
|
||||
|
||||
function tokenKey() {
|
||||
@@ -310,6 +391,18 @@ const methods: { id: Method; label: string }[] = [
|
||||
{ id: "adb", label: "ADB" },
|
||||
];
|
||||
|
||||
const profileSub = computed(() => {
|
||||
if (!profile.value) return "";
|
||||
if (platform.value === "huangdou") {
|
||||
if (profile.value.has_login === "1") {
|
||||
return profile.value.username || profile.value.phone || profile.value.email || "";
|
||||
}
|
||||
return "访客";
|
||||
}
|
||||
if (platform.value === "dramabox") return profile.value.native || profile.value.email || "";
|
||||
return profile.value.email || "未绑定邮箱";
|
||||
});
|
||||
|
||||
const accountFields = computed(() => {
|
||||
if (platform.value === "huangdou") {
|
||||
return [
|
||||
@@ -631,6 +724,13 @@ const accountOptions = computed(() =>
|
||||
})),
|
||||
);
|
||||
|
||||
const huangdouAccountOptions = computed(() =>
|
||||
huangdouAccounts.value.map((item) => ({
|
||||
label: item.nickname ? `${item.nickname} · ${item.username}` : item.username,
|
||||
value: item.username,
|
||||
})),
|
||||
);
|
||||
|
||||
function readList<T>(key: string): T[] {
|
||||
try {
|
||||
const data = JSON.parse(localStorage.getItem(key) || "[]");
|
||||
@@ -678,6 +778,91 @@ function saveAccount(info: Profile) {
|
||||
selectedAccount.value = next.email;
|
||||
}
|
||||
|
||||
let huangdouAccountsReady = false;
|
||||
let huangdouAccountTimer = 0;
|
||||
|
||||
function writeHuangdouAccounts() {
|
||||
window.clearTimeout(huangdouAccountTimer);
|
||||
huangdouAccountTimer = window.setTimeout(() => {
|
||||
const accounts = huangdouAccounts.value.map((item) => ({
|
||||
username: item.username,
|
||||
password: item.password,
|
||||
nickname: item.nickname || "",
|
||||
}));
|
||||
void fetch("/api/huangdou/accounts", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ accounts }),
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function usableHuangdouAccounts(rows: HuangdouAccount[]) {
|
||||
return rows.filter((item) => Boolean(item?.username) && typeof item.password === "string" && item.password);
|
||||
}
|
||||
|
||||
async function loadHuangdouAccounts() {
|
||||
const local = usableHuangdouAccounts(readList<HuangdouAccount>(HUANGDOU_ACCOUNTS_KEY));
|
||||
let remote: HuangdouAccount[] = [];
|
||||
try {
|
||||
const response = await fetch("/api/huangdou/accounts");
|
||||
if (response.ok) {
|
||||
const payload = await response.json();
|
||||
remote = usableHuangdouAccounts(Array.isArray(payload.accounts) ? payload.accounts : []);
|
||||
}
|
||||
} catch {
|
||||
remote = [];
|
||||
}
|
||||
huangdouAccounts.value = remote.length ? remote : local;
|
||||
if (!remote.length && local.length) writeHuangdouAccounts();
|
||||
if (huangdouAccounts.value[0]) applyHuangdouAccount(huangdouAccounts.value[0].username);
|
||||
}
|
||||
|
||||
function applyHuangdouAccount(username: string) {
|
||||
const found = huangdouAccounts.value.find((item) => item.username === username);
|
||||
if (!found) return;
|
||||
huangdouSelected.value = found.username;
|
||||
huangdouUser.value = found.username;
|
||||
huangdouPassword.value = found.password;
|
||||
huangdouRemember.value = true;
|
||||
}
|
||||
|
||||
function removeHuangdouAccount() {
|
||||
if (!huangdouSelected.value) return;
|
||||
const removing = huangdouSelected.value;
|
||||
huangdouAccounts.value = huangdouAccounts.value.filter((item) => item.username !== removing);
|
||||
writeHuangdouAccounts();
|
||||
if (huangdouUser.value === removing) {
|
||||
huangdouUser.value = "";
|
||||
huangdouPassword.value = "";
|
||||
}
|
||||
huangdouSelected.value = huangdouAccounts.value[0]?.username ?? null;
|
||||
if (huangdouSelected.value) applyHuangdouAccount(huangdouSelected.value);
|
||||
}
|
||||
|
||||
function saveHuangdouAccount(info: Profile) {
|
||||
const username = huangdouUser.value.trim();
|
||||
if (!username || !huangdouPassword.value) return;
|
||||
const next: HuangdouAccount = {
|
||||
username,
|
||||
password: huangdouPassword.value,
|
||||
nickname: info.nickname || info.username || "",
|
||||
};
|
||||
huangdouAccounts.value = [next, ...huangdouAccounts.value.filter((item) => item.username !== username)];
|
||||
writeHuangdouAccounts();
|
||||
huangdouSelected.value = username;
|
||||
}
|
||||
|
||||
function forgetHuangdouAccount(username: string) {
|
||||
const name = username.trim();
|
||||
if (!name) return;
|
||||
const next = huangdouAccounts.value.filter((item) => item.username !== name);
|
||||
if (next.length === huangdouAccounts.value.length) return;
|
||||
huangdouAccounts.value = next;
|
||||
writeHuangdouAccounts();
|
||||
if (huangdouSelected.value === name) huangdouSelected.value = next[0]?.username ?? null;
|
||||
}
|
||||
|
||||
function profileText(key: keyof Profile) {
|
||||
if (key === "loginType") {
|
||||
const kind = String(profile.value?.loginType || "").trim().toLowerCase();
|
||||
@@ -772,15 +957,82 @@ watch(method, (value) => {
|
||||
if (value === "adb") loadDevices();
|
||||
});
|
||||
|
||||
async function loginHuangdou() {
|
||||
watch(huangdouRemember, (value) => {
|
||||
try {
|
||||
localStorage.setItem(HUANGDOU_REMEMBER_KEY, value ? "1" : "0");
|
||||
} catch {
|
||||
// 勾选状态只影响本机
|
||||
}
|
||||
});
|
||||
|
||||
watch(huangdouUser, (value) => {
|
||||
const found = huangdouAccounts.value.find((item) => item.username === value.trim());
|
||||
huangdouSelected.value = found ? found.username : null;
|
||||
});
|
||||
|
||||
watch([huangdouRemember, huangdouUser, huangdouPassword], () => {
|
||||
if (!huangdouAccountsReady) return;
|
||||
const username = huangdouUser.value.trim();
|
||||
if (!username) return;
|
||||
if (huangdouRemember.value && huangdouPassword.value) {
|
||||
const existing = huangdouAccounts.value.find((item) => item.username === username);
|
||||
if (
|
||||
existing &&
|
||||
existing.password === huangdouPassword.value &&
|
||||
huangdouAccounts.value[0]?.username === username
|
||||
) {
|
||||
huangdouSelected.value = username;
|
||||
return;
|
||||
}
|
||||
huangdouAccounts.value = [
|
||||
{
|
||||
username,
|
||||
password: huangdouPassword.value,
|
||||
nickname: existing?.nickname || "",
|
||||
},
|
||||
...huangdouAccounts.value.filter((item) => item.username !== username),
|
||||
];
|
||||
huangdouSelected.value = username;
|
||||
writeHuangdouAccounts();
|
||||
return;
|
||||
}
|
||||
if (!huangdouRemember.value) {
|
||||
const next = huangdouAccounts.value.filter((item) => item.username !== username);
|
||||
if (next.length === huangdouAccounts.value.length) return;
|
||||
huangdouAccounts.value = next;
|
||||
if (huangdouSelected.value === username) huangdouSelected.value = next[0]?.username ?? null;
|
||||
writeHuangdouAccounts();
|
||||
}
|
||||
});
|
||||
|
||||
async function loginHuangdou(asGuest = false) {
|
||||
error.value = "";
|
||||
if (!asGuest && (!huangdouUser.value.trim() || !huangdouPassword.value)) {
|
||||
error.value = "请填写账号和密码";
|
||||
return;
|
||||
}
|
||||
busy.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/huangdou/login/device", { method: "POST" });
|
||||
const host = huangdouHost.value.trim() || "https://pmihlvee.cc";
|
||||
huangdouHost.value = host;
|
||||
localStorage.setItem(HUANGDOU_HOST_KEY, host);
|
||||
const response = await fetch("/api/huangdou/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
host,
|
||||
username: asGuest ? "" : huangdouUser.value.trim(),
|
||||
password: asGuest ? "" : huangdouPassword.value,
|
||||
}),
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "登录失败");
|
||||
}
|
||||
if (!asGuest) {
|
||||
if (huangdouRemember.value) saveHuangdouAccount(payload.profile || {});
|
||||
else forgetHuangdouAccount(huangdouUser.value);
|
||||
}
|
||||
token.value = payload.token;
|
||||
profile.value = payload.profile;
|
||||
writeSavedToken(payload.token);
|
||||
@@ -868,7 +1120,7 @@ async function loginDramabox() {
|
||||
|
||||
async function login() {
|
||||
if (platform.value === "huangdou") {
|
||||
await loginHuangdou();
|
||||
await loginHuangdou(false);
|
||||
return;
|
||||
}
|
||||
if (platform.value === "dramabox") {
|
||||
@@ -974,6 +1226,9 @@ async function logout() {
|
||||
token.value = "";
|
||||
profile.value = null;
|
||||
page.value = "download";
|
||||
if (platform.value === "huangdou" && huangdouAccounts.value.length) {
|
||||
applyHuangdouAccount(huangdouSelected.value || huangdouAccounts.value[0].username);
|
||||
}
|
||||
forgetSavedToken();
|
||||
sessionStorage.removeItem(SESSION_DEVICE_KEY);
|
||||
try {
|
||||
@@ -1043,7 +1298,7 @@ async function confirmQuit() {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
document.title = "RaptDrama Download Tools";
|
||||
document.title = "VideosDownTools";
|
||||
void watchClose();
|
||||
await loadDeviceDefaults();
|
||||
loadSettings();
|
||||
@@ -1054,10 +1309,13 @@ onMounted(async () => {
|
||||
}
|
||||
savedAccounts.value = readList<SavedAccount>(ACCOUNTS_KEY);
|
||||
if (savedAccounts.value[0]) applyAccount(savedAccounts.value[0].email);
|
||||
await loadHuangdouAccounts();
|
||||
huangdouAccountsReady = true;
|
||||
if (platform.value === "dramabox") {
|
||||
await loadDramaboxLanguages();
|
||||
void loadDevices();
|
||||
}
|
||||
if (platform.value === "huangdou") void sendHuangdouFingerprint();
|
||||
let saved = readSavedToken();
|
||||
if (!saved && isolated.value) {
|
||||
try {
|
||||
@@ -1182,6 +1440,7 @@ onUnmounted(stopLive);
|
||||
:device="sessionDevice()"
|
||||
:api-base="apiBase"
|
||||
:remote-search="isolated"
|
||||
:show-point-download="platform === 'huangdou'"
|
||||
@started="page = 'progress'"
|
||||
@play="openPlay"
|
||||
/>
|
||||
@@ -1205,8 +1464,9 @@ onUnmounted(stopLive);
|
||||
<div class="profile-name-row">
|
||||
<span class="profile-name">{{ profile.nickname || "未命名" }}</span>
|
||||
<n-tag v-if="profile.badge" size="small" :bordered="false" type="success">{{ profile.badge }}</n-tag>
|
||||
<n-tag v-if="platform === 'huangdou'" size="small" :bordered="false" :type="profile.has_login === '1' ? 'success' : 'default'">{{ profile.has_login === "1" ? "已登录" : "访客" }}</n-tag>
|
||||
</div>
|
||||
<span class="profile-sub">{{ profile.email || (platform === "dramabox" ? profile.native || "" : "未绑定邮箱") }}</span>
|
||||
<span class="profile-sub">{{ profileSub }}</span>
|
||||
</div>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
@@ -1271,6 +1531,35 @@ onUnmounted(stopLive);
|
||||
<n-tab v-for="item in methods" :key="item.id" :name="item.id">{{ item.label }}</n-tab>
|
||||
</n-tabs>
|
||||
<n-form label-placement="left" label-width="96" size="small" :show-feedback="false" @submit.prevent="login">
|
||||
<template v-if="platform === 'huangdou'">
|
||||
<n-form-item label="域名">
|
||||
<n-input v-model:value="huangdouHost" placeholder="https://pmihlvee.cc" />
|
||||
</n-form-item>
|
||||
<n-form-item v-if="huangdouAccounts.length" label="已保存">
|
||||
<div class="device-line">
|
||||
<n-select
|
||||
:value="huangdouSelected"
|
||||
:options="huangdouAccountOptions"
|
||||
placeholder="选择已保存的账号"
|
||||
@update:value="applyHuangdouAccount"
|
||||
/>
|
||||
<n-button attr-type="button" :disabled="!huangdouSelected" @click="removeHuangdouAccount">删除</n-button>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="账号">
|
||||
<n-input v-model:value="huangdouUser" placeholder="手机号或邮箱" autocomplete="username" />
|
||||
</n-form-item>
|
||||
<n-form-item label="密码">
|
||||
<n-input v-model:value="huangdouPassword" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" />
|
||||
</n-form-item>
|
||||
<n-form-item label="记住">
|
||||
<n-checkbox v-model:checked="huangdouRemember">记住账号密码</n-checkbox>
|
||||
</n-form-item>
|
||||
<n-form-item label="指纹">
|
||||
<n-button attr-type="button" secondary :loading="huangdouFingerprintBusy" @click="rollHuangdouFingerprint">更换新设备指纹</n-button>
|
||||
</n-form-item>
|
||||
<n-text v-if="huangdouFingerprintNote" class="hint" depth="3">{{ huangdouFingerprintNote }}</n-text>
|
||||
</template>
|
||||
<n-form-item v-if="platform === 'dramabox'" label="地区">
|
||||
<n-select v-model:value="dramaboxLang" filterable :options="dramaboxLangs" placeholder="选择国家 / 语言" />
|
||||
</n-form-item>
|
||||
@@ -1315,15 +1604,11 @@ onUnmounted(stopLive);
|
||||
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-text v-if="platform === 'dramabox' && !devicesBusy && devices.length === 0" class="hint" depth="3">当前没有可用设备,可先访客进入。</n-text>
|
||||
<n-text v-if="platform === 'dramabox'" class="hint" depth="3">选好地区后点访客进入即可浏览。解锁内容和下载请先从设备登录。</n-text>
|
||||
<n-text v-if="platform === 'rapt' && method === 'guest'" class="hint" depth="3">将注册一个新的游客账号,并读取它的个人信息。</n-text>
|
||||
<n-text v-if="platform === 'rapt' && method === 'adb' && !devicesBusy && devices.length === 0" class="hint" depth="3">没有检测到已连接的设备。</n-text>
|
||||
<n-text v-if="platform === 'rapt' && method === 'adb'" class="hint" depth="3">从已 root 的设备读取当前登录账号。未 root 的设备无法获取登录信息。默认同时读取这台设备的品牌、型号和系统版本,可在右下角设置里修改。</n-text>
|
||||
<n-alert v-if="error" class="hint" type="error" :show-icon="false">{{ error }}</n-alert>
|
||||
<div class="login-actions">
|
||||
<n-button v-if="platform === 'dramabox'" attr-type="button" secondary :loading="busy" :disabled="!dramaboxDeviceReady" @click="loginDramaboxAdb">从设备登录</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="busy">{{ platform === "dramabox" ? "访客进入" : isolated ? "进入" : "登录" }}</n-button>
|
||||
<n-button v-if="platform === 'huangdou'" attr-type="button" secondary :loading="busy" @click="loginHuangdou(true)">访客进入</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="busy">{{ platform === "dramabox" ? "访客进入" : platform === "huangdou" ? "登录" : isolated ? "进入" : "登录" }}</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ interface Episode {
|
||||
idx: number;
|
||||
title: string;
|
||||
playable: boolean;
|
||||
points?: number;
|
||||
media?: string;
|
||||
locked_reason?: string;
|
||||
is_preview?: boolean;
|
||||
@@ -56,6 +57,13 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
function episodeNote(episode: Episode): string {
|
||||
if (episode.points) return `${episode.points} 积分`;
|
||||
const text = episode.locked_reason || "";
|
||||
if (text.includes("不含") || text.includes("权益") || text.includes("解锁")) return "需要积分";
|
||||
return text || "无地址";
|
||||
}
|
||||
|
||||
function select(episode: Episode) {
|
||||
if (!episode.playable || episode.cid === current.value) return;
|
||||
current.value = episode.cid;
|
||||
@@ -126,7 +134,7 @@ onUnmounted(stop);
|
||||
@click="select(episode)"
|
||||
>
|
||||
<span class="play-episode-title">{{ episode.title }}</span>
|
||||
<span v-if="!episode.playable" class="play-episode-lock">{{ episode.locked_reason || "无地址" }}</span>
|
||||
<span v-if="!episode.playable" class="play-episode-lock">{{ episodeNote(episode) }}</span>
|
||||
<span v-else-if="episode.is_preview" class="play-episode-lock">试看</span>
|
||||
</button>
|
||||
<div v-if="!loading && episodes.length === 0" class="play-empty">没有分集</div>
|
||||
|
||||
@@ -99,8 +99,6 @@ function setDraftField(key: keyof DeviceProfile, value: string | boolean) {
|
||||
<n-radio value="settings">使用上面的设置</n-radio>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<n-text class="hint" depth="3">保存后下次登录生效。当前这次登录已经绑定的设备信息不会中途更换。</n-text>
|
||||
<n-text class="hint" depth="3">从设备读取时会带上品牌、型号、系统版本、设备 ID 和已安装的 App 版本。指纹和语言仍用当前设置里的值。</n-text>
|
||||
</n-form>
|
||||
</n-tab-pane>
|
||||
<n-tab-pane name="proxy" tab="代理" display-directive="if">
|
||||
|
||||
@@ -40,6 +40,7 @@ const props = defineProps<{
|
||||
device: object | null;
|
||||
apiBase?: string;
|
||||
remoteSearch?: boolean;
|
||||
showPointDownload?: boolean;
|
||||
}>();
|
||||
const apiBase = computed(() => props.apiBase || "/api");
|
||||
|
||||
@@ -63,13 +64,12 @@ const directory = ref("");
|
||||
const starting = ref(false);
|
||||
const footError = ref("");
|
||||
const coverStatus = reactive<Record<string, "ready" | "failed">>({});
|
||||
const coverDone = ref(0);
|
||||
const coverTotal = ref(0);
|
||||
const scrollTop = ref(0);
|
||||
const viewHeight = ref(800);
|
||||
const gridWidth = ref(720);
|
||||
const gridTops = ref<Record<string, number>>({});
|
||||
const emit = defineEmits<{ started: []; play: [Drama] }>();
|
||||
const downloadPoints = ref(false);
|
||||
const scrollEl = ref<HTMLElement | null>(null);
|
||||
const grids = new Map<string, HTMLElement>();
|
||||
const gridBinders = new Map<string, (el: unknown) => void>();
|
||||
@@ -79,6 +79,8 @@ let flushFrame = 0;
|
||||
let pendingPages: PageEvent[] = [];
|
||||
let coverQueue: string[] = [];
|
||||
const coverQueued = new Set<string>();
|
||||
const coverOwners = new Map<string, Set<string>>();
|
||||
const coverAbort = new Map<string, AbortController>();
|
||||
let coverRunning = 0;
|
||||
let coverToken = 0;
|
||||
const COVER_CONCURRENCY = 2;
|
||||
@@ -116,60 +118,110 @@ function resetCovers() {
|
||||
coverToken += 1;
|
||||
coverQueue = [];
|
||||
coverQueued.clear();
|
||||
coverOwners.clear();
|
||||
for (const controller of coverAbort.values()) controller.abort();
|
||||
coverAbort.clear();
|
||||
coverRunning = 0;
|
||||
coverDone.value = 0;
|
||||
coverTotal.value = 0;
|
||||
for (const key of Object.keys(coverStatus)) delete coverStatus[key];
|
||||
}
|
||||
|
||||
function enqueueCovers(items: Drama[]) {
|
||||
const token = coverToken;
|
||||
let added = 0;
|
||||
for (const item of items) {
|
||||
function enqueueSectionCovers(sectionKey: string) {
|
||||
if (!isExpanded(sectionKey)) return;
|
||||
const section = sections.value.find((item) => item.key === sectionKey);
|
||||
if (!section) return;
|
||||
let added = false;
|
||||
for (const item of section.items) {
|
||||
const src = coverOf(item.image);
|
||||
if (!src || coverStatus[src] || coverQueued.has(src)) continue;
|
||||
if (!src || coverStatus[src]) continue;
|
||||
let owners = coverOwners.get(src);
|
||||
if (!owners) {
|
||||
owners = new Set();
|
||||
coverOwners.set(src, owners);
|
||||
}
|
||||
owners.add(sectionKey);
|
||||
if (coverQueued.has(src) || coverAbort.has(src)) continue;
|
||||
coverQueued.add(src);
|
||||
coverQueue.push(src);
|
||||
added += 1;
|
||||
added = true;
|
||||
}
|
||||
if (added) pumpCovers(coverToken);
|
||||
}
|
||||
|
||||
function stopSectionCovers(sectionKey: string) {
|
||||
for (const [src, owners] of [...coverOwners]) {
|
||||
if (!owners.delete(sectionKey)) continue;
|
||||
if (owners.size) continue;
|
||||
coverOwners.delete(src);
|
||||
coverQueue = coverQueue.filter((item) => item !== src);
|
||||
coverQueued.delete(src);
|
||||
const controller = coverAbort.get(src);
|
||||
if (controller) controller.abort();
|
||||
}
|
||||
if (!added) return;
|
||||
coverTotal.value += added;
|
||||
pumpCovers(token);
|
||||
}
|
||||
|
||||
function pumpCovers(token: number) {
|
||||
while (coverRunning < COVER_CONCURRENCY && coverQueue.length) {
|
||||
const src = coverQueue.shift();
|
||||
if (!src) break;
|
||||
if (!coverOwners.get(src)?.size) {
|
||||
coverQueued.delete(src);
|
||||
continue;
|
||||
}
|
||||
const controller = new AbortController();
|
||||
coverAbort.set(src, controller);
|
||||
coverRunning += 1;
|
||||
void prefetchCover(src).then(
|
||||
(ok) => settleCover(token, src, ok),
|
||||
() => settleCover(token, src, false),
|
||||
void prefetchCover(src, controller.signal).then(
|
||||
(ok) => settleCover(token, src, ok, false),
|
||||
(exc: unknown) => settleCover(token, src, false, exc instanceof DOMException && exc.name === "AbortError"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function prefetchCover(src: string) {
|
||||
async function prefetchCover(src: string, signal: AbortSignal) {
|
||||
if (src.startsWith("/api/")) {
|
||||
const response = await fetch(src);
|
||||
const response = await fetch(src, { signal });
|
||||
if (!response.ok) return false;
|
||||
await response.arrayBuffer();
|
||||
return true;
|
||||
}
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.onload = () => resolve();
|
||||
image.onerror = () => reject(new Error("cover"));
|
||||
const done = () => {
|
||||
signal.removeEventListener("abort", abort);
|
||||
resolve();
|
||||
};
|
||||
const abort = () => {
|
||||
image.onload = null;
|
||||
image.onerror = null;
|
||||
image.src = "";
|
||||
reject(new DOMException("aborted", "AbortError"));
|
||||
};
|
||||
if (signal.aborted) {
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
signal.addEventListener("abort", abort, { once: true });
|
||||
image.onload = done;
|
||||
image.onerror = () => {
|
||||
signal.removeEventListener("abort", abort);
|
||||
reject(new Error("cover"));
|
||||
};
|
||||
image.src = src;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
function settleCover(token: number, src: string, ok: boolean) {
|
||||
function settleCover(token: number, src: string, ok: boolean, aborted: boolean) {
|
||||
if (token !== coverToken) return;
|
||||
coverRunning = Math.max(0, coverRunning - 1);
|
||||
markCover(src, ok);
|
||||
coverDone.value += 1;
|
||||
coverAbort.delete(src);
|
||||
if (aborted || !coverOwners.get(src)?.size) {
|
||||
coverQueued.delete(src);
|
||||
} else {
|
||||
markCover(src, ok);
|
||||
coverOwners.delete(src);
|
||||
coverQueued.delete(src);
|
||||
}
|
||||
pumpCovers(token);
|
||||
}
|
||||
|
||||
@@ -178,9 +230,10 @@ function isExpanded(key: string) {
|
||||
}
|
||||
|
||||
function toggleExpanded(key: string) {
|
||||
expanded.value = isExpanded(key)
|
||||
? expanded.value.filter((item) => item !== key)
|
||||
: [...expanded.value, key];
|
||||
const open = isExpanded(key);
|
||||
expanded.value = open ? expanded.value.filter((item) => item !== key) : [...expanded.value, key];
|
||||
if (open) stopSectionCovers(key);
|
||||
else enqueueSectionCovers(key);
|
||||
void nextTick(() => measure());
|
||||
}
|
||||
|
||||
@@ -279,7 +332,7 @@ function applyPage(event: PageEvent) {
|
||||
if (event.pages) section.pages = event.pages;
|
||||
if (event.items?.length) {
|
||||
section.items.push(...event.items);
|
||||
enqueueCovers(event.items);
|
||||
enqueueSectionCovers(section.key);
|
||||
}
|
||||
if (event.done) section.loading = false;
|
||||
}
|
||||
@@ -571,6 +624,7 @@ async function find(keyword = query.value) {
|
||||
flashKey.value = "";
|
||||
if (!isExpanded(hit.sectionKey)) {
|
||||
expanded.value = [...expanded.value, hit.sectionKey];
|
||||
enqueueSectionCovers(hit.sectionKey);
|
||||
}
|
||||
await nextTick();
|
||||
if (generation !== revealGeneration) return;
|
||||
@@ -589,12 +643,8 @@ async function find(keyword = query.value) {
|
||||
const loadedCount = computed(() =>
|
||||
sections.value.reduce((sum, section) => sum + (section.key === "search" ? 0 : section.items.length), 0),
|
||||
);
|
||||
const coverPending = computed(() => coverTotal.value > 0 && coverDone.value < coverTotal.value);
|
||||
const showProgress = computed(() => busy.value || stopped.value || coverPending.value);
|
||||
const showProgress = computed(() => busy.value || stopped.value);
|
||||
const progress = computed(() => {
|
||||
if (!busy.value && coverPending.value && coverTotal.value) {
|
||||
return Math.min(100, Math.round((coverDone.value / coverTotal.value) * 100));
|
||||
}
|
||||
let got = 0;
|
||||
let total = 0;
|
||||
for (const section of sections.value) {
|
||||
@@ -608,11 +658,7 @@ const progress = computed(() => {
|
||||
const progressText = computed(() => {
|
||||
const count = loadedCount.value;
|
||||
if (busy.value) return `已加载 ${count} 部`;
|
||||
if (stopped.value && coverPending.value) {
|
||||
return `已停止,共 ${count} 部,封面 ${coverDone.value}/${coverTotal.value}`;
|
||||
}
|
||||
if (stopped.value) return `已停止,共 ${count} 部`;
|
||||
if (coverPending.value) return `封面 ${coverDone.value}/${coverTotal.value}`;
|
||||
return "";
|
||||
});
|
||||
|
||||
@@ -666,10 +712,10 @@ async function searchRemote(keyword: string, generation: number) {
|
||||
pages: 0,
|
||||
});
|
||||
}
|
||||
enqueueCovers(items);
|
||||
publishSections();
|
||||
syncSelectedCounts();
|
||||
if (!isExpanded(key)) expanded.value = [...expanded.value, key];
|
||||
enqueueSectionCovers(key);
|
||||
void nextTick(() => measure());
|
||||
} catch {
|
||||
if (generation === revealGeneration) searchHint.value = "搜索失败";
|
||||
@@ -714,7 +760,12 @@ async function startDownload() {
|
||||
const response = await fetch(`${apiBase.value}/downloads`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: props.token, device: props.device, items }),
|
||||
body: JSON.stringify({
|
||||
token: props.token,
|
||||
device: props.device,
|
||||
items,
|
||||
download_points: props.showPointDownload ? downloadPoints.value : false,
|
||||
}),
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) {
|
||||
@@ -738,7 +789,7 @@ async function startDownload() {
|
||||
type="line"
|
||||
:percentage="progress"
|
||||
:show-indicator="false"
|
||||
:processing="busy || coverPending"
|
||||
:processing="busy"
|
||||
:height="8"
|
||||
/>
|
||||
</div>
|
||||
@@ -746,7 +797,7 @@ async function startDownload() {
|
||||
<template #trigger>
|
||||
<n-button size="small" secondary @click="stopLoad">停止</n-button>
|
||||
</template>
|
||||
停止后不再获取新剧目,已拿到的封面会继续加载
|
||||
停止后不再获取新剧目
|
||||
</n-tooltip>
|
||||
</div>
|
||||
<div class="download-body">
|
||||
@@ -845,6 +896,7 @@ async function startDownload() {
|
||||
<div class="foot-selected">
|
||||
<n-text>已选 {{ selected.size }} 部</n-text>
|
||||
<n-button secondary size="small" :disabled="selected.size === 0" @click="clearSelection">取消选择</n-button>
|
||||
<n-checkbox v-if="showPointDownload" v-model:checked="downloadPoints">下载积分视频</n-checkbox>
|
||||
</div>
|
||||
<div class="foot-actions">
|
||||
<n-text class="foot-dir" depth="3" :title="directory">{{ directory || "未设置下载目录" }}</n-text>
|
||||
@@ -890,7 +942,9 @@ async function startDownload() {
|
||||
padding: 12px 20px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.12);
|
||||
background: #18181c;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.foot-selected { flex-wrap: wrap; }
|
||||
.foot-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
||||
.foot-selected { display: flex; align-items: center; gap: 8px; flex: none; }
|
||||
.foot-dir { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
Reference in New Issue
Block a user