123云盘播放
This commit is contained in:
@@ -3711,6 +3711,9 @@ const NetDiskConfigComponent = ({
|
||||
const [tianyiEnabled, setTianyiEnabled] = useState(false);
|
||||
const [tianyiAccount, setTianyiAccount] = useState('');
|
||||
const [tianyiPassword, setTianyiPassword] = useState('');
|
||||
const [pan123Enabled, setPan123Enabled] = useState(false);
|
||||
const [pan123Account, setPan123Account] = useState('');
|
||||
const [pan123Password, setPan123Password] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const quark = config?.NetDiskConfig?.Quark;
|
||||
@@ -3725,6 +3728,9 @@ const NetDiskConfigComponent = ({
|
||||
setTianyiEnabled(config?.NetDiskConfig?.Tianyi?.Enabled || false);
|
||||
setTianyiAccount(config?.NetDiskConfig?.Tianyi?.Account || '');
|
||||
setTianyiPassword(config?.NetDiskConfig?.Tianyi?.Password || '');
|
||||
setPan123Enabled(config?.NetDiskConfig?.Pan123?.Enabled || false);
|
||||
setPan123Account(config?.NetDiskConfig?.Pan123?.Account || '');
|
||||
setPan123Password(config?.NetDiskConfig?.Pan123?.Password || '');
|
||||
}, [config]);
|
||||
|
||||
const handleSave = async () => {
|
||||
@@ -3752,6 +3758,11 @@ const NetDiskConfigComponent = ({
|
||||
Account: tianyiAccount,
|
||||
Password: tianyiPassword,
|
||||
},
|
||||
Pan123: {
|
||||
Enabled: pan123Enabled,
|
||||
Account: pan123Account,
|
||||
Password: pan123Password,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -3878,6 +3889,35 @@ const NetDiskConfigComponent = ({
|
||||
});
|
||||
};
|
||||
|
||||
const handleValidatePan123 = async () => {
|
||||
await withLoading('validatePan123NetDisk', async () => {
|
||||
try {
|
||||
const response = await fetch('/api/admin/netdisk', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action: 'validate',
|
||||
provider: 'pan123',
|
||||
Pan123: {
|
||||
Account: pan123Account,
|
||||
Password: pan123Password,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || '校验失败');
|
||||
}
|
||||
|
||||
showSuccess(data.message || '123网盘账号密码可用', showAlert);
|
||||
} catch (error) {
|
||||
showError(error instanceof Error ? error.message : '校验失败', showAlert);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='space-y-6'>
|
||||
<details className='pt-4 border-t border-gray-200 dark:border-gray-700'>
|
||||
@@ -4144,6 +4184,78 @@ const NetDiskConfigComponent = ({
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details className='pt-4 border-t border-gray-200 dark:border-gray-700'>
|
||||
<summary className='text-sm font-semibold text-gray-900 dark:text-gray-100 cursor-pointer'>
|
||||
123网盘
|
||||
</summary>
|
||||
<div className='mt-4 space-y-4'>
|
||||
<div className='flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700'>
|
||||
<div>
|
||||
<h3 className='text-sm font-medium text-gray-900 dark:text-gray-100'>
|
||||
启用123网盘
|
||||
</h3>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mt-1'>
|
||||
开启后,网盘搜索中的123网盘资源会显示“立即播放”按钮
|
||||
</p>
|
||||
</div>
|
||||
<label className='relative inline-flex items-center cursor-pointer'>
|
||||
<input
|
||||
type='checkbox'
|
||||
checked={pan123Enabled}
|
||||
onChange={(e) => setPan123Enabled(e.target.checked)}
|
||||
className='sr-only peer'
|
||||
/>
|
||||
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-teal-300 dark:peer-focus:ring-teal-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-teal-600"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||
账号
|
||||
</label>
|
||||
<input
|
||||
type='text'
|
||||
value={pan123Account}
|
||||
onChange={(e) => setPan123Account(e.target.value)}
|
||||
disabled={!pan123Enabled}
|
||||
placeholder='输入123网盘账号'
|
||||
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-teal-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed'
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||
密码
|
||||
</label>
|
||||
<input
|
||||
type='password'
|
||||
value={pan123Password}
|
||||
onChange={(e) => setPan123Password(e.target.value)}
|
||||
disabled={!pan123Enabled}
|
||||
placeholder='输入123网盘密码'
|
||||
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-teal-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed'
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='flex gap-3'>
|
||||
<button
|
||||
onClick={handleValidatePan123}
|
||||
disabled={!pan123Enabled || !pan123Account || !pan123Password || isLoading('validatePan123NetDisk')}
|
||||
className={buttonStyles.primary}
|
||||
>
|
||||
{isLoading('validatePan123NetDisk') ? '校验中...' : '校验123网盘账号密码'}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isLoading('saveNetDisk')}
|
||||
className={buttonStyles.success}
|
||||
>
|
||||
{isLoading('saveNetDisk') ? '保存中...' : '保存配置'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<AlertModal
|
||||
isOpen={alertModal.isOpen}
|
||||
onClose={hideAlert}
|
||||
|
||||
@@ -10,6 +10,11 @@ import {
|
||||
assertMobileAuthorizationHeaderSafe,
|
||||
normalizeMobileAuthorization,
|
||||
} from '@/lib/netdisk/mobile.client';
|
||||
import {
|
||||
normalizePan123Account,
|
||||
normalizePan123Password,
|
||||
validatePan123Credentials,
|
||||
} from '@/lib/netdisk/pan123.client';
|
||||
import {
|
||||
assertQuarkCookieHeaderSafe,
|
||||
normalizeQuarkCookie,
|
||||
@@ -46,7 +51,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { action, Quark, Mobile, Baidu, Tianyi, provider } = body;
|
||||
const { action, Quark, Mobile, Baidu, Tianyi, Pan123, provider } = body;
|
||||
const adminConfig = await getConfig();
|
||||
|
||||
if (action === 'save') {
|
||||
@@ -57,6 +62,8 @@ export async function POST(request: NextRequest) {
|
||||
const normalizedBaiduCookie = Baidu?.Cookie ? assertBaiduCookieHeaderSafe(Baidu.Cookie) : '';
|
||||
const normalizedTianyiAccount = Tianyi?.Account ? normalizeTianyiAccount(Tianyi.Account) : '';
|
||||
const normalizedTianyiPassword = Tianyi?.Password ? normalizeTianyiPassword(Tianyi.Password) : '';
|
||||
const normalizedPan123Account = Pan123?.Account ? normalizePan123Account(Pan123.Account) : '';
|
||||
const normalizedPan123Password = Pan123?.Password ? normalizePan123Password(Pan123.Password) : '';
|
||||
|
||||
adminConfig.NetDiskConfig = adminConfig.NetDiskConfig || {};
|
||||
adminConfig.NetDiskConfig.Quark = {
|
||||
@@ -77,6 +84,11 @@ export async function POST(request: NextRequest) {
|
||||
Account: normalizedTianyiAccount,
|
||||
Password: normalizedTianyiPassword,
|
||||
};
|
||||
adminConfig.NetDiskConfig.Pan123 = {
|
||||
Enabled: Boolean(Pan123?.Enabled),
|
||||
Account: normalizedPan123Account,
|
||||
Password: normalizedPan123Password,
|
||||
};
|
||||
|
||||
await db.saveAdminConfig(adminConfig);
|
||||
await setCachedConfig(adminConfig);
|
||||
@@ -119,6 +131,19 @@ export async function POST(request: NextRequest) {
|
||||
message: '天翼云盘账号密码可用',
|
||||
});
|
||||
}
|
||||
if (provider === 'pan123') {
|
||||
if (!Pan123?.Account || !Pan123?.Password) {
|
||||
return NextResponse.json({ error: '请先填写123网盘账号和密码' }, { status: 400 });
|
||||
}
|
||||
await validatePan123Credentials(
|
||||
normalizePan123Account(Pan123.Account),
|
||||
normalizePan123Password(Pan123.Password)
|
||||
);
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '123网盘账号密码可用',
|
||||
});
|
||||
}
|
||||
|
||||
if (!Quark?.Cookie) {
|
||||
return NextResponse.json({ error: '请先填写夸克 Cookie' }, { status: 400 });
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { listPan123ShareVideos } from '@/lib/netdisk/pan123.client';
|
||||
import { createPan123NetdiskSession } from '@/lib/netdisk/pan123-session-cache';
|
||||
import { NETDISK_123_SOURCE } from '@/lib/netdisk/source';
|
||||
import { hasFeaturePermission } from '@/lib/permissions';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const authInfo = getAuthInfoFromCookie(request);
|
||||
if (!authInfo?.username) {
|
||||
return NextResponse.json({ error: '未登录' }, { status: 401 });
|
||||
}
|
||||
if (!(await hasFeaturePermission(authInfo.username, 'netdisk_temp_play'))) {
|
||||
return NextResponse.json({ error: '无权限使用临时播放' }, { status: 403 });
|
||||
}
|
||||
|
||||
const { shareUrl, passcode, title } = await request.json();
|
||||
if (!shareUrl) {
|
||||
return NextResponse.json({ error: '分享链接不能为空' }, { status: 400 });
|
||||
}
|
||||
|
||||
const config = await getConfig();
|
||||
const pan123Config = config.NetDiskConfig?.Pan123;
|
||||
if (!pan123Config?.Enabled || !pan123Config.Account || !pan123Config.Password) {
|
||||
return NextResponse.json({ error: '123网盘未配置或未启用' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await listPan123ShareVideos(shareUrl, passcode || '');
|
||||
const session = createPan123NetdiskSession({
|
||||
title: title || result.title,
|
||||
shareUrl,
|
||||
passcode,
|
||||
files: result.files,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
source: NETDISK_123_SOURCE,
|
||||
id: session.id,
|
||||
title: title || result.title,
|
||||
totalFiles: result.files.length,
|
||||
expiresAt: session.expiresAt,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '立即播放失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { getPan123PlayInfo, listPan123ShareVideos } from '@/lib/netdisk/pan123.client';
|
||||
import {
|
||||
createPan123NetdiskSession,
|
||||
getPan123NetdiskSession,
|
||||
parsePan123NetdiskId,
|
||||
refreshPan123NetdiskSession,
|
||||
} from '@/lib/netdisk/pan123-session-cache';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const authInfo = getAuthInfoFromCookie(request);
|
||||
if (!authInfo?.username) {
|
||||
return NextResponse.json({ error: '未授权' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const sessionId = searchParams.get('id') || searchParams.get('session');
|
||||
const episodeIndexRaw = searchParams.get('episodeIndex');
|
||||
const format = searchParams.get('format');
|
||||
const quality = searchParams.get('quality') || '';
|
||||
if (!sessionId || episodeIndexRaw == null) {
|
||||
return NextResponse.json({ error: '缺少参数' }, { status: 400 });
|
||||
}
|
||||
|
||||
const episodeIndex = Number.parseInt(episodeIndexRaw, 10);
|
||||
if (!Number.isInteger(episodeIndex) || episodeIndex < 0) {
|
||||
return NextResponse.json({ error: '无效的 episodeIndex' }, { status: 400 });
|
||||
}
|
||||
|
||||
const config = await getConfig();
|
||||
const pan123Config = config.NetDiskConfig?.Pan123;
|
||||
if (!pan123Config?.Enabled || !pan123Config.Account || !pan123Config.Password) {
|
||||
return NextResponse.json({ error: '123网盘未配置或未启用' }, { status: 400 });
|
||||
}
|
||||
|
||||
let session = refreshPan123NetdiskSession(sessionId) || getPan123NetdiskSession(sessionId);
|
||||
if (!session) {
|
||||
const payload = parsePan123NetdiskId(sessionId);
|
||||
const result = await listPan123ShareVideos(payload.shareUrl, payload.passcode || '');
|
||||
session = createPan123NetdiskSession({
|
||||
title: result.title,
|
||||
shareUrl: payload.shareUrl,
|
||||
passcode: payload.passcode,
|
||||
files: result.files,
|
||||
});
|
||||
}
|
||||
|
||||
const file = session.files[episodeIndex];
|
||||
if (!file) {
|
||||
return NextResponse.json({ error: '播放文件不存在' }, { status: 404 });
|
||||
}
|
||||
|
||||
const playInfo = await getPan123PlayInfo(file, pan123Config.Account, pan123Config.Password);
|
||||
refreshPan123NetdiskSession(sessionId);
|
||||
const selectedUrl = playInfo.qualities.find((item) => item.name === quality)?.url || playInfo.url;
|
||||
|
||||
if (format === 'json') {
|
||||
return NextResponse.json({
|
||||
url: selectedUrl,
|
||||
headers: {},
|
||||
qualities: playInfo.qualities,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.redirect(selectedUrl);
|
||||
} catch (error) {
|
||||
console.error('[netdisk-123][play] error', error);
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '获取播放地址失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,13 @@ import {
|
||||
parseTianyiNetdiskId,
|
||||
refreshTianyiNetdiskSession,
|
||||
} from '@/lib/netdisk/tianyi-session-cache';
|
||||
import { LEGACY_QUARK_TEMP_SOURCE, NETDISK_BAIDU_SOURCE, NETDISK_MOBILE_SOURCE, NETDISK_QUARK_SOURCE, NETDISK_TIANYI_SOURCE, normalizeNetdiskSource } from '@/lib/netdisk/source';
|
||||
import {
|
||||
createPan123NetdiskSession,
|
||||
getPan123NetdiskSession,
|
||||
parsePan123NetdiskId,
|
||||
refreshPan123NetdiskSession,
|
||||
} from '@/lib/netdisk/pan123-session-cache';
|
||||
import { LEGACY_QUARK_TEMP_SOURCE, NETDISK_123_SOURCE, NETDISK_BAIDU_SOURCE, NETDISK_MOBILE_SOURCE, NETDISK_QUARK_SOURCE, NETDISK_TIANYI_SOURCE, normalizeNetdiskSource } from '@/lib/netdisk/source';
|
||||
import {
|
||||
executeSavedSourceScript,
|
||||
normalizeScriptDetailResult,
|
||||
@@ -40,6 +46,30 @@ import {
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
function formatNetdiskEpisodeTitle(parsed: {
|
||||
season?: number;
|
||||
episode?: number;
|
||||
}, fallback: string) {
|
||||
if (parsed.season && parsed.episode) {
|
||||
const season = String(Math.trunc(parsed.season)).padStart(2, '0');
|
||||
const episodeValue = parsed.episode;
|
||||
const episode =
|
||||
Number.isInteger(episodeValue)
|
||||
? String(Math.trunc(episodeValue)).padStart(2, '0')
|
||||
: String(episodeValue);
|
||||
return `S${season}E${episode}`;
|
||||
}
|
||||
|
||||
if (parsed.episode) {
|
||||
const episodeValue = parsed.episode;
|
||||
return Number.isInteger(episodeValue)
|
||||
? `第${Math.trunc(episodeValue)}集`
|
||||
: `第${episodeValue}集`;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 source 和 id 直接获取视频详情
|
||||
* 这个API专门用于play页面快速获取当前源的详情
|
||||
@@ -327,16 +357,14 @@ export async function GET(request: NextRequest) {
|
||||
const { parseVideoFileName } = await import('@/lib/video-parser');
|
||||
const parsedFiles = mobileSession.files.map((file, index) => {
|
||||
const parsed = parseVideoFileName(file.name);
|
||||
return {
|
||||
...file,
|
||||
originalIndex: index,
|
||||
sortEpisode: parsed.episode || index + 1,
|
||||
isOVA: parsed.isOVA,
|
||||
displayTitle:
|
||||
parsed.title ||
|
||||
(parsed.episode ? `第${parsed.episode}集` : file.name),
|
||||
};
|
||||
}).sort((a, b) => {
|
||||
return {
|
||||
...file,
|
||||
originalIndex: index,
|
||||
sortEpisode: parsed.episode || index + 1,
|
||||
isOVA: parsed.isOVA,
|
||||
displayTitle: formatNetdiskEpisodeTitle(parsed, file.name),
|
||||
};
|
||||
}).sort((a, b) => {
|
||||
if (a.isOVA && !b.isOVA) return 1;
|
||||
if (!a.isOVA && b.isOVA) return -1;
|
||||
return a.sortEpisode !== b.sortEpisode
|
||||
@@ -407,8 +435,7 @@ export async function GET(request: NextRequest) {
|
||||
originalIndex: index,
|
||||
sortEpisode: parsed.episode || index + 1,
|
||||
isOVA: parsed.isOVA,
|
||||
displayTitle:
|
||||
parsed.title || (parsed.episode ? `第${parsed.episode}集` : file.name),
|
||||
displayTitle: formatNetdiskEpisodeTitle(parsed, file.name),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
@@ -485,8 +512,7 @@ export async function GET(request: NextRequest) {
|
||||
originalIndex: index,
|
||||
sortEpisode: parsed.episode || index + 1,
|
||||
isOVA: parsed.isOVA,
|
||||
displayTitle:
|
||||
parsed.title || (parsed.episode ? `第${parsed.episode}集` : file.name),
|
||||
displayTitle: formatNetdiskEpisodeTitle(parsed, file.name),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
@@ -520,6 +546,75 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceCode === NETDISK_123_SOURCE) {
|
||||
try {
|
||||
const config = await getConfig();
|
||||
const pan123Config = config.NetDiskConfig?.Pan123;
|
||||
if (!pan123Config?.Enabled || !pan123Config.Account || !pan123Config.Password) {
|
||||
throw new Error('123网盘未配置或未启用');
|
||||
}
|
||||
|
||||
let session = refreshPan123NetdiskSession(id) || getPan123NetdiskSession(id);
|
||||
if (!session) {
|
||||
const payload = parsePan123NetdiskId(id);
|
||||
const { listPan123ShareVideos } = await import('@/lib/netdisk/pan123.client');
|
||||
const result = await listPan123ShareVideos(payload.shareUrl, payload.passcode || '');
|
||||
session = createPan123NetdiskSession({
|
||||
title: title || result.title,
|
||||
shareUrl: payload.shareUrl,
|
||||
passcode: payload.passcode,
|
||||
files: result.files,
|
||||
});
|
||||
}
|
||||
if (!session) {
|
||||
throw new Error('123网盘播放信息恢复失败');
|
||||
}
|
||||
|
||||
const pan123Session = session;
|
||||
const { parseVideoFileName } = await import('@/lib/video-parser');
|
||||
const parsedFiles = pan123Session.files
|
||||
.map((file, index) => {
|
||||
const parsed = parseVideoFileName(file.fileName);
|
||||
return {
|
||||
...file,
|
||||
originalIndex: index,
|
||||
sortEpisode: parsed.episode || index + 1,
|
||||
isOVA: parsed.isOVA,
|
||||
displayTitle: formatNetdiskEpisodeTitle(parsed, file.fileName),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
if (a.isOVA && !b.isOVA) return 1;
|
||||
if (!a.isOVA && b.isOVA) return -1;
|
||||
return a.sortEpisode !== b.sortEpisode
|
||||
? a.sortEpisode - b.sortEpisode
|
||||
: a.fileName.localeCompare(b.fileName, 'zh-Hans-CN', { numeric: true, sensitivity: 'base' });
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
source: NETDISK_123_SOURCE,
|
||||
source_name: '123网盘',
|
||||
id: pan123Session.id,
|
||||
title: title || pan123Session.title,
|
||||
poster: '',
|
||||
year: '',
|
||||
douban_id: 0,
|
||||
desc: `123网盘分享:${pan123Session.shareUrl}`,
|
||||
episodes: parsedFiles.map((file) => (
|
||||
`/api/netdisk/123/play?id=${encodeURIComponent(pan123Session.id)}&episodeIndex=${file.originalIndex}`
|
||||
)),
|
||||
episodes_titles: parsedFiles.map((file) => file.displayTitle),
|
||||
proxyMode: false,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[netdisk-123][source-detail] error', error);
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceCode === NETDISK_QUARK_SOURCE || sourceCode === LEGACY_QUARK_TEMP_SOURCE) {
|
||||
try {
|
||||
const config = await getConfig();
|
||||
@@ -555,7 +650,7 @@ export async function GET(request: NextRequest) {
|
||||
originalIndex: index,
|
||||
fileName: file.name,
|
||||
episode: parsed.episode || index + 1,
|
||||
title: parsed.title || (parsed.episode ? `第${parsed.episode}集` : file.name),
|
||||
title: formatNetdiskEpisodeTitle(parsed, file.name),
|
||||
isOVA: parsed.isOVA,
|
||||
};
|
||||
})
|
||||
|
||||
+120
-8
@@ -24,6 +24,7 @@ import HttpWarningDialog from '@/components/HttpWarningDialog';
|
||||
import PageLayout from '@/components/PageLayout';
|
||||
import ScrollableRow from '@/components/ScrollableRow';
|
||||
import { useSite } from '@/components/SiteProvider';
|
||||
import Toast, { ToastProps } from '@/components/Toast';
|
||||
import VideoCard from '@/components/VideoCard';
|
||||
|
||||
// 首页模块配置接口
|
||||
@@ -70,20 +71,129 @@ function HomeClient() {
|
||||
const [mangaEnabled, setMangaEnabled] = useState(false);
|
||||
const [showDirectPlayDialog, setShowDirectPlayDialog] = useState(false);
|
||||
const [directPlayUrl, setDirectPlayUrl] = useState('');
|
||||
const [directPlaySubmitting, setDirectPlaySubmitting] = useState(false);
|
||||
const [toast, setToast] = useState<ToastProps | null>(null);
|
||||
|
||||
const detectNetdiskLink = (url: string): {
|
||||
provider: 'quark' | 'mobile' | 'baidu' | 'tianyi' | '123';
|
||||
shareUrl: string;
|
||||
passcode?: string;
|
||||
} | null => {
|
||||
const trimmed = url.trim();
|
||||
|
||||
const pickPasscode = (...values: Array<string | undefined>) =>
|
||||
values.map((item) => item?.trim()).find(Boolean);
|
||||
|
||||
const inlinePasscode = (text: string) =>
|
||||
pickPasscode(
|
||||
text.match(/(?:提取码|访问码|密码)\s*[::=]?\s*([a-zA-Z0-9]{4,8})/i)?.[1],
|
||||
text.match(/[?&](?:pwd|passcode|accessCode)=([^&\s]+)/i)?.[1]
|
||||
);
|
||||
|
||||
if (/https:\/\/(?:www\.)?123(?:684|865|912|pan)\.(?:com|cn)\/s\//i.test(trimmed)) {
|
||||
return {
|
||||
provider: '123',
|
||||
shareUrl: trimmed,
|
||||
passcode: pickPasscode(
|
||||
trimmed.match(/[?&]pwd=([^&]+)/i)?.[1],
|
||||
inlinePasscode(trimmed)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (/https:\/\/cloud\.189\.cn\/(web\/share\?code=|t\/)/i.test(trimmed) || /https:\/\/h5\.cloud\.189\.cn\/share\.html#\/t\//i.test(trimmed)) {
|
||||
return {
|
||||
provider: 'tianyi',
|
||||
shareUrl: trimmed,
|
||||
passcode: pickPasscode(
|
||||
trimmed.match(/[?&]pwd=([^&]+)/i)?.[1],
|
||||
inlinePasscode(trimmed)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (/pan\.baidu\.com\/(s\/|wap\/init\?surl=)/i.test(trimmed)) {
|
||||
return {
|
||||
provider: 'baidu',
|
||||
shareUrl: trimmed,
|
||||
passcode: pickPasscode(
|
||||
trimmed.match(/[?&](?:pwd|accessCode)=([^&]+)/i)?.[1],
|
||||
inlinePasscode(trimmed)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (/https:\/\/pan\.quark\.cn\/s\//i.test(trimmed)) {
|
||||
return {
|
||||
provider: 'quark',
|
||||
shareUrl: trimmed,
|
||||
passcode: pickPasscode(
|
||||
trimmed.match(/[?&](?:pwd|passcode)=([^&]+)/i)?.[1],
|
||||
inlinePasscode(trimmed)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (/https:\/\/(?:yun|caiyun)\.139\.com\//i.test(trimmed)) {
|
||||
return { provider: 'mobile', shareUrl: trimmed };
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const handleDirectPlay = () => {
|
||||
setDirectPlayUrl('');
|
||||
setShowDirectPlayDialog(true);
|
||||
};
|
||||
|
||||
const submitDirectPlay = () => {
|
||||
const submitDirectPlay = async () => {
|
||||
const trimmed = directPlayUrl.trim();
|
||||
if (!trimmed) return;
|
||||
const encoded = base58Encode(trimmed);
|
||||
if (!encoded) return;
|
||||
setShowDirectPlayDialog(false);
|
||||
setDirectPlayUrl('');
|
||||
router.push(`/play?source=directplay&id=${encodeURIComponent(encoded)}`);
|
||||
setDirectPlaySubmitting(true);
|
||||
try {
|
||||
const netdisk = detectNetdiskLink(trimmed);
|
||||
if (netdisk) {
|
||||
const source =
|
||||
netdisk.provider === 'mobile'
|
||||
? 'netdisk-mobile'
|
||||
: netdisk.provider === 'baidu'
|
||||
? 'netdisk-baidu'
|
||||
: netdisk.provider === 'tianyi'
|
||||
? 'netdisk-tianyi'
|
||||
: netdisk.provider === '123'
|
||||
? 'netdisk-123'
|
||||
: 'netdisk-quark';
|
||||
const id = base58Encode(
|
||||
JSON.stringify({
|
||||
shareUrl: netdisk.shareUrl,
|
||||
passcode: netdisk.passcode || '',
|
||||
})
|
||||
);
|
||||
if (!id) {
|
||||
throw new Error('网盘链接编码失败');
|
||||
}
|
||||
const targetUrl = `/play?source=${encodeURIComponent(source)}&id=${encodeURIComponent(id)}&title=${encodeURIComponent('网盘直链播放')}`;
|
||||
setShowDirectPlayDialog(false);
|
||||
setDirectPlayUrl('');
|
||||
window.location.assign(targetUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
const encoded = base58Encode(trimmed);
|
||||
if (!encoded) return;
|
||||
const targetUrl = `/play?source=directplay&id=${encodeURIComponent(encoded)}`;
|
||||
setShowDirectPlayDialog(false);
|
||||
setDirectPlayUrl('');
|
||||
window.location.assign(targetUrl);
|
||||
} catch (error) {
|
||||
setToast({
|
||||
message: error instanceof Error ? error.message : '播放失败',
|
||||
type: 'error',
|
||||
onClose: () => setToast(null),
|
||||
});
|
||||
} finally {
|
||||
setDirectPlaySubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadHomeLayoutSettings = () => {
|
||||
@@ -759,16 +869,18 @@ function HomeClient() {
|
||||
</button>
|
||||
<button
|
||||
onClick={submitDirectPlay}
|
||||
disabled={!directPlayUrl.trim()}
|
||||
disabled={!directPlayUrl.trim() || directPlaySubmitting}
|
||||
className='px-4 py-2 rounded-lg bg-blue-600 hover:bg-blue-700 text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed'
|
||||
>
|
||||
开始播放
|
||||
{directPlaySubmitting ? '处理中...' : '开始播放'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{toast && <Toast {...toast} />}
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2504,6 +2504,7 @@ function PlayPageClient() {
|
||||
const isSpecialLazyPlayUrl =
|
||||
isXiaoyaLazyPlayUrl ||
|
||||
newUrl.startsWith('/api/openlist/play') ||
|
||||
newUrl.startsWith('/api/netdisk/123/play') ||
|
||||
newUrl.startsWith('/api/netdisk/quark/play') ||
|
||||
newUrl.startsWith('/api/netdisk/baidu/play') ||
|
||||
newUrl.startsWith('/api/source-script/play');
|
||||
|
||||
Reference in New Issue
Block a user