修复夸克直链播放重复转存相同文件
This commit is contained in:
@@ -3936,7 +3936,7 @@ const NetDiskConfigComponent = ({
|
|||||||
const [enabled, setEnabled] = useState(false);
|
const [enabled, setEnabled] = useState(false);
|
||||||
const [cookie, setCookie] = useState('');
|
const [cookie, setCookie] = useState('');
|
||||||
const [savePath, setSavePath] = useState('/');
|
const [savePath, setSavePath] = useState('/');
|
||||||
const [quarkPlayMode, setQuarkPlayMode] = useState<'direct_first' | 'transcode_first'>('direct_first');
|
const [quarkPlayMode, setQuarkPlayMode] = useState<'direct_first' | 'transcode_first'>('transcode_first');
|
||||||
const [mobileEnabled, setMobileEnabled] = useState(false);
|
const [mobileEnabled, setMobileEnabled] = useState(false);
|
||||||
const [mobileAuthorization, setMobileAuthorization] = useState('');
|
const [mobileAuthorization, setMobileAuthorization] = useState('');
|
||||||
const [baiduEnabled, setBaiduEnabled] = useState(false);
|
const [baiduEnabled, setBaiduEnabled] = useState(false);
|
||||||
@@ -3960,7 +3960,7 @@ const NetDiskConfigComponent = ({
|
|||||||
setEnabled(quark?.Enabled || false);
|
setEnabled(quark?.Enabled || false);
|
||||||
setCookie(quark?.Cookie || '');
|
setCookie(quark?.Cookie || '');
|
||||||
setSavePath(quark?.SavePath || '/');
|
setSavePath(quark?.SavePath || '/');
|
||||||
setQuarkPlayMode(quark?.PlayMode === 'transcode_first' ? 'transcode_first' : 'direct_first');
|
setQuarkPlayMode(quark?.PlayMode === 'direct_first' ? 'direct_first' : 'transcode_first');
|
||||||
setMobileEnabled(mobile?.Enabled || false);
|
setMobileEnabled(mobile?.Enabled || false);
|
||||||
setMobileAuthorization(mobile?.Authorization || '');
|
setMobileAuthorization(mobile?.Authorization || '');
|
||||||
setBaiduEnabled(config?.NetDiskConfig?.Baidu?.Enabled || false);
|
setBaiduEnabled(config?.NetDiskConfig?.Baidu?.Enabled || false);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export async function POST(request: NextRequest) {
|
|||||||
Enabled: Boolean(Quark?.Enabled),
|
Enabled: Boolean(Quark?.Enabled),
|
||||||
Cookie: normalizedCookie,
|
Cookie: normalizedCookie,
|
||||||
SavePath: Quark?.SavePath || '/',
|
SavePath: Quark?.SavePath || '/',
|
||||||
PlayMode: Quark?.PlayMode === 'transcode_first' ? 'transcode_first' : 'direct_first',
|
PlayMode: Quark?.PlayMode === 'direct_first' ? 'direct_first' : 'transcode_first',
|
||||||
};
|
};
|
||||||
adminConfig.NetDiskConfig.Mobile = {
|
adminConfig.NetDiskConfig.Mobile = {
|
||||||
Enabled: Boolean(Mobile?.Enabled),
|
Enabled: Boolean(Mobile?.Enabled),
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ export async function GET(request: NextRequest) {
|
|||||||
shareId: session.shareId,
|
shareId: session.shareId,
|
||||||
shareToken: session.shareToken,
|
shareToken: session.shareToken,
|
||||||
fileId: file.fid,
|
fileId: file.fid,
|
||||||
|
fileName: file.name,
|
||||||
|
size: file.size,
|
||||||
shareFileToken: file.shareFidToken,
|
shareFileToken: file.shareFidToken,
|
||||||
playFolderFid: session.playFolderFid,
|
playFolderFid: session.playFolderFid,
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-3
@@ -724,7 +724,7 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
|||||||
Enabled: false,
|
Enabled: false,
|
||||||
Cookie: '',
|
Cookie: '',
|
||||||
SavePath: '/',
|
SavePath: '/',
|
||||||
PlayMode: 'direct_first',
|
PlayMode: 'transcode_first',
|
||||||
},
|
},
|
||||||
Mobile: {
|
Mobile: {
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
@@ -762,11 +762,11 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
|||||||
Enabled: false,
|
Enabled: false,
|
||||||
Cookie: '',
|
Cookie: '',
|
||||||
SavePath: '/',
|
SavePath: '/',
|
||||||
PlayMode: 'direct_first',
|
PlayMode: 'transcode_first',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!adminConfig.NetDiskConfig.Quark.PlayMode) {
|
if (!adminConfig.NetDiskConfig.Quark.PlayMode) {
|
||||||
adminConfig.NetDiskConfig.Quark.PlayMode = 'direct_first';
|
adminConfig.NetDiskConfig.Quark.PlayMode = 'transcode_first';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!adminConfig.NetDiskConfig.Mobile) {
|
if (!adminConfig.NetDiskConfig.Mobile) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export async function resolveQuarkSession(id: string) {
|
|||||||
throw new Error('夸克网盘播放信息恢复失败');
|
throw new Error('夸克网盘播放信息恢复失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
const playMode: QuarkPlayMode = quarkConfig.PlayMode === 'transcode_first' ? 'transcode_first' : 'direct_first';
|
const playMode: QuarkPlayMode = quarkConfig.PlayMode === 'direct_first' ? 'direct_first' : 'transcode_first';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
session,
|
session,
|
||||||
|
|||||||
@@ -298,6 +298,27 @@ async function findDirectoryByName(
|
|||||||
) || null;
|
) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function findDriveFileInFolder(
|
||||||
|
cookie: string,
|
||||||
|
parentFid: string,
|
||||||
|
input: { fileName?: string; size?: number }
|
||||||
|
): Promise<any | null> {
|
||||||
|
const fileName = input.fileName?.trim();
|
||||||
|
if (!fileName) return null;
|
||||||
|
|
||||||
|
const items = await fetchAllDriveFolderItems(cookie, parentFid);
|
||||||
|
return items.find((item: any) => {
|
||||||
|
const isDir = Boolean(item.dir || item.is_dir || item.file_type === 0);
|
||||||
|
if (isDir) return false;
|
||||||
|
const itemName = String(item.file_name || item.name || '');
|
||||||
|
if (itemName !== fileName) return false;
|
||||||
|
if (input.size && Number(item.size || 0) > 0) {
|
||||||
|
return Number(item.size || 0) === input.size;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}) || null;
|
||||||
|
}
|
||||||
|
|
||||||
export async function validateQuarkCookieReadable(cookie: string): Promise<void> {
|
export async function validateQuarkCookieReadable(cookie: string): Promise<void> {
|
||||||
const safeCookie = assertQuarkCookieHeaderSafe(cookie);
|
const safeCookie = assertQuarkCookieHeaderSafe(cookie);
|
||||||
await fetchDriveFolderItems(safeCookie, '0');
|
await fetchDriveFolderItems(safeCookie, '0');
|
||||||
@@ -626,11 +647,22 @@ export async function saveQuarkShareFile(
|
|||||||
shareId: string;
|
shareId: string;
|
||||||
shareToken: string;
|
shareToken: string;
|
||||||
fileId: string;
|
fileId: string;
|
||||||
|
fileName?: string;
|
||||||
|
size?: number;
|
||||||
shareFileToken?: string;
|
shareFileToken?: string;
|
||||||
playFolderFid: string;
|
playFolderFid: string;
|
||||||
}
|
}
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const safeCookie = assertQuarkCookieHeaderSafe(cookie);
|
const safeCookie = assertQuarkCookieHeaderSafe(cookie);
|
||||||
|
|
||||||
|
const existedFile = await findDriveFileInFolder(safeCookie, input.playFolderFid, {
|
||||||
|
fileName: input.fileName,
|
||||||
|
size: input.size,
|
||||||
|
});
|
||||||
|
if (existedFile) {
|
||||||
|
return String(existedFile.fid || existedFile.file_id);
|
||||||
|
}
|
||||||
|
|
||||||
const taskId = await submitSaveTask(
|
const taskId = await submitSaveTask(
|
||||||
safeCookie,
|
safeCookie,
|
||||||
{ pwdId: input.shareId, passcode: '' },
|
{ pwdId: input.shareId, passcode: '' },
|
||||||
@@ -639,8 +671,9 @@ export async function saveQuarkShareFile(
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
fid: input.fileId,
|
fid: input.fileId,
|
||||||
fileName: '',
|
fileName: input.fileName || '',
|
||||||
dir: false,
|
dir: false,
|
||||||
|
size: input.size,
|
||||||
shareFidToken: input.shareFileToken,
|
shareFidToken: input.shareFileToken,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -668,6 +701,14 @@ export async function saveQuarkShareFile(
|
|||||||
return String(saveAsTopFids[0]);
|
return String(saveAsTopFids[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const savedFile = await findDriveFileInFolder(safeCookie, input.playFolderFid, {
|
||||||
|
fileName: input.fileName,
|
||||||
|
size: input.size,
|
||||||
|
});
|
||||||
|
if (savedFile) {
|
||||||
|
return String(savedFile.fid || savedFile.file_id);
|
||||||
|
}
|
||||||
|
|
||||||
const status = data?.data?.status;
|
const status = data?.data?.status;
|
||||||
if (status === -1 || status === 'failed' || data?.data?.err_code) {
|
if (status === -1 || status === 'failed' || data?.data?.err_code) {
|
||||||
throw new Error(data?.data?.message || data?.data?.err_msg || '夸克任务执行失败');
|
throw new Error(data?.data?.message || data?.data?.err_msg || '夸克任务执行失败');
|
||||||
@@ -686,7 +727,7 @@ export async function saveQuarkShareFile(
|
|||||||
export async function getQuarkPlayUrls(
|
export async function getQuarkPlayUrls(
|
||||||
cookie: string,
|
cookie: string,
|
||||||
savedFileId: string,
|
savedFileId: string,
|
||||||
playMode: QuarkPlayMode = 'direct_first'
|
playMode: QuarkPlayMode = 'transcode_first'
|
||||||
): Promise<Array<{ name: string; url: string; priority: number }>> {
|
): Promise<Array<{ name: string; url: string; priority: number }>> {
|
||||||
const safeCookie = assertQuarkCookieHeaderSafe(cookie);
|
const safeCookie = assertQuarkCookieHeaderSafe(cookie);
|
||||||
const headers = getHeaders(safeCookie);
|
const headers = getHeaders(safeCookie);
|
||||||
|
|||||||
Reference in New Issue
Block a user