移动云盘在线播放
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user