feat: 接入 DramaBox 并按语言地区切换清单
This commit is contained in:
+123
-32
@@ -7,7 +7,7 @@ import SettingsPanel from "./views/SettingsPanel.vue";
|
||||
import PlayerPage from "./views/PlayerPage.vue";
|
||||
|
||||
type Method = "guest" | "password" | "adb";
|
||||
type Platform = "rapt" | "huangdou";
|
||||
type Platform = "rapt" | "huangdou" | "dramabox";
|
||||
|
||||
interface Profile {
|
||||
nickname?: string;
|
||||
@@ -30,6 +30,10 @@ interface Profile {
|
||||
balance?: string | number;
|
||||
is_vip?: string | number;
|
||||
has_login?: string;
|
||||
country?: string;
|
||||
language?: string;
|
||||
native?: string;
|
||||
locale?: string;
|
||||
}
|
||||
|
||||
interface Device {
|
||||
@@ -75,6 +79,7 @@ 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 themeOverrides: GlobalThemeOverrides = {
|
||||
Form: {
|
||||
@@ -85,10 +90,22 @@ const themeOverrides: GlobalThemeOverrides = {
|
||||
const platforms: { key: Platform; label: string }[] = [
|
||||
{ key: "rapt", label: "RaptDrama" },
|
||||
{ key: "huangdou", label: "黄豆短剧" },
|
||||
{ key: "dramabox", label: "DramaBox" },
|
||||
];
|
||||
const platform = ref<Platform>(readPlatform());
|
||||
const apiBase = computed(() => (platform.value === "huangdou" ? "/api/huangdou" : "/api"));
|
||||
const platformLabel = computed(() => platforms.find((item) => item.key === platform.value)?.label || "RaptDrama");
|
||||
const isolated = computed(() => platform.value === "huangdou" || platform.value === "dramabox");
|
||||
const apiBase = computed(() => {
|
||||
if (platform.value === "huangdou") return "/api/huangdou";
|
||||
if (platform.value === "dramabox") return "/api/dramabox";
|
||||
return "/api";
|
||||
});
|
||||
const platformLabel = computed(() => {
|
||||
const name = platforms.find((item) => item.key === platform.value)?.label || "RaptDrama";
|
||||
if (platform.value === "dramabox" && profile.value?.nickname) return `${name} · ${profile.value.nickname}`;
|
||||
return name;
|
||||
});
|
||||
const dramaboxLang = ref("th");
|
||||
const dramaboxLangs = ref<{ label: string; value: string }[]>([]);
|
||||
const method = ref<Method>("guest");
|
||||
const email = ref("");
|
||||
const password = ref("");
|
||||
@@ -159,7 +176,7 @@ const menuValue = computed(() => {
|
||||
function readPlatform(): Platform {
|
||||
try {
|
||||
const value = localStorage.getItem(PLATFORM_KEY);
|
||||
if (value === "huangdou" || value === "rapt") return value;
|
||||
if (value === "huangdou" || value === "rapt" || value === "dramabox") return value;
|
||||
} catch {
|
||||
// 沿用默认平台
|
||||
}
|
||||
@@ -167,14 +184,43 @@ function readPlatform(): Platform {
|
||||
}
|
||||
|
||||
function selectPlatform(key: string) {
|
||||
if (key !== "rapt" && key !== "huangdou") return;
|
||||
if (key !== "rapt" && key !== "huangdou" && key !== "dramabox") return;
|
||||
platform.value = key;
|
||||
localStorage.setItem(PLATFORM_KEY, key);
|
||||
error.value = "";
|
||||
if (key === "dramabox") void loadDramaboxLanguages();
|
||||
}
|
||||
|
||||
function tokenKey() {
|
||||
return platform.value === "huangdou" ? "huangdou-token" : "rapt-token";
|
||||
if (platform.value === "huangdou") return "huangdou-token";
|
||||
if (platform.value === "dramabox") return "dramabox-token";
|
||||
return "rapt-token";
|
||||
}
|
||||
|
||||
async function loadDramaboxLanguages() {
|
||||
try {
|
||||
const response = await fetch("/api/dramabox/languages");
|
||||
const payload = await response.json();
|
||||
const items = Array.isArray(payload.items) ? payload.items : [];
|
||||
dramaboxLangs.value = items.map((item: { id: string; label: string }) => ({
|
||||
label: item.label,
|
||||
value: item.id,
|
||||
}));
|
||||
} catch {
|
||||
dramaboxLangs.value = [];
|
||||
}
|
||||
if (!dramaboxLangs.value.length) {
|
||||
dramaboxLangs.value = [
|
||||
{ label: "泰国 · 泰语", value: "th" },
|
||||
{ label: "美国 · 英语", value: "en" },
|
||||
];
|
||||
}
|
||||
try {
|
||||
const saved = localStorage.getItem(DRAMABOX_LANG_KEY);
|
||||
if (saved && dramaboxLangs.value.some((item) => item.value === saved)) dramaboxLang.value = saved;
|
||||
} catch {
|
||||
// 使用默认地区
|
||||
}
|
||||
}
|
||||
|
||||
function openPlay(drama: { id: string | number; title: string; image: string }) {
|
||||
@@ -225,20 +271,28 @@ const methods: { id: Method; label: string }[] = [
|
||||
{ id: "adb", label: "ADB" },
|
||||
];
|
||||
|
||||
const accountFields = computed(() =>
|
||||
platform.value === "huangdou"
|
||||
? [
|
||||
{ key: "username" as const, label: "账号" },
|
||||
{ key: "id" as const, label: "用户 ID" },
|
||||
{ key: "group_name" as const, label: "身份" },
|
||||
{ key: "email" as const, label: "邮箱" },
|
||||
{ key: "phone" as const, label: "手机" },
|
||||
]
|
||||
: [
|
||||
{ key: "email" as const, label: "邮箱" },
|
||||
{ key: "id" as const, label: "用户 ID" },
|
||||
],
|
||||
);
|
||||
const accountFields = computed(() => {
|
||||
if (platform.value === "huangdou") {
|
||||
return [
|
||||
{ key: "username" as const, label: "账号" },
|
||||
{ key: "id" as const, label: "用户 ID" },
|
||||
{ key: "group_name" as const, label: "身份" },
|
||||
{ key: "email" as const, label: "邮箱" },
|
||||
{ key: "phone" as const, label: "手机" },
|
||||
];
|
||||
}
|
||||
if (platform.value === "dramabox") {
|
||||
return [
|
||||
{ key: "country" as const, label: "国家" },
|
||||
{ key: "language" as const, label: "语言" },
|
||||
{ key: "id" as const, label: "代码" },
|
||||
];
|
||||
}
|
||||
return [
|
||||
{ key: "email" as const, label: "邮箱" },
|
||||
{ key: "id" as const, label: "用户 ID" },
|
||||
];
|
||||
});
|
||||
|
||||
const statFields = computed(() =>
|
||||
platform.value === "huangdou"
|
||||
@@ -247,6 +301,8 @@ const statFields = computed(() =>
|
||||
{ key: "score" as const, label: "余额" },
|
||||
{ key: "watched" as const, label: "观看" },
|
||||
]
|
||||
: platform.value === "dramabox"
|
||||
? []
|
||||
: [
|
||||
{ key: "vipday" as const, label: "VIP" },
|
||||
{ key: "score" as const, label: "积分" },
|
||||
@@ -310,13 +366,13 @@ async function loadDownloadSettings() {
|
||||
|
||||
async function enterSettings() {
|
||||
settingsError.value = "";
|
||||
if (platform.value === "huangdou" && settingsTab.value === "device") settingsTab.value = "download";
|
||||
if (isolated.value && settingsTab.value === "device") settingsTab.value = "download";
|
||||
await loadDownloadSettings();
|
||||
draft.value = copySettings(settings.value);
|
||||
}
|
||||
|
||||
async function openSettings() {
|
||||
settingsTab.value = platform.value === "huangdou" ? "download" : "device";
|
||||
settingsTab.value = isolated.value ? "download" : "device";
|
||||
await enterSettings();
|
||||
settingsOpen.value = true;
|
||||
}
|
||||
@@ -602,11 +658,41 @@ async function loginHuangdou() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loginDramabox() {
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
try {
|
||||
localStorage.setItem(DRAMABOX_LANG_KEY, dramaboxLang.value);
|
||||
const response = await fetch("/api/dramabox/login/device", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ language: dramaboxLang.value }),
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "进入失败");
|
||||
}
|
||||
token.value = payload.token;
|
||||
profile.value = payload.profile;
|
||||
sessionStorage.setItem(tokenKey(), payload.token);
|
||||
page.value = "download";
|
||||
startLive();
|
||||
} catch (exc) {
|
||||
error.value = exc instanceof Error ? exc.message : "进入失败";
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function login() {
|
||||
if (platform.value === "huangdou") {
|
||||
await loginHuangdou();
|
||||
return;
|
||||
}
|
||||
if (platform.value === "dramabox") {
|
||||
await loginDramabox();
|
||||
return;
|
||||
}
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
try {
|
||||
@@ -709,7 +795,7 @@ async function logout() {
|
||||
sessionStorage.removeItem(SESSION_DEVICE_KEY);
|
||||
if (!current) return;
|
||||
try {
|
||||
await fetch(platform.value === "huangdou" ? "/api/huangdou/logout" : "/api/logout", {
|
||||
await fetch(isolated.value ? `${apiBase.value}/logout` : "/api/logout", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: current }),
|
||||
@@ -739,11 +825,12 @@ async function watchClose() {
|
||||
|
||||
async function askClose(win: ReturnType<typeof getCurrentWindow>) {
|
||||
try {
|
||||
const [rapt, huangdou] = await Promise.all([
|
||||
const [rapt, huangdou, dramabox] = await Promise.all([
|
||||
fetch("/api/downloads").then((item) => item.json()).catch(() => ({})),
|
||||
fetch("/api/huangdou/downloads").then((item) => item.json()).catch(() => ({})),
|
||||
fetch("/api/dramabox/downloads").then((item) => item.json()).catch(() => ({})),
|
||||
]);
|
||||
const count = Number(rapt.active_count || 0) + Number(huangdou.active_count || 0);
|
||||
const count = Number(rapt.active_count || 0) + Number(huangdou.active_count || 0) + Number(dramabox.active_count || 0);
|
||||
if (count > 0) {
|
||||
closeCount.value = count;
|
||||
closeAsk.value = true;
|
||||
@@ -775,9 +862,10 @@ onMounted(async () => {
|
||||
}
|
||||
savedAccounts.value = readList<SavedAccount>(ACCOUNTS_KEY);
|
||||
if (savedAccounts.value[0]) applyAccount(savedAccounts.value[0].email);
|
||||
if (platform.value === "dramabox") await loadDramaboxLanguages();
|
||||
const saved = sessionStorage.getItem(tokenKey());
|
||||
if (!saved) return;
|
||||
const response = await fetch(platform.value === "huangdou" ? "/api/huangdou/me" : "/api/me", {
|
||||
const response = await fetch(isolated.value ? `${apiBase.value}/me` : "/api/me", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: saved, device: sessionDevice() }),
|
||||
@@ -862,7 +950,7 @@ onUnmounted(stopLive);
|
||||
:token="token"
|
||||
:device="sessionDevice()"
|
||||
:api-base="apiBase"
|
||||
:remote-search="platform === 'huangdou'"
|
||||
:remote-search="isolated"
|
||||
@started="page = 'progress'"
|
||||
@play="openPlay"
|
||||
/>
|
||||
@@ -876,7 +964,7 @@ onUnmounted(stopLive);
|
||||
<DownloadProgressPage v-show="page === 'progress'" :api-base="apiBase" :active="downloadState.active" :done="downloadState.done" />
|
||||
<div v-show="page === 'settings'" class="settings-page">
|
||||
<n-alert v-if="settingsError" class="hint" type="error" :show-icon="false">{{ settingsError }}</n-alert>
|
||||
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="platform === 'huangdou'" @choose="chooseDownloadDirectory" />
|
||||
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="isolated" @choose="chooseDownloadDirectory" />
|
||||
</div>
|
||||
<div v-show="page === 'profile'" class="profile-page">
|
||||
<div class="profile-sheet">
|
||||
@@ -887,7 +975,7 @@ onUnmounted(stopLive);
|
||||
<span class="profile-name">{{ profile.nickname || "未命名" }}</span>
|
||||
<n-tag v-if="profile.badge" size="small" :bordered="false" type="success">{{ profile.badge }}</n-tag>
|
||||
</div>
|
||||
<span class="profile-sub">{{ profile.email || "未绑定邮箱" }}</span>
|
||||
<span class="profile-sub">{{ profile.email || (platform === "dramabox" ? profile.native || "" : "未绑定邮箱") }}</span>
|
||||
</div>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
@@ -904,7 +992,7 @@ onUnmounted(stopLive);
|
||||
退出
|
||||
</n-tooltip>
|
||||
</div>
|
||||
<div class="profile-stats" :style="{ gridTemplateColumns: `repeat(${statFields.length}, minmax(0, 1fr))` }">
|
||||
<div v-if="statFields.length" class="profile-stats" :style="{ gridTemplateColumns: `repeat(${statFields.length}, minmax(0, 1fr))` }">
|
||||
<div v-for="item in statFields" :key="item.key" class="profile-stat">
|
||||
<span class="profile-stat-value">{{ profileNumber(item.key) }}</span>
|
||||
<span class="profile-stat-label">{{ item.label }}</span>
|
||||
@@ -945,6 +1033,9 @@ 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">
|
||||
<n-form-item v-if="platform === 'dramabox'" label="地区">
|
||||
<n-select v-model:value="dramaboxLang" filterable :options="dramaboxLangs" placeholder="选择国家 / 语言" />
|
||||
</n-form-item>
|
||||
<template v-if="platform === 'rapt' && method === 'password'">
|
||||
<n-form-item v-if="savedAccounts.length" label="已保存">
|
||||
<div class="device-line">
|
||||
@@ -984,7 +1075,7 @@ onUnmounted(stopLive);
|
||||
<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 type="primary" attr-type="submit" :loading="busy">{{ platform === "huangdou" ? "进入" : "登录" }}</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="busy">{{ isolated ? "进入" : "登录" }}</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
@@ -1009,7 +1100,7 @@ onUnmounted(stopLive);
|
||||
<n-modal v-model:show="settingsOpen" preset="card" title="设置" style="width: 640px">
|
||||
<div class="settings-modal-body">
|
||||
<n-alert v-if="settingsError" class="hint" type="error" :show-icon="false">{{ settingsError }}</n-alert>
|
||||
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="platform === 'huangdou'" @choose="chooseDownloadDirectory" />
|
||||
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="isolated" @choose="chooseDownloadDirectory" />
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
|
||||
Reference in New Issue
Block a user