feat: 接入黄豆短剧独立清单与下载
This commit is contained in:
+147
-41
@@ -7,6 +7,7 @@ import SettingsPanel from "./views/SettingsPanel.vue";
|
||||
import PlayerPage from "./views/PlayerPage.vue";
|
||||
|
||||
type Method = "guest" | "password" | "adb";
|
||||
type Platform = "rapt" | "huangdou";
|
||||
|
||||
interface Profile {
|
||||
nickname?: string;
|
||||
@@ -23,6 +24,12 @@ interface Profile {
|
||||
google_bind?: number;
|
||||
apple_bind?: number;
|
||||
avatarNumUrl?: string;
|
||||
username?: string;
|
||||
phone?: string;
|
||||
group_name?: string;
|
||||
balance?: string | number;
|
||||
is_vip?: string | number;
|
||||
has_login?: string;
|
||||
}
|
||||
|
||||
interface Device {
|
||||
@@ -67,6 +74,7 @@ function emptyProxy(): ProxySettings {
|
||||
const DEVICE_KEY = "rapt-device-settings";
|
||||
const SESSION_DEVICE_KEY = "rapt-device";
|
||||
const ACCOUNTS_KEY = "rapt-accounts";
|
||||
const PLATFORM_KEY = "rapt-platform";
|
||||
|
||||
const themeOverrides: GlobalThemeOverrides = {
|
||||
Form: {
|
||||
@@ -74,6 +82,13 @@ const themeOverrides: GlobalThemeOverrides = {
|
||||
},
|
||||
};
|
||||
|
||||
const platforms: { key: Platform; label: string }[] = [
|
||||
{ key: "rapt", label: "RaptDrama" },
|
||||
{ key: "huangdou", label: "黄豆短剧" },
|
||||
];
|
||||
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 method = ref<Method>("guest");
|
||||
const email = ref("");
|
||||
const password = ref("");
|
||||
@@ -85,7 +100,7 @@ const error = ref("");
|
||||
const token = ref("");
|
||||
const profile = ref<Profile | null>(null);
|
||||
const page = ref<"download" | "profile" | "progress" | "settings" | "play">("download");
|
||||
const playing = ref<{ id: number; title: string; image: string } | null>(null);
|
||||
const playing = ref<{ id: string | number; title: string; image: string } | null>(null);
|
||||
const progressCount = ref(0);
|
||||
interface LiveJob {
|
||||
id: string;
|
||||
@@ -141,7 +156,28 @@ const menuValue = computed(() => {
|
||||
return page.value;
|
||||
});
|
||||
|
||||
function openPlay(drama: { id: number; title: string; image: string }) {
|
||||
function readPlatform(): Platform {
|
||||
try {
|
||||
const value = localStorage.getItem(PLATFORM_KEY);
|
||||
if (value === "huangdou" || value === "rapt") return value;
|
||||
} catch {
|
||||
// 沿用默认平台
|
||||
}
|
||||
return "rapt";
|
||||
}
|
||||
|
||||
function selectPlatform(key: string) {
|
||||
if (key !== "rapt" && key !== "huangdou") return;
|
||||
platform.value = key;
|
||||
localStorage.setItem(PLATFORM_KEY, key);
|
||||
error.value = "";
|
||||
}
|
||||
|
||||
function tokenKey() {
|
||||
return platform.value === "huangdou" ? "huangdou-token" : "rapt-token";
|
||||
}
|
||||
|
||||
function openPlay(drama: { id: string | number; title: string; image: string }) {
|
||||
playing.value = drama;
|
||||
page.value = "play";
|
||||
}
|
||||
@@ -189,18 +225,36 @@ const methods: { id: Method; label: string }[] = [
|
||||
{ id: "adb", label: "ADB" },
|
||||
];
|
||||
|
||||
const accountFields: { key: keyof Profile; label: string }[] = [
|
||||
{ key: "email", label: "邮箱" },
|
||||
{ key: "id", label: "用户 ID" },
|
||||
];
|
||||
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 statFields: { key: keyof Profile; label: string }[] = [
|
||||
{ key: "vipday", label: "VIP" },
|
||||
{ key: "score", label: "积分" },
|
||||
{ key: "watched", label: "观看" },
|
||||
{ key: "rewards", label: "奖励" },
|
||||
{ key: "login_day", label: "登录" },
|
||||
];
|
||||
const statFields = computed(() =>
|
||||
platform.value === "huangdou"
|
||||
? [
|
||||
{ key: "vipday" as const, label: "VIP" },
|
||||
{ key: "score" as const, label: "余额" },
|
||||
{ key: "watched" as const, label: "观看" },
|
||||
]
|
||||
: [
|
||||
{ key: "vipday" as const, label: "VIP" },
|
||||
{ key: "score" as const, label: "积分" },
|
||||
{ key: "watched" as const, label: "观看" },
|
||||
{ key: "rewards" as const, label: "奖励" },
|
||||
{ key: "login_day" as const, label: "登录" },
|
||||
],
|
||||
);
|
||||
|
||||
const bindFields: { key: keyof Profile; label: string }[] = [
|
||||
{ key: "email_bind", label: "邮箱" },
|
||||
@@ -246,7 +300,7 @@ function normalizeWorkers(value: unknown) {
|
||||
}
|
||||
|
||||
async function loadDownloadSettings() {
|
||||
const response = await fetch("/api/downloads/settings");
|
||||
const response = await fetch(`${apiBase.value}/downloads/settings`);
|
||||
if (!response.ok) return;
|
||||
const payload = await response.json();
|
||||
settings.value.workers = normalizeWorkers(payload.workers);
|
||||
@@ -256,12 +310,13 @@ async function loadDownloadSettings() {
|
||||
|
||||
async function enterSettings() {
|
||||
settingsError.value = "";
|
||||
if (platform.value === "huangdou" && settingsTab.value === "device") settingsTab.value = "download";
|
||||
await loadDownloadSettings();
|
||||
draft.value = copySettings(settings.value);
|
||||
}
|
||||
|
||||
async function openSettings() {
|
||||
settingsTab.value = "device";
|
||||
settingsTab.value = platform.value === "huangdou" ? "download" : "device";
|
||||
await enterSettings();
|
||||
settingsOpen.value = true;
|
||||
}
|
||||
@@ -314,7 +369,7 @@ async function saveSettings() {
|
||||
settingsBusy.value = true;
|
||||
try {
|
||||
await applyProxy(proxy);
|
||||
const response = await fetch("/api/downloads/settings", {
|
||||
const response = await fetch(`${apiBase.value}/downloads/settings`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ directory, workers }),
|
||||
@@ -345,7 +400,7 @@ async function saveSettings() {
|
||||
|
||||
async function chooseDownloadDirectory() {
|
||||
settingsError.value = "";
|
||||
const response = await fetch("/api/downloads/choose", { method: "POST" });
|
||||
const response = await fetch(`${apiBase.value}/downloads/choose`, { method: "POST" });
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
settingsError.value = typeof payload.detail === "string" ? payload.detail : "目录选择失败";
|
||||
@@ -526,7 +581,32 @@ watch(method, (value) => {
|
||||
if (value === "adb") loadDevices();
|
||||
});
|
||||
|
||||
async function loginHuangdou() {
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/huangdou/login/device", { method: "POST" });
|
||||
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;
|
||||
}
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
try {
|
||||
@@ -561,7 +641,7 @@ async function login() {
|
||||
}
|
||||
token.value = payload.token;
|
||||
profile.value = payload.profile;
|
||||
sessionStorage.setItem("rapt-token", payload.token);
|
||||
sessionStorage.setItem(tokenKey(), payload.token);
|
||||
rememberSessionDevice(payload.device);
|
||||
page.value = "download";
|
||||
startLive();
|
||||
@@ -576,7 +656,7 @@ async function login() {
|
||||
const avatarSrc = computed(() => {
|
||||
const image = profile.value?.avatarNumUrl || "";
|
||||
if (!image) return undefined;
|
||||
if (image.startsWith("http://") || image.startsWith("https://")) return image;
|
||||
if (image.startsWith("http://") || image.startsWith("https://") || image.startsWith("/api/")) return image;
|
||||
return `https://apis.raptdrama.com${image.startsWith("/") ? image : `/${image}`}`;
|
||||
});
|
||||
|
||||
@@ -597,7 +677,7 @@ function applyLive(payload: { downloads?: { active: LiveJob[]; done: LiveJob[];
|
||||
function startLive() {
|
||||
stopLive();
|
||||
const protocol = location.protocol === "https:" ? "wss" : "ws";
|
||||
const socket = new WebSocket(`${protocol}://${location.host}/api/live`);
|
||||
const socket = new WebSocket(`${protocol}://${location.host}/api/live?platform=${platform.value}`);
|
||||
liveSocket = socket;
|
||||
socket.onmessage = (event) => {
|
||||
applyLive(JSON.parse(event.data));
|
||||
@@ -625,11 +705,11 @@ async function logout() {
|
||||
token.value = "";
|
||||
profile.value = null;
|
||||
page.value = "download";
|
||||
sessionStorage.removeItem("rapt-token");
|
||||
sessionStorage.removeItem(tokenKey());
|
||||
sessionStorage.removeItem(SESSION_DEVICE_KEY);
|
||||
if (!current) return;
|
||||
try {
|
||||
await fetch("/api/logout", {
|
||||
await fetch(platform.value === "huangdou" ? "/api/huangdou/logout" : "/api/logout", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: current }),
|
||||
@@ -659,9 +739,11 @@ async function watchClose() {
|
||||
|
||||
async function askClose(win: ReturnType<typeof getCurrentWindow>) {
|
||||
try {
|
||||
const response = await fetch("/api/downloads");
|
||||
const payload = await response.json();
|
||||
const count = Number(payload.active_count || 0);
|
||||
const [rapt, huangdou] = await Promise.all([
|
||||
fetch("/api/downloads").then((item) => item.json()).catch(() => ({})),
|
||||
fetch("/api/huangdou/downloads").then((item) => item.json()).catch(() => ({})),
|
||||
]);
|
||||
const count = Number(rapt.active_count || 0) + Number(huangdou.active_count || 0);
|
||||
if (count > 0) {
|
||||
closeCount.value = count;
|
||||
closeAsk.value = true;
|
||||
@@ -693,15 +775,15 @@ onMounted(async () => {
|
||||
}
|
||||
savedAccounts.value = readList<SavedAccount>(ACCOUNTS_KEY);
|
||||
if (savedAccounts.value[0]) applyAccount(savedAccounts.value[0].email);
|
||||
const saved = sessionStorage.getItem("rapt-token");
|
||||
const saved = sessionStorage.getItem(tokenKey());
|
||||
if (!saved) return;
|
||||
const response = await fetch("/api/me", {
|
||||
const response = await fetch(platform.value === "huangdou" ? "/api/huangdou/me" : "/api/me", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: saved, device: sessionDevice() }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
sessionStorage.removeItem("rapt-token");
|
||||
sessionStorage.removeItem(tokenKey());
|
||||
return;
|
||||
}
|
||||
const payload = await response.json();
|
||||
@@ -720,6 +802,7 @@ onUnmounted(stopLive);
|
||||
<n-layout v-if="profile" class="shell" has-sider position="absolute">
|
||||
<n-layout-sider bordered :width="208" content-style="height: 100%; padding: 0">
|
||||
<div class="sider">
|
||||
<div class="platform-mark">{{ platformLabel }}</div>
|
||||
<n-menu
|
||||
:value="menuValue"
|
||||
:options="mainMenu"
|
||||
@@ -778,6 +861,8 @@ onUnmounted(stopLive);
|
||||
ref="downloadRef"
|
||||
:token="token"
|
||||
:device="sessionDevice()"
|
||||
:api-base="apiBase"
|
||||
:remote-search="platform === 'huangdou'"
|
||||
@started="page = 'progress'"
|
||||
@play="openPlay"
|
||||
/>
|
||||
@@ -786,11 +871,12 @@ onUnmounted(stopLive);
|
||||
:token="token"
|
||||
:device="sessionDevice()"
|
||||
:drama-id="playing.id"
|
||||
:api-base="apiBase"
|
||||
/>
|
||||
<DownloadProgressPage v-show="page === 'progress'" :active="downloadState.active" :done="downloadState.done" />
|
||||
<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" @choose="chooseDownloadDirectory" />
|
||||
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="platform === 'huangdou'" @choose="chooseDownloadDirectory" />
|
||||
</div>
|
||||
<div v-show="page === 'profile'" class="profile-page">
|
||||
<div class="profile-sheet">
|
||||
@@ -818,7 +904,7 @@ onUnmounted(stopLive);
|
||||
退出
|
||||
</n-tooltip>
|
||||
</div>
|
||||
<div class="profile-stats">
|
||||
<div 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>
|
||||
@@ -831,7 +917,7 @@ onUnmounted(stopLive);
|
||||
<span class="profile-row-value">{{ profileText(item.key) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="profile-block">
|
||||
<div v-if="platform === 'rapt'" class="profile-block">
|
||||
<div class="profile-block-title">绑定</div>
|
||||
<div class="profile-binds">
|
||||
<span v-for="item in bindFields" :key="item.key" class="profile-bind" :class="{ on: profileBound(item.key) }">{{ item.label }}</span>
|
||||
@@ -842,15 +928,27 @@ onUnmounted(stopLive);
|
||||
</n-layout-content>
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
<n-layout v-else class="shell login-shell" position="absolute">
|
||||
<n-layout v-else class="shell login-shell" has-sider position="absolute">
|
||||
<n-layout-sider bordered :width="208" content-style="height: 100%; padding: 0">
|
||||
<div class="sider">
|
||||
<n-menu
|
||||
:value="platform"
|
||||
:options="platforms.map((item) => ({ label: item.label, key: item.key }))"
|
||||
@update:value="selectPlatform"
|
||||
/>
|
||||
</div>
|
||||
</n-layout-sider>
|
||||
<n-layout-content>
|
||||
<div class="login-center">
|
||||
<div class="card">
|
||||
<n-tabs v-model:value="method" type="segment" size="small">
|
||||
<n-tabs v-if="platform === 'rapt'" v-model:value="method" type="segment" size="small">
|
||||
<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="method === 'password'">
|
||||
<template v-if="platform === 'huangdou'">
|
||||
<n-text class="hint" depth="3">打开后会自动分配一个设备账号,无需观看广告。账号密码登录以后再做。</n-text>
|
||||
</template>
|
||||
<template v-else-if="method === 'password'">
|
||||
<n-form-item v-if="savedAccounts.length" label="已保存">
|
||||
<div class="device-line">
|
||||
<n-select
|
||||
@@ -872,7 +970,7 @@ onUnmounted(stopLive);
|
||||
<n-checkbox v-model:checked="rememberPassword">记住账号密码</n-checkbox>
|
||||
</n-form-item>
|
||||
</template>
|
||||
<n-form-item v-else-if="method === 'adb'" label="设备">
|
||||
<n-form-item v-else-if="platform === 'rapt' && method === 'adb'" label="设备">
|
||||
<div class="device-line">
|
||||
<n-select
|
||||
v-model:value="serial"
|
||||
@@ -884,12 +982,12 @@ onUnmounted(stopLive);
|
||||
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-text v-if="method === 'guest'" class="hint" depth="3">将注册一个新的游客账号,并读取它的个人信息。</n-text>
|
||||
<n-text v-if="method === 'adb' && !devicesBusy && devices.length === 0" class="hint" depth="3">没有检测到已连接的设备。</n-text>
|
||||
<n-text v-if="method === 'adb'" class="hint" depth="3">从已 root 的设备读取当前登录账号。未 root 的设备无法获取登录信息。默认同时读取这台设备的品牌、型号和系统版本,可在右下角设置里修改。</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 type="primary" attr-type="submit" :loading="busy">登录</n-button>
|
||||
<n-button type="primary" attr-type="submit" :loading="busy">{{ platform === "huangdou" ? "进入" : "登录" }}</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
@@ -914,7 +1012,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" @choose="chooseDownloadDirectory" />
|
||||
<SettingsPanel v-model:tab="settingsTab" :draft="draft" :hide-device="platform === 'huangdou'" @choose="chooseDownloadDirectory" />
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
@@ -979,6 +1077,12 @@ html { color-scheme: dark; }
|
||||
min-height: 0;
|
||||
}
|
||||
.sider { height: 100%; min-height: 100%; display: flex; flex-direction: column; box-sizing: border-box; padding: 12px 8px; }
|
||||
.platform-mark {
|
||||
padding: 2px 12px 10px;
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
font-size: 13px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.user-nav {
|
||||
margin-top: auto;
|
||||
display: flex;
|
||||
@@ -1142,6 +1246,8 @@ html { color-scheme: dark; }
|
||||
.login-shell > .n-layout-scroll-container,
|
||||
.login-shell .n-layout-content,
|
||||
.login-shell .n-layout-content > .n-layout-scroll-container { height: 100%; }
|
||||
.login-shell .n-layout-sider,
|
||||
.login-shell .n-layout-sider > .n-layout-sider-scroll-container { height: 100%; }
|
||||
.login-center {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user