115网盘在线播放
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
normalizePan123Password,
|
||||
validatePan123Credentials,
|
||||
} from '@/lib/netdisk/pan123.client';
|
||||
import { assertPan115CookieHeaderSafe, normalizePan115Cookie, validatePan115Cookie } from '@/lib/netdisk/pan115.client';
|
||||
import {
|
||||
assertQuarkCookieHeaderSafe,
|
||||
normalizeQuarkCookie,
|
||||
@@ -56,7 +57,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { action, Quark, Mobile, Baidu, Tianyi, Pan123, UC, provider } = body;
|
||||
const { action, Quark, Mobile, Baidu, Tianyi, Pan123, UC, Pan115, provider } = body;
|
||||
const adminConfig = await getConfig();
|
||||
|
||||
if (action === 'save') {
|
||||
@@ -71,6 +72,7 @@ export async function POST(request: NextRequest) {
|
||||
const normalizedPan123Password = Pan123?.Password ? normalizePan123Password(Pan123.Password) : '';
|
||||
const normalizedUCCookie = UC?.Cookie ? assertUCCookieHeaderSafe(UC.Cookie) : '';
|
||||
const normalizedUCToken = UC?.Token ? String(UC.Token).trim() : '';
|
||||
const normalizedPan115Cookie = Pan115?.Cookie ? assertPan115CookieHeaderSafe(Pan115.Cookie) : '';
|
||||
|
||||
adminConfig.NetDiskConfig = adminConfig.NetDiskConfig || {};
|
||||
adminConfig.NetDiskConfig.Quark = {
|
||||
@@ -102,6 +104,10 @@ export async function POST(request: NextRequest) {
|
||||
Token: normalizedUCToken,
|
||||
SavePath: UC?.SavePath || '/',
|
||||
};
|
||||
adminConfig.NetDiskConfig.Pan115 = {
|
||||
Enabled: Boolean(Pan115?.Enabled),
|
||||
Cookie: normalizedPan115Cookie,
|
||||
};
|
||||
|
||||
await db.saveAdminConfig(adminConfig);
|
||||
await setCachedConfig(adminConfig);
|
||||
@@ -167,6 +173,16 @@ export async function POST(request: NextRequest) {
|
||||
message: 'UC Cookie 可读',
|
||||
});
|
||||
}
|
||||
if (provider === 'pan115') {
|
||||
if (!Pan115?.Cookie) {
|
||||
return NextResponse.json({ error: '请先填写115 Cookie' }, { status: 400 });
|
||||
}
|
||||
await validatePan115Cookie(normalizePan115Cookie(Pan115.Cookie));
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '115 Cookie 格式正常',
|
||||
});
|
||||
}
|
||||
|
||||
if (!Quark?.Cookie) {
|
||||
return NextResponse.json({ error: '请先填写夸克 Cookie' }, { status: 400 });
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { listPan115ShareVideos } from '@/lib/netdisk/pan115.client';
|
||||
import { createPan115NetdiskSession } from '@/lib/netdisk/pan115-session-cache';
|
||||
import { NETDISK_115_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 pan115Config = config.NetDiskConfig?.Pan115;
|
||||
if (!pan115Config?.Enabled || !pan115Config.Cookie) {
|
||||
return NextResponse.json({ error: '115网盘未配置或未启用' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await listPan115ShareVideos(shareUrl, passcode || '');
|
||||
const session = createPan115NetdiskSession({
|
||||
title: title || result.title,
|
||||
shareUrl,
|
||||
passcode,
|
||||
files: result.files,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
source: NETDISK_115_SOURCE,
|
||||
id: session.id,
|
||||
title: title || result.title,
|
||||
fileCount: result.files.length,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '立即播放失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getPan115PlayUrl } from '@/lib/netdisk/pan115.client';
|
||||
import { getPan115NetdiskSession, refreshPan115NetdiskSession } from '@/lib/netdisk/pan115-session-cache';
|
||||
import { resolvePan115Session } from '@/lib/netdisk/pan115-session-resolver';
|
||||
|
||||
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 id = searchParams.get('id') || searchParams.get('session');
|
||||
const episodeIndexRaw = searchParams.get('episodeIndex');
|
||||
const format = searchParams.get('format');
|
||||
if (!id || 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 });
|
||||
}
|
||||
|
||||
refreshPan115NetdiskSession(id) || getPan115NetdiskSession(id);
|
||||
const { session, cookie } = await resolvePan115Session(id);
|
||||
const file = session.files[episodeIndex];
|
||||
if (!file) {
|
||||
return NextResponse.json({ error: '播放文件不存在' }, { status: 404 });
|
||||
}
|
||||
|
||||
const url = await getPan115PlayUrl(file, cookie);
|
||||
refreshPan115NetdiskSession(id);
|
||||
|
||||
if (format === 'json') {
|
||||
return NextResponse.json({ url, headers: {} });
|
||||
}
|
||||
|
||||
return NextResponse.redirect(url);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '获取播放地址失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,12 @@ import {
|
||||
parsePan123NetdiskId,
|
||||
refreshPan123NetdiskSession,
|
||||
} from '@/lib/netdisk/pan123-session-cache';
|
||||
import {
|
||||
createPan115NetdiskSession,
|
||||
getPan115NetdiskSession,
|
||||
parsePan115NetdiskId,
|
||||
refreshPan115NetdiskSession,
|
||||
} from '@/lib/netdisk/pan115-session-cache';
|
||||
import {
|
||||
createQuarkNetdiskSession,
|
||||
getQuarkNetdiskSession,
|
||||
@@ -32,6 +38,7 @@ import {
|
||||
} from '@/lib/netdisk/quark-session-cache';
|
||||
import {
|
||||
LEGACY_QUARK_TEMP_SOURCE,
|
||||
NETDISK_115_SOURCE,
|
||||
NETDISK_123_SOURCE,
|
||||
NETDISK_BAIDU_SOURCE,
|
||||
NETDISK_MOBILE_SOURCE,
|
||||
@@ -630,6 +637,74 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceCode === NETDISK_115_SOURCE) {
|
||||
try {
|
||||
const config = await getConfig();
|
||||
const pan115Config = config.NetDiskConfig?.Pan115;
|
||||
if (!pan115Config?.Enabled || !pan115Config.Cookie) {
|
||||
throw new Error('115网盘未配置或未启用');
|
||||
}
|
||||
|
||||
let session = refreshPan115NetdiskSession(id) || getPan115NetdiskSession(id);
|
||||
if (!session) {
|
||||
const payload = parsePan115NetdiskId(id);
|
||||
const { listPan115ShareVideos } = await import('@/lib/netdisk/pan115.client');
|
||||
const result = await listPan115ShareVideos(payload.shareUrl, payload.passcode || '');
|
||||
session = createPan115NetdiskSession({
|
||||
title: title || result.title,
|
||||
shareUrl: payload.shareUrl,
|
||||
passcode: payload.passcode,
|
||||
files: result.files,
|
||||
});
|
||||
}
|
||||
if (!session) {
|
||||
throw new Error('115网盘播放信息恢复失败');
|
||||
}
|
||||
|
||||
const pan115Session = session;
|
||||
const { parseVideoFileName } = await import('@/lib/video-parser');
|
||||
const parsedFiles = pan115Session.files
|
||||
.map((file, index) => {
|
||||
const parsed = parseVideoFileName(file.name);
|
||||
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
|
||||
? a.sortEpisode - b.sortEpisode
|
||||
: a.name.localeCompare(b.name, 'zh-Hans-CN', { numeric: true, sensitivity: 'base' });
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
source: NETDISK_115_SOURCE,
|
||||
source_name: '115网盘',
|
||||
id: pan115Session.id,
|
||||
title: title || pan115Session.title,
|
||||
poster: '',
|
||||
year: '',
|
||||
douban_id: 0,
|
||||
desc: `115网盘分享:${pan115Session.shareUrl}`,
|
||||
episodes: parsedFiles.map((file) => (
|
||||
`/api/netdisk/115/play?id=${encodeURIComponent(pan115Session.id)}&episodeIndex=${file.originalIndex}`
|
||||
)),
|
||||
episodes_titles: parsedFiles.map((file) => file.displayTitle),
|
||||
proxyMode: false,
|
||||
});
|
||||
} catch (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();
|
||||
|
||||
Reference in New Issue
Block a user