重复转存校验

This commit is contained in:
mtvpls
2026-04-07 20:06:58 +08:00
parent 9b707c1a17
commit 4b62d7d7af
4 changed files with 126 additions and 14 deletions
+10 -3
View File
@@ -168,11 +168,18 @@ export async function GET(request: NextRequest) {
throw new Error('未找到已完成的播放链接');
}
// 如果指定了 format=json,返回 JSON 格式
// 如果指定了 format=json尝试解析到最终直链后再返回 JSON
if (format === 'json') {
const resolvedQualities = await Promise.all(
qualities.map(async (quality: any) => ({
...quality,
url: await getFinalUrl(quality.url),
}))
);
return NextResponse.json({
url: qualities[0].url,
qualities
url: resolvedQualities[0].url,
qualities: resolvedQualities,
});
}
+20
View File
@@ -50,6 +50,26 @@ export async function POST(request: NextRequest) {
result.folderName
);
if (
config.OpenListConfig?.Enabled &&
config.OpenListConfig.URL &&
config.OpenListConfig.Username &&
config.OpenListConfig.Password
) {
try {
const { OpenListClient } = await import('@/lib/openlist.client');
const openListClient = new OpenListClient(
config.OpenListConfig.URL,
config.OpenListConfig.Username,
config.OpenListConfig.Password
);
await openListClient.refreshDirectory(quarkConfig.OpenListTempPath || '/');
await openListClient.refreshDirectory(openlistFolderPath);
} catch (refreshError) {
console.warn('[quark instant-play] 刷新 OpenList 临时目录失败:', refreshError);
}
}
return NextResponse.json({
success: true,
source: 'quark-temp',
+21 -4
View File
@@ -307,6 +307,26 @@ export async function GET(request: NextRequest) {
const videoExtensions = ['.mp4', '.mkv', '.avi', '.m3u8', '.flv', '.ts', '.mov', '.wmv', '.webm', '.rmvb', '.rm', '.mpg', '.mpeg', '.3gp', '.f4v', '.m4v', '.vob'];
const listTempDirectory = async (currentPath: string, page: number, pageSize: number) => {
const load = async (refresh = false) => client.listDirectory(currentPath, page, pageSize, refresh);
let response = await load(page === 1);
if (response.code === 200) {
return response;
}
const parentPath = currentPath.substring(0, currentPath.lastIndexOf('/')) || '/';
await client.refreshDirectory(parentPath);
response = await load(true);
if (response.code !== 200) {
const message = response.message || '目录不存在或 OpenList 路径未映射';
throw new Error(`读取临时目录失败: ${message}(路径: ${currentPath}`);
}
return response;
};
const collectFiles = async (currentPath: string): Promise<Array<{ path: string; name: string }>> => {
const allFiles: Array<{ path: string; name: string }> = [];
let currentPage = 1;
@@ -314,10 +334,7 @@ export async function GET(request: NextRequest) {
let hasMore = true;
while (hasMore) {
const response = await client.listDirectory(currentPath, currentPage, pageSize);
if (response.code !== 200) {
throw new Error('读取临时目录失败');
}
const response = await listTempDirectory(currentPath, currentPage, pageSize);
for (const item of response.data.content) {
const itemPath = `${currentPath}${currentPath.endsWith('/') ? '' : '/'}${item.name}`;