feat: DramaBox 全量走 App 接口,清单可停止并避免卡死
分类按 App 翻页,精选走推荐接口。清单顶部显示进度,停止后不再拉新剧,已拿到的封面继续加载。列表只绘制可见卡片,避免大量剧目占满主线程。
This commit is contained in:
+184
-34
@@ -76,11 +76,23 @@ interface ProxySettings {
|
||||
function emptyProxy(): ProxySettings {
|
||||
return { mode: "off", scheme: "http", host: "", port: "", username: "", password: "" };
|
||||
}
|
||||
|
||||
function normalizeProxy(value: Partial<ProxySettings> | null | undefined): ProxySettings {
|
||||
const proxy = { ...emptyProxy(), ...(value || {}) };
|
||||
if (proxy.mode !== "off" && proxy.mode !== "system" && proxy.mode !== "custom") proxy.mode = "off";
|
||||
if (proxy.scheme !== "http" && proxy.scheme !== "socks5") proxy.scheme = "http";
|
||||
proxy.host = String(proxy.host || "");
|
||||
proxy.port = String(proxy.port || "");
|
||||
proxy.username = String(proxy.username || "");
|
||||
proxy.password = String(proxy.password || "");
|
||||
return proxy;
|
||||
}
|
||||
const DEVICE_KEY = "rapt-device-settings";
|
||||
const SESSION_DEVICE_KEY = "rapt-device";
|
||||
const ACCOUNTS_KEY = "rapt-accounts";
|
||||
const PLATFORM_KEY = "rapt-platform";
|
||||
const DRAMABOX_LANG_KEY = "dramabox-language";
|
||||
const DRAMABOX_DEVICE_KEY = "dramabox-device";
|
||||
|
||||
const themeOverrides: GlobalThemeOverrides = {
|
||||
Form: {
|
||||
@@ -108,6 +120,7 @@ const platformLabel = computed(() => {
|
||||
const dramaboxLang = ref("th");
|
||||
const dramaboxLangs = ref<{ label: string; value: string }[]>([]);
|
||||
const accountBusy = ref(false);
|
||||
const activeProxyUrl = ref("");
|
||||
const profileError = ref("");
|
||||
const method = ref<Method>("guest");
|
||||
const email = ref("");
|
||||
@@ -120,6 +133,7 @@ const error = ref("");
|
||||
const token = ref("");
|
||||
const profile = ref<Profile | null>(null);
|
||||
const dramaboxLoggedIn = computed(() => profile.value?.has_login === "1");
|
||||
const dramaboxDeviceReady = computed(() => devices.value.some((item) => item.state === "device"));
|
||||
const page = ref<"download" | "profile" | "progress" | "settings" | "play">("download");
|
||||
const playing = ref<{ id: string | number; title: string; image: string } | null>(null);
|
||||
const progressCount = ref(0);
|
||||
@@ -150,6 +164,8 @@ const downloadRef = ref<{
|
||||
loadDirectory: () => Promise<void>;
|
||||
} | null>(null);
|
||||
const catalogQuery = ref("");
|
||||
const catalogMaxPages = ref(300);
|
||||
let catalogPagesTimer: number | null = null;
|
||||
const mainMenu = computed(() => [
|
||||
{ label: "视频清单", key: "download" },
|
||||
{
|
||||
@@ -192,7 +208,10 @@ function selectPlatform(key: string) {
|
||||
platform.value = key;
|
||||
localStorage.setItem(PLATFORM_KEY, key);
|
||||
error.value = "";
|
||||
if (key === "dramabox") void loadDramaboxLanguages();
|
||||
if (key === "dramabox") {
|
||||
void loadDramaboxLanguages();
|
||||
void loadDevices();
|
||||
}
|
||||
}
|
||||
|
||||
function tokenKey() {
|
||||
@@ -362,10 +381,7 @@ function loadSettings() {
|
||||
settings.value.custom = { ...builtinDevice.value, ...data.custom };
|
||||
}
|
||||
if (data.proxy && typeof data.proxy === "object") {
|
||||
const proxy = { ...emptyProxy(), ...data.proxy };
|
||||
if (proxy.mode !== "off" && proxy.mode !== "system" && proxy.mode !== "custom") proxy.mode = "off";
|
||||
if (proxy.scheme !== "http" && proxy.scheme !== "socks5") proxy.scheme = "http";
|
||||
settings.value.proxy = proxy;
|
||||
settings.value.proxy = normalizeProxy(data.proxy);
|
||||
}
|
||||
} catch {
|
||||
settings.value.custom = { ...builtinDevice.value };
|
||||
@@ -384,6 +400,50 @@ function normalizeWorkers(value: unknown) {
|
||||
return count;
|
||||
}
|
||||
|
||||
function normalizeCatalogPages(value: unknown) {
|
||||
const count = Number(value);
|
||||
if (!Number.isInteger(count) || count < 1) return 300;
|
||||
return Math.min(count, 999);
|
||||
}
|
||||
|
||||
async function loadCatalogSettings() {
|
||||
if (platform.value !== "dramabox") return;
|
||||
try {
|
||||
const response = await fetch("/api/dramabox/catalog/settings");
|
||||
if (!response.ok) return;
|
||||
const payload = await response.json();
|
||||
catalogMaxPages.value = normalizeCatalogPages(payload.max_pages);
|
||||
} catch {
|
||||
catalogMaxPages.value = 300;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveCatalogMaxPages(value: number) {
|
||||
const pages = normalizeCatalogPages(value);
|
||||
catalogMaxPages.value = pages;
|
||||
try {
|
||||
const response = await fetch("/api/dramabox/catalog/settings", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ max_pages: pages }),
|
||||
});
|
||||
if (!response.ok) return;
|
||||
const payload = await response.json();
|
||||
catalogMaxPages.value = normalizeCatalogPages(payload.max_pages);
|
||||
} catch {
|
||||
// 下次刷新会重新读取
|
||||
}
|
||||
}
|
||||
|
||||
function onCatalogMaxPages(value: number | null) {
|
||||
if (value === null) return;
|
||||
catalogMaxPages.value = normalizeCatalogPages(value);
|
||||
if (catalogPagesTimer) window.clearTimeout(catalogPagesTimer);
|
||||
catalogPagesTimer = window.setTimeout(() => {
|
||||
void saveCatalogMaxPages(catalogMaxPages.value);
|
||||
}, 400);
|
||||
}
|
||||
|
||||
async function loadDownloadSettings() {
|
||||
const response = await fetch(`${apiBase.value}/downloads/settings`);
|
||||
if (!response.ok) return;
|
||||
@@ -408,9 +468,16 @@ async function openSettings() {
|
||||
|
||||
watch(page, (value) => {
|
||||
if (value === "settings") void enterSettings();
|
||||
if (value === "profile" && platform.value === "dramabox") void loadDevices();
|
||||
});
|
||||
watch(
|
||||
() => platform.value === "dramabox" && !!profile.value,
|
||||
(ready) => {
|
||||
if (ready) void loadCatalogSettings();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 打开页面时把本机保存的代理推给后端,避免进程重启后丢失。
|
||||
async function applyProxy(proxy: ProxySettings) {
|
||||
const response = await fetch("/api/proxy", {
|
||||
method: "POST",
|
||||
@@ -421,6 +488,22 @@ async function applyProxy(proxy: ProxySettings) {
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "代理设置失败");
|
||||
}
|
||||
activeProxyUrl.value = typeof payload.url === "string" ? payload.url : "";
|
||||
}
|
||||
|
||||
// 代理存在后台文件里。页面地址每次启动端口不同,不能只靠浏览器本地存储。
|
||||
async function loadProxySettings() {
|
||||
const response = await fetch("/api/proxy");
|
||||
if (response.ok) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
const server = normalizeProxy(payload);
|
||||
if (server.mode !== "off") {
|
||||
settings.value.proxy = server;
|
||||
activeProxyUrl.value = typeof payload.url === "string" ? payload.url : "";
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (settings.value.proxy.mode !== "off") await applyProxy(settings.value.proxy);
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
@@ -446,14 +529,20 @@ async function saveSettings() {
|
||||
return;
|
||||
}
|
||||
const directory = draft.value.directory.trim();
|
||||
if (!directory) {
|
||||
settingsTab.value = "download";
|
||||
settingsError.value = "请选择下载目录";
|
||||
return;
|
||||
}
|
||||
settingsBusy.value = true;
|
||||
try {
|
||||
await applyProxy(proxy);
|
||||
settings.value.proxy = copySettings(proxy);
|
||||
localStorage.setItem(DEVICE_KEY, JSON.stringify({
|
||||
adbMode: settings.value.adbMode,
|
||||
custom: settings.value.custom,
|
||||
proxy: settings.value.proxy,
|
||||
}));
|
||||
if (!directory) {
|
||||
settingsTab.value = "download";
|
||||
settingsError.value = "请选择下载目录";
|
||||
return;
|
||||
}
|
||||
const response = await fetch(`${apiBase.value}/downloads/settings`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@@ -595,6 +684,7 @@ function profileText(key: keyof Profile) {
|
||||
if (kind === "google") return "Google";
|
||||
if (kind === "facebook") return "Facebook";
|
||||
if (kind === "apple") return "Apple";
|
||||
if (kind === "app") return "设备";
|
||||
return kind ? String(profile.value?.loginType) : "—";
|
||||
}
|
||||
const value = profile.value?.[key];
|
||||
@@ -617,12 +707,21 @@ function deviceLabel(item: Device) {
|
||||
return `${item.model} · ${item.serial} · ${mark}`;
|
||||
}
|
||||
|
||||
function rememberedSerial() {
|
||||
try {
|
||||
return localStorage.getItem(DRAMABOX_DEVICE_KEY) || "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function applyDeviceList(list: Device[]) {
|
||||
devices.value = list;
|
||||
const stillThere = devices.value.some((item) => item.serial === serial.value && item.state === "device");
|
||||
if (!stillThere) {
|
||||
const ready = devices.value.filter((item) => item.state === "device");
|
||||
serial.value = ready.length === 1 ? ready[0].serial : null;
|
||||
const remembered = ready.find((item) => item.serial === rememberedSerial());
|
||||
serial.value = remembered?.serial || (ready.length === 1 ? ready[0].serial : null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,32 +793,35 @@ async function loginHuangdou() {
|
||||
}
|
||||
}
|
||||
|
||||
function errorText(exc: unknown, fallback: string) {
|
||||
if (typeof exc === "string" && exc.trim()) return exc;
|
||||
if (exc instanceof Error && exc.message) return exc.message;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function loginDramaboxAccount() {
|
||||
async function loginDramaboxAdb() {
|
||||
const inside = Boolean(token.value);
|
||||
error.value = "";
|
||||
profileError.value = "";
|
||||
if (inside) accountBusy.value = true;
|
||||
else busy.value = true;
|
||||
try {
|
||||
if (!inTauri()) throw new Error("请在桌面程序里登录");
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
const language = dramaboxLang.value || profile.value?.locale || "th";
|
||||
const user = await invoke<Record<string, unknown>>("dramabox_login", { language });
|
||||
localStorage.setItem(DRAMABOX_LANG_KEY, language);
|
||||
const response = await fetch("/api/dramabox/login/account", {
|
||||
if (!serial.value) await loadDevices();
|
||||
if (!serial.value && error.value) throw new Error(error.value);
|
||||
const ready = devices.value.filter((item) => item.state === "device");
|
||||
const picked = serial.value || "";
|
||||
if (!picked) {
|
||||
throw new Error(
|
||||
ready.length
|
||||
? "请选择设备"
|
||||
: "没有检测到已连接的设备。手机请打开 USB 调试;MuMu 请先点探测。",
|
||||
);
|
||||
}
|
||||
serial.value = picked;
|
||||
localStorage.setItem(DRAMABOX_DEVICE_KEY, picked);
|
||||
localStorage.setItem(DRAMABOX_LANG_KEY, dramaboxLang.value);
|
||||
const response = await fetch("/api/dramabox/login/adb", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ language, user }),
|
||||
body: JSON.stringify({ serial: picked, language: dramaboxLang.value }),
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "登录失败");
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "读取登录失败");
|
||||
}
|
||||
token.value = payload.token;
|
||||
profile.value = payload.profile;
|
||||
@@ -729,7 +831,7 @@ async function loginDramaboxAccount() {
|
||||
startLive();
|
||||
}
|
||||
} catch (exc) {
|
||||
const message = errorText(exc, "登录失败");
|
||||
const message = exc instanceof Error ? exc.message : "读取登录失败";
|
||||
if (inside) profileError.value = message;
|
||||
else error.value = message;
|
||||
} finally {
|
||||
@@ -946,13 +1048,16 @@ onMounted(async () => {
|
||||
await loadDeviceDefaults();
|
||||
loadSettings();
|
||||
try {
|
||||
await applyProxy(settings.value.proxy);
|
||||
await loadProxySettings();
|
||||
} catch {
|
||||
error.value = "代理还没有生效,请重新打开设置并保存";
|
||||
}
|
||||
savedAccounts.value = readList<SavedAccount>(ACCOUNTS_KEY);
|
||||
if (savedAccounts.value[0]) applyAccount(savedAccounts.value[0].email);
|
||||
if (platform.value === "dramabox") await loadDramaboxLanguages();
|
||||
if (platform.value === "dramabox") {
|
||||
await loadDramaboxLanguages();
|
||||
void loadDevices();
|
||||
}
|
||||
let saved = readSavedToken();
|
||||
if (!saved && isolated.value) {
|
||||
try {
|
||||
@@ -1001,6 +1106,27 @@ onUnmounted(stopLive);
|
||||
:options="mainMenu"
|
||||
@update:value="page = $event"
|
||||
/>
|
||||
<div v-if="platform === 'dramabox' && page === 'download'" class="catalog-limit">
|
||||
<div class="catalog-limit-label">
|
||||
最大页数
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<span class="help-dot" tabindex="0">?</span>
|
||||
</template>
|
||||
每个分类最多翻这么多页。精选这类推荐流可能一直有新内容,到上限就会停下。改完后点刷新生效。
|
||||
</n-tooltip>
|
||||
</div>
|
||||
<n-input-number
|
||||
:value="catalogMaxPages"
|
||||
class="catalog-limit-input"
|
||||
size="small"
|
||||
button-placement="both"
|
||||
:min="1"
|
||||
:max="999"
|
||||
:precision="0"
|
||||
@update:value="onCatalogMaxPages"
|
||||
/>
|
||||
</div>
|
||||
<div class="user-nav" :class="{ active: page === 'profile' }">
|
||||
<button type="button" class="user-nav-main" @click="page = 'profile'">
|
||||
<n-avatar round :size="28" :src="avatarSrc" />
|
||||
@@ -1107,8 +1233,8 @@ onUnmounted(stopLive);
|
||||
<div class="profile-block-title">
|
||||
<span>账号</span>
|
||||
<span v-if="platform === 'dramabox'" class="profile-title-actions">
|
||||
<n-tag size="small" :bordered="false" :type="dramaboxLoggedIn ? 'success' : 'default'">{{ dramaboxLoggedIn ? "已登录" : "未登录" }}</n-tag>
|
||||
<n-button v-if="!dramaboxLoggedIn" size="tiny" secondary :loading="accountBusy" @click="loginDramaboxAccount">登录</n-button>
|
||||
<n-tag size="small" :bordered="false" :type="dramaboxLoggedIn ? 'success' : 'default'">{{ dramaboxLoggedIn ? "已登录" : "访客" }}</n-tag>
|
||||
<n-button size="tiny" secondary :loading="accountBusy" :disabled="!dramaboxDeviceReady" @click="loginDramaboxAdb">从设备登录</n-button>
|
||||
</span>
|
||||
</div>
|
||||
<n-alert v-if="profileError" class="hint" type="error" :show-icon="false">{{ profileError }}</n-alert>
|
||||
@@ -1148,6 +1274,13 @@ onUnmounted(stopLive);
|
||||
<n-form-item v-if="platform === 'dramabox'" label="地区">
|
||||
<n-select v-model:value="dramaboxLang" filterable :options="dramaboxLangs" placeholder="选择国家 / 语言" />
|
||||
</n-form-item>
|
||||
<n-form-item v-if="platform === 'dramabox'" label="设备">
|
||||
<div class="device-line">
|
||||
<n-select v-model:value="serial" :options="deviceOptions" :loading="devicesBusy" placeholder="请选择设备" />
|
||||
<n-button :loading="devicesBusy" @click="loadDevices">刷新</n-button>
|
||||
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<template v-if="platform === 'rapt' && method === 'password'">
|
||||
<n-form-item v-if="savedAccounts.length" label="已保存">
|
||||
<div class="device-line">
|
||||
@@ -1182,13 +1315,15 @@ 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" :loading="busy" @click="loginDramaboxAccount">登录</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="busy">{{ isolated ? "进入" : "登录" }}</n-button>
|
||||
<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>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
@@ -1284,6 +1419,21 @@ html { color-scheme: dark; }
|
||||
font-size: 13px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.catalog-limit {
|
||||
flex: none;
|
||||
margin: 12px 4px 0;
|
||||
padding: 10px 8px 4px;
|
||||
}
|
||||
.catalog-limit-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 8px;
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-size: 13px;
|
||||
}
|
||||
.catalog-limit-input { width: 100%; }
|
||||
.catalog-limit-input .n-input__input-el { text-align: center; }
|
||||
.user-nav {
|
||||
margin-top: auto;
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user