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;
|
||||
|
||||
@@ -16,7 +16,9 @@ interface Job {
|
||||
const props = defineProps<{
|
||||
active: Job[];
|
||||
done: Job[];
|
||||
apiBase?: string;
|
||||
}>();
|
||||
const apiBase = computed(() => props.apiBase || "/api");
|
||||
|
||||
const tab = ref<"active" | "done">("active");
|
||||
const holding = ref(false);
|
||||
@@ -38,14 +40,14 @@ async function holdAll() {
|
||||
if (!props.active.length || holding.value) return;
|
||||
holding.value = true;
|
||||
try {
|
||||
await fetch(resumeAll.value ? "/api/downloads/resume-all" : "/api/downloads/pause-all", { method: "POST" });
|
||||
await fetch(resumeAll.value ? `${apiBase.value}/downloads/resume-all` : `${apiBase.value}/downloads/pause-all`, { method: "POST" });
|
||||
} finally {
|
||||
holding.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function act(id: string, action: string) {
|
||||
await fetch(`/api/downloads/${id}/${action}`, { method: "POST" });
|
||||
await fetch(`${apiBase.value}/downloads/${id}/${action}`, { method: "POST" });
|
||||
}
|
||||
|
||||
async function remuxSaved() {
|
||||
@@ -53,7 +55,7 @@ async function remuxSaved() {
|
||||
remuxing.value = true;
|
||||
remuxNote.value = "";
|
||||
try {
|
||||
const response = await fetch("/api/downloads/remux", { method: "POST" });
|
||||
const response = await fetch(`${apiBase.value}/downloads/remux`, { method: "POST" });
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
remuxNote.value = data.detail || "重新合成失败";
|
||||
@@ -73,7 +75,7 @@ async function remuxOne(id: string) {
|
||||
remuxingId.value = id;
|
||||
remuxNote.value = "";
|
||||
try {
|
||||
const response = await fetch(`/api/downloads/${id}/remux`, { method: "POST" });
|
||||
const response = await fetch(`${apiBase.value}/downloads/${id}/remux`, { method: "POST" });
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
remuxNote.value = data.detail || "重新合成失败";
|
||||
@@ -92,7 +94,7 @@ async function redownload(id: string) {
|
||||
if (remuxing.value || remuxingId.value) return;
|
||||
remuxNote.value = "";
|
||||
try {
|
||||
const response = await fetch(`/api/downloads/${id}/redownload`, { method: "POST" });
|
||||
const response = await fetch(`${apiBase.value}/downloads/${id}/redownload`, { method: "POST" });
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
remuxNote.value = data.detail || "重新下载失败";
|
||||
@@ -105,7 +107,7 @@ async function redownload(id: string) {
|
||||
}
|
||||
|
||||
async function remove(id: string) {
|
||||
await fetch(`/api/downloads/${id}`, { method: "DELETE" });
|
||||
await fetch(`${apiBase.value}/downloads/${id}`, { method: "DELETE" });
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -6,13 +6,18 @@ interface Episode {
|
||||
idx: number;
|
||||
title: string;
|
||||
playable: boolean;
|
||||
media?: string;
|
||||
locked_reason?: string;
|
||||
is_preview?: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
token: string;
|
||||
device: object | null;
|
||||
dramaId: number;
|
||||
dramaId: string | number;
|
||||
apiBase?: string;
|
||||
}>();
|
||||
const apiBase = computed(() => props.apiBase || "/api");
|
||||
|
||||
const episodes = ref<Episode[]>([]);
|
||||
const current = ref<number | null>(null);
|
||||
@@ -27,7 +32,7 @@ async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const response = await fetch("/api/play/episodes", {
|
||||
const response = await fetch(`${apiBase.value}/play/episodes`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: props.token, device: props.device, vid: props.dramaId }),
|
||||
@@ -62,7 +67,13 @@ function attach(cid: number) {
|
||||
const video = videoRef.value;
|
||||
if (!video) return;
|
||||
stop();
|
||||
const url = `/api/play/${props.dramaId}/${cid}/index.m3u8`;
|
||||
const episode = episodes.value.find((item) => item.cid === cid);
|
||||
if (episode?.media === "file") {
|
||||
video.src = `${apiBase.value}/play/${props.dramaId}/${cid}/file`;
|
||||
video.play().catch(() => undefined);
|
||||
return;
|
||||
}
|
||||
const url = `${apiBase.value}/play/${props.dramaId}/${cid}/index.m3u8`;
|
||||
if (Hls.isSupported()) {
|
||||
const player = new Hls();
|
||||
hls = player;
|
||||
@@ -115,7 +126,8 @@ onUnmounted(stop);
|
||||
@click="select(episode)"
|
||||
>
|
||||
<span class="play-episode-title">{{ episode.title }}</span>
|
||||
<span v-if="!episode.playable" class="play-episode-lock">无地址</span>
|
||||
<span v-if="!episode.playable" class="play-episode-lock">{{ episode.locked_reason || "无地址" }}</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>
|
||||
</div>
|
||||
@@ -157,8 +169,9 @@ onUnmounted(stop);
|
||||
.play-episode {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
gap: 4px 8px;
|
||||
min-height: 36px;
|
||||
margin: 0 0 4px;
|
||||
padding: 6px 10px;
|
||||
@@ -173,6 +186,6 @@ onUnmounted(stop);
|
||||
.play-episode.current { background: rgba(99, 226, 183, 0.16); }
|
||||
.play-episode:disabled { color: rgba(255, 255, 255, 0.35); cursor: default; }
|
||||
.play-episode-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.play-episode-lock { flex: none; font-size: 12px; }
|
||||
.play-episode-lock { flex: 1 1 100%; font-size: 12px; line-height: 1.3; white-space: normal; }
|
||||
.play-empty { padding: 8px 10px; color: rgba(255, 255, 255, 0.45); }
|
||||
</style>
|
||||
|
||||
@@ -30,7 +30,7 @@ interface SettingsDraft {
|
||||
}
|
||||
|
||||
const tab = defineModel<"device" | "proxy" | "download">("tab", { required: true });
|
||||
const props = defineProps<{ draft: SettingsDraft }>();
|
||||
const props = defineProps<{ draft: SettingsDraft; hideDevice?: boolean }>();
|
||||
const emit = defineEmits<{ choose: [] }>();
|
||||
|
||||
const deviceFields: { key: keyof DeviceProfile; label: string; kind?: "select" | "switch" | "language" }[] = [
|
||||
@@ -64,7 +64,7 @@ function setDraftField(key: keyof DeviceProfile, value: string | boolean) {
|
||||
|
||||
<template>
|
||||
<n-tabs v-model:value="tab" type="line" size="small">
|
||||
<n-tab-pane name="device" tab="设备信息" display-directive="if">
|
||||
<n-tab-pane v-if="!hideDevice" name="device" tab="设备信息" display-directive="if">
|
||||
<n-form class="settings-form" label-placement="left" label-width="96" size="small" :show-feedback="false">
|
||||
<n-form-item v-for="field in deviceFields" :key="field.key" :label="field.label">
|
||||
<n-switch
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
interface Drama {
|
||||
id: number;
|
||||
id: string | number;
|
||||
title: string;
|
||||
image: string;
|
||||
payType?: string;
|
||||
corner?: string;
|
||||
locked?: boolean;
|
||||
limitedFree?: boolean;
|
||||
}
|
||||
|
||||
interface Section {
|
||||
@@ -16,11 +20,14 @@ interface Section {
|
||||
const props = defineProps<{
|
||||
token: string;
|
||||
device: object | null;
|
||||
apiBase?: string;
|
||||
remoteSearch?: boolean;
|
||||
}>();
|
||||
const apiBase = computed(() => props.apiBase || "/api");
|
||||
|
||||
const sections = ref<Section[]>([]);
|
||||
const expanded = ref<string[]>([]);
|
||||
const selected = ref<Set<number>>(new Set());
|
||||
const selected = ref<Set<string>>(new Set());
|
||||
const busy = ref(false);
|
||||
const error = ref("");
|
||||
const query = ref("");
|
||||
@@ -40,7 +47,7 @@ const scrollEl = ref<HTMLElement | null>(null);
|
||||
|
||||
function coverOf(image: string) {
|
||||
if (!image) return "";
|
||||
if (image.startsWith("/api/covers/")) return image;
|
||||
if (image.startsWith("/api/")) return image;
|
||||
if (image.startsWith("http")) return image;
|
||||
return `https://apis.raptdrama.com${image.startsWith("/") ? image : `/${image}`}`;
|
||||
}
|
||||
@@ -56,7 +63,7 @@ function toggleExpanded(key: string) {
|
||||
}
|
||||
|
||||
function selectedCount(section: Section) {
|
||||
return section.items.filter((item) => selected.value.has(item.id)).length;
|
||||
return section.items.filter((item) => selected.value.has(dramaKey(item.id))).length;
|
||||
}
|
||||
|
||||
function allChecked(section: Section) {
|
||||
@@ -68,18 +75,24 @@ function someChecked(section: Section) {
|
||||
return count > 0 && count < section.items.length;
|
||||
}
|
||||
|
||||
function toggleDrama(id: number, checked: boolean) {
|
||||
function dramaKey(id: string | number) {
|
||||
return String(id);
|
||||
}
|
||||
|
||||
function toggleDrama(id: string | number, checked: boolean) {
|
||||
const next = new Set(selected.value);
|
||||
if (checked) next.add(id);
|
||||
else next.delete(id);
|
||||
const key = dramaKey(id);
|
||||
if (checked) next.add(key);
|
||||
else next.delete(key);
|
||||
selected.value = next;
|
||||
}
|
||||
|
||||
function toggleSection(section: Section, checked: boolean) {
|
||||
const next = new Set(selected.value);
|
||||
for (const item of section.items) {
|
||||
if (checked) next.add(item.id);
|
||||
else next.delete(item.id);
|
||||
const key = dramaKey(item.id);
|
||||
if (checked) next.add(key);
|
||||
else next.delete(key);
|
||||
}
|
||||
selected.value = next;
|
||||
}
|
||||
@@ -89,7 +102,7 @@ function clearSelection() {
|
||||
}
|
||||
|
||||
function pruneSelection() {
|
||||
const ids = new Set(sections.value.flatMap((section) => section.items.map((item) => item.id)));
|
||||
const ids = new Set(sections.value.flatMap((section) => section.items.map((item) => dramaKey(item.id))));
|
||||
selected.value = new Set([...selected.value].filter((id) => ids.has(id)));
|
||||
}
|
||||
|
||||
@@ -122,7 +135,7 @@ async function reload(refresh = false) {
|
||||
error.value = "";
|
||||
busy.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/catalog", {
|
||||
const response = await fetch(`${apiBase.value}/catalog`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: props.token, device: props.device, refresh }),
|
||||
@@ -173,13 +186,13 @@ async function reload(refresh = false) {
|
||||
}
|
||||
}
|
||||
|
||||
function cardKey(sectionKey: string, id: number) {
|
||||
return `${sectionKey}-${id}`;
|
||||
function cardKey(sectionKey: string, id: string | number) {
|
||||
return `${sectionKey}-${dramaKey(id)}`;
|
||||
}
|
||||
|
||||
function matches() {
|
||||
const keyword = query.value.trim().toLowerCase();
|
||||
const found: { sectionKey: string; id: number }[] = [];
|
||||
const found: { sectionKey: string; id: string | number }[] = [];
|
||||
if (!keyword) return found;
|
||||
for (const section of sections.value) {
|
||||
for (const item of section.items) {
|
||||
@@ -250,7 +263,12 @@ async function find(keyword = query.value) {
|
||||
searchHint.value = "请输入名称";
|
||||
return;
|
||||
}
|
||||
const found = matches();
|
||||
let found = matches();
|
||||
if (!found.length && props.remoteSearch) {
|
||||
await searchRemote(text, generation);
|
||||
if (generation !== revealGeneration) return;
|
||||
found = matches();
|
||||
}
|
||||
if (!found.length) {
|
||||
searchHint.value = "没有找到";
|
||||
flashKey.value = "";
|
||||
@@ -289,8 +307,44 @@ onMounted(() => {
|
||||
});
|
||||
defineExpose({ reload, busy, find, searchHint, clearSearch, loadDirectory });
|
||||
|
||||
async function searchRemote(keyword: string, generation: number) {
|
||||
searchHint.value = "正在搜索";
|
||||
try {
|
||||
const response = await fetch(`${apiBase.value}/search`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: props.token, device: props.device, keyword }),
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (generation !== revealGeneration) return;
|
||||
if (!response.ok) {
|
||||
searchHint.value = typeof payload.detail === "string" ? payload.detail : "搜索失败";
|
||||
return;
|
||||
}
|
||||
const items = Array.isArray(payload.items) ? payload.items : [];
|
||||
const key = "search";
|
||||
const existing = sections.value.find((section) => section.key === key);
|
||||
if (existing) {
|
||||
existing.items = items;
|
||||
existing.loading = false;
|
||||
existing.note = items.length ? "" : "没有搜索结果";
|
||||
} else {
|
||||
sections.value.unshift({
|
||||
key,
|
||||
name: "搜索结果",
|
||||
note: items.length ? "" : "没有搜索结果",
|
||||
items,
|
||||
loading: false,
|
||||
});
|
||||
}
|
||||
if (!isExpanded(key)) expanded.value = [...expanded.value, key];
|
||||
} catch {
|
||||
if (generation === revealGeneration) searchHint.value = "搜索失败";
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDirectory() {
|
||||
const response = await fetch("/api/downloads");
|
||||
const response = await fetch(`${apiBase.value}/downloads`);
|
||||
if (!response.ok) return;
|
||||
const payload = await response.json();
|
||||
directory.value = payload.directory || "";
|
||||
@@ -298,7 +352,7 @@ async function loadDirectory() {
|
||||
|
||||
async function chooseDirectory() {
|
||||
footError.value = "";
|
||||
const response = await fetch("/api/downloads/pick", { method: "POST" });
|
||||
const response = await fetch(`${apiBase.value}/downloads/pick`, { method: "POST" });
|
||||
if (!response.ok) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
const detail = typeof payload.detail === "string" ? payload.detail : "";
|
||||
@@ -310,20 +364,21 @@ async function chooseDirectory() {
|
||||
}
|
||||
|
||||
async function startDownload() {
|
||||
const seen = new Set<number>();
|
||||
const items: { id: number; title: string; image: string }[] = [];
|
||||
const seen = new Set<string>();
|
||||
const items: { id: string; title: string; image: string }[] = [];
|
||||
for (const section of sections.value) {
|
||||
for (const item of section.items) {
|
||||
if (!selected.value.has(item.id) || seen.has(item.id)) continue;
|
||||
seen.add(item.id);
|
||||
items.push({ id: item.id, title: item.title, image: item.image });
|
||||
const key = dramaKey(item.id);
|
||||
if (!selected.value.has(key) || seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
items.push({ id: key, title: item.title, image: item.image });
|
||||
}
|
||||
}
|
||||
if (!items.length) return;
|
||||
starting.value = true;
|
||||
footError.value = "";
|
||||
try {
|
||||
const response = await fetch("/api/downloads", {
|
||||
const response = await fetch(`${apiBase.value}/downloads`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: props.token, device: props.device, items }),
|
||||
@@ -384,10 +439,11 @@ async function startDownload() {
|
||||
:key="item.id"
|
||||
class="drama-card"
|
||||
:data-card="cardKey(section.key, item.id)"
|
||||
@click="toggleDrama(item.id, !selected.has(item.id))"
|
||||
@click="toggleDrama(item.id, !selected.has(dramaKey(item.id)))"
|
||||
>
|
||||
<div class="cover">
|
||||
<img v-if="item.image" :src="coverOf(item.image)" :alt="item.title" />
|
||||
<span v-if="item.corner || item.locked || item.limitedFree" class="cover-tag">{{ item.corner || (item.limitedFree ? "限免" : item.payType || "付费") }}</span>
|
||||
<div class="cover-play-layer">
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
@@ -402,7 +458,7 @@ async function startDownload() {
|
||||
<div class="pick" @click.stop>
|
||||
<n-tooltip placement="left">
|
||||
<template #trigger>
|
||||
<n-checkbox :checked="selected.has(item.id)" @update:checked="toggleDrama(item.id, $event)" />
|
||||
<n-checkbox :checked="selected.has(dramaKey(item.id))" @update:checked="toggleDrama(item.id, $event)" />
|
||||
</template>
|
||||
{{ selected.has(item.id) ? "取消选择" : "选择" }}
|
||||
</n-tooltip>
|
||||
@@ -496,6 +552,22 @@ async function startDownload() {
|
||||
cursor: pointer;
|
||||
}
|
||||
.cover { position: relative; background: #2a2a2a; }
|
||||
.cover-tag {
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
top: 6px;
|
||||
z-index: 2;
|
||||
max-width: calc(100% - 12px);
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
background: rgba(0, 0, 0, 0.62);
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cover img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
|
||||
.cover:not(:has(img)) { aspect-ratio: 3 / 4; }
|
||||
.cover-play-layer {
|
||||
|
||||
Reference in New Issue
Block a user