Add missing size field causing timeout when downloading large files

This commit is contained in:
mbaharip
2024-04-12 05:35:19 +07:00
parent 43b108cf47
commit c5434fe9c4
+4 -14
View File
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { import {
CheckDownloadToken, CheckDownloadToken,
CheckPassword, CheckPassword,
@@ -50,7 +51,7 @@ If you've already entered the password, please make sure your browser is not blo
const _filePaths = RedirectSearchFile(encryptedId); const _filePaths = RedirectSearchFile(encryptedId);
const _fileMeta = gdrive.files.get({ const _fileMeta = gdrive.files.get({
fileId: decryptedId, fileId: decryptedId,
fields: "id, name, mimeType, fileExtension, webContentLink", fields: "id, name, mimeType, size, fileExtension, webContentLink",
supportsAllDrives: config.apiConfig.isTeamDrive, supportsAllDrives: config.apiConfig.isTeamDrive,
}); });
const _fileContent = gdrive.files.get( const _fileContent = gdrive.files.get(
@@ -69,6 +70,7 @@ If you've already entered the password, please make sure your browser is not blo
_fileContent, _fileContent,
_filePaths, _filePaths,
]); ]);
if (!config.apiConfig.allowDownloadProtectedFile) { if (!config.apiConfig.allowDownloadProtectedFile) {
const checkPath = await CheckPaths(filePaths.split("/")); const checkPath = await CheckPaths(filePaths.split("/"));
if (!checkPath.success) throw new Error("File not found"); if (!checkPath.success) throw new Error("File not found");
@@ -107,6 +109,7 @@ If you've already entered the password, please make sure your browser is not blo
config.apiConfig.maxFileSize && config.apiConfig.maxFileSize &&
fileSize > config.apiConfig.maxFileSize fileSize > config.apiConfig.maxFileSize
) { ) {
console.log("File size is too large, redirecting to webContentLink");
return NextResponse.redirect(fileMeta.data.webContentLink, { return NextResponse.redirect(fileMeta.data.webContentLink, {
status: 302, status: 302,
headers: { headers: {
@@ -141,19 +144,6 @@ If you've already entered the password, please make sure your browser is not blo
"Cache-Control": config.cacheControl, "Cache-Control": config.cacheControl,
}, },
}); });
// const data = await GetFile(encryptedId);
// if (data.mimeType?.includes("folder"))
// throw new Error("Can't download folder");
// if (!data.encryptedWebContentLink)
// throw new Error("No download link found");
// const decryptedWebContent = await decryptData(data.encryptedWebContentLink);
// return new NextResponse(null, {
// status: 302,
// headers: {
// Location: decryptedWebContent,
// },
// });
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
console.error(e.message); console.error(e.message);