移动云盘在线播放
This commit is contained in:
@@ -5,6 +5,10 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig, setCachedConfig } from '@/lib/config';
|
||||
import { db } from '@/lib/db';
|
||||
import {
|
||||
assertMobileAuthorizationHeaderSafe,
|
||||
normalizeMobileAuthorization,
|
||||
} from '@/lib/netdisk/mobile.client';
|
||||
import {
|
||||
assertQuarkCookieHeaderSafe,
|
||||
normalizeQuarkCookie,
|
||||
@@ -40,11 +44,14 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { action, Quark } = body;
|
||||
const { action, Quark, Mobile, provider } = body;
|
||||
const adminConfig = await getConfig();
|
||||
|
||||
if (action === 'save') {
|
||||
const normalizedCookie = Quark?.Cookie ? assertQuarkCookieHeaderSafe(Quark.Cookie) : '';
|
||||
const normalizedMobileAuthorization = Mobile?.Authorization
|
||||
? assertMobileAuthorizationHeaderSafe(Mobile.Authorization)
|
||||
: '';
|
||||
|
||||
adminConfig.NetDiskConfig = adminConfig.NetDiskConfig || {};
|
||||
adminConfig.NetDiskConfig.Quark = {
|
||||
@@ -54,6 +61,10 @@ export async function POST(request: NextRequest) {
|
||||
PlayTempSavePath: Quark?.PlayTempSavePath || '/',
|
||||
OpenListTempPath: Quark?.OpenListTempPath || '/',
|
||||
};
|
||||
adminConfig.NetDiskConfig.Mobile = {
|
||||
Enabled: Boolean(Mobile?.Enabled),
|
||||
Authorization: normalizedMobileAuthorization,
|
||||
};
|
||||
|
||||
await db.saveAdminConfig(adminConfig);
|
||||
await setCachedConfig(adminConfig);
|
||||
@@ -62,10 +73,21 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
if (action === 'validate') {
|
||||
if (provider === 'mobile') {
|
||||
if (!Mobile?.Authorization) {
|
||||
return NextResponse.json({ error: '请先填写移动云盘 Authorization' }, { status: 400 });
|
||||
}
|
||||
|
||||
normalizeMobileAuthorization(Mobile.Authorization);
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '移动云盘 Authorization 格式正常',
|
||||
});
|
||||
}
|
||||
|
||||
if (!Quark?.Cookie) {
|
||||
return NextResponse.json({ error: '请先填写夸克 Cookie' }, { status: 400 });
|
||||
}
|
||||
|
||||
await validateQuarkCookieReadable(normalizeQuarkCookie(Quark.Cookie));
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { listMobileShareVideos } from '@/lib/netdisk/mobile.client';
|
||||
import { createMobileNetdiskSession } from '@/lib/netdisk/mobile-session-cache';
|
||||
import { NETDISK_MOBILE_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 mobileConfig = config.NetDiskConfig?.Mobile;
|
||||
if (!mobileConfig?.Enabled || !mobileConfig.Authorization) {
|
||||
return NextResponse.json({ error: '移动云盘未配置或未启用' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await listMobileShareVideos(shareUrl, mobileConfig.Authorization);
|
||||
const session = createMobileNetdiskSession({
|
||||
title: title || result.title,
|
||||
shareUrl,
|
||||
passcode,
|
||||
files: result.files,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
source: NETDISK_MOBILE_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,90 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import {
|
||||
getMobileShareDownloadUrl,
|
||||
getMobileSharePlayUrl,
|
||||
listMobileShareVideos,
|
||||
} from '@/lib/netdisk/mobile.client';
|
||||
import {
|
||||
createMobileNetdiskSession,
|
||||
getMobileNetdiskSession,
|
||||
parseMobileNetdiskId,
|
||||
refreshMobileNetdiskSession,
|
||||
} from '@/lib/netdisk/mobile-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');
|
||||
|
||||
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 mobileConfig = config.NetDiskConfig?.Mobile;
|
||||
if (!mobileConfig?.Enabled || !mobileConfig.Authorization) {
|
||||
return NextResponse.json({ error: '移动云盘未配置或未启用' }, { status: 400 });
|
||||
}
|
||||
|
||||
let session = refreshMobileNetdiskSession(sessionId) || getMobileNetdiskSession(sessionId);
|
||||
if (!session) {
|
||||
const payload = parseMobileNetdiskId(sessionId);
|
||||
const result = await listMobileShareVideos(payload.shareUrl, mobileConfig.Authorization);
|
||||
session = createMobileNetdiskSession({
|
||||
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 });
|
||||
}
|
||||
|
||||
let url = '';
|
||||
try {
|
||||
url = await getMobileSharePlayUrl(
|
||||
file.contentId,
|
||||
file.linkID,
|
||||
mobileConfig.Authorization
|
||||
);
|
||||
} catch {
|
||||
url = await getMobileShareDownloadUrl(
|
||||
file.contentId,
|
||||
file.linkID,
|
||||
mobileConfig.Authorization
|
||||
);
|
||||
}
|
||||
refreshMobileNetdiskSession(sessionId);
|
||||
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getConfig } from '@/lib/config';
|
||||
import { createQuarkInstantPlayFolder } from '@/lib/netdisk/quark.client';
|
||||
import { NETDISK_QUARK_SOURCE } from '@/lib/netdisk/source';
|
||||
import { hasFeaturePermission } from '@/lib/permissions';
|
||||
import { base58Encode } from '@/lib/utils';
|
||||
|
||||
@@ -76,7 +77,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
source: 'quark-temp',
|
||||
source: NETDISK_QUARK_SOURCE,
|
||||
id: base58Encode(openlistFolderPath),
|
||||
title: title || result.folderName,
|
||||
openlistFolderPath,
|
||||
|
||||
@@ -6,6 +6,13 @@ import { getAuthInfoFromCookie } from '@/lib/auth';
|
||||
import { getAvailableApiSites, getCacheTime, getConfig } from '@/lib/config';
|
||||
import { getDetailFromApiV2 } from '@/lib/downstream';
|
||||
import { getProxyToken } from '@/lib/emby-token';
|
||||
import {
|
||||
createMobileNetdiskSession,
|
||||
getMobileNetdiskSession,
|
||||
parseMobileNetdiskId,
|
||||
refreshMobileNetdiskSession,
|
||||
} from '@/lib/netdisk/mobile-session-cache';
|
||||
import { LEGACY_QUARK_TEMP_SOURCE, NETDISK_MOBILE_SOURCE, NETDISK_QUARK_SOURCE, normalizeNetdiskSource } from '@/lib/netdisk/source';
|
||||
import {
|
||||
executeSavedSourceScript,
|
||||
normalizeScriptDetailResult,
|
||||
@@ -27,7 +34,7 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get('id');
|
||||
const sourceCode = searchParams.get('source');
|
||||
const sourceCode = normalizeNetdiskSource(searchParams.get('source'));
|
||||
const fileName = searchParams.get('fileName'); // 小雅源:用户点击的文件名
|
||||
const title = searchParams.get('title');
|
||||
|
||||
@@ -275,7 +282,79 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceCode === 'quark-temp') {
|
||||
if (sourceCode === NETDISK_MOBILE_SOURCE) {
|
||||
try {
|
||||
const config = await getConfig();
|
||||
const mobileConfig = config.NetDiskConfig?.Mobile;
|
||||
if (!mobileConfig?.Enabled || !mobileConfig.Authorization) {
|
||||
throw new Error('移动云盘未配置或未启用');
|
||||
}
|
||||
|
||||
let session = refreshMobileNetdiskSession(id) || getMobileNetdiskSession(id);
|
||||
if (!session) {
|
||||
const payload = parseMobileNetdiskId(id);
|
||||
const { listMobileShareVideos } = await import('@/lib/netdisk/mobile.client');
|
||||
const result = await listMobileShareVideos(payload.shareUrl, mobileConfig.Authorization);
|
||||
session = createMobileNetdiskSession({
|
||||
title: title || result.title,
|
||||
shareUrl: payload.shareUrl,
|
||||
passcode: payload.passcode,
|
||||
files: result.files,
|
||||
});
|
||||
}
|
||||
if (!session) {
|
||||
throw new Error('移动云盘播放信息恢复失败');
|
||||
}
|
||||
const mobileSession = session;
|
||||
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) => {
|
||||
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',
|
||||
});
|
||||
});
|
||||
|
||||
const episodes = parsedFiles.map((file) => (
|
||||
`/api/netdisk/mobile/play?id=${encodeURIComponent(mobileSession.id)}&episodeIndex=${file.originalIndex}`
|
||||
));
|
||||
|
||||
return NextResponse.json({
|
||||
source: NETDISK_MOBILE_SOURCE,
|
||||
source_name: '移动云盘',
|
||||
id: mobileSession.id,
|
||||
title: title || mobileSession.title,
|
||||
poster: '',
|
||||
year: '',
|
||||
douban_id: 0,
|
||||
desc: `移动云盘分享:${mobileSession.shareUrl}`,
|
||||
episodes,
|
||||
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();
|
||||
const openListConfig = config.OpenListConfig;
|
||||
@@ -390,7 +469,7 @@ export async function GET(request: NextRequest) {
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
source: 'quark-temp',
|
||||
source: NETDISK_QUARK_SOURCE,
|
||||
source_name: '夸克临时播放',
|
||||
id,
|
||||
title: title || folderPath.split('/').filter(Boolean).pop() || '夸克临时播放',
|
||||
|
||||
Reference in New Issue
Block a user