From 163ef9b5db470c6ae3438bb2cd07fdb4e393a818 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:28:07 +0700 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=90=9E=20fix:=20teamdrive=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/actions.ts | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/app/actions.ts b/src/app/actions.ts index 1dc7f91..cd00fee 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -216,8 +216,12 @@ export async function CheckPassword( q: query.join(" and "), fields: "files(id, name, mimeType, parents)", pageSize: 1000, - supportsAllDrives: config.apiConfig.isTeamDrive, - includeItemsFromAllDrives: config.apiConfig.isTeamDrive, + ...(config.apiConfig.isTeamDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: config.apiConfig.rootFolder, + corpora: "drive", + }), }); // To save processing time, skip if password file not found @@ -353,8 +357,12 @@ export async function GetFiles({ orderBy: config.apiConfig.defaultOrder, pageSize: config.apiConfig.itemsPerPage, pageToken: pageToken, - supportsAllDrives: config.apiConfig.isTeamDrive, - includeItemsFromAllDrives: config.apiConfig.isTeamDrive, + ...(config.apiConfig.isTeamDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: config.apiConfig.rootFolder, + corpora: "drive", + }), }); const encryptedData: z.infer[] = []; @@ -471,8 +479,12 @@ export async function SearchFile( orderBy: "name_natural desc", pageSize: config.apiConfig.searchResult, pageToken: nextPageToken, - supportsAllDrives: config.apiConfig.isTeamDrive, - includeItemsFromAllDrives: config.apiConfig.isTeamDrive, + ...(config.apiConfig.isTeamDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: config.apiConfig.rootFolder, + corpora: "drive", + }), }); const encryptedData: z.infer[] = []; if (!data.data.files?.length) @@ -593,8 +605,12 @@ export async function GetReadme( orderBy: config.apiConfig.defaultOrder, pageSize: config.apiConfig.itemsPerPage, pageToken: undefined, - supportsAllDrives: config.apiConfig.isTeamDrive, - includeItemsFromAllDrives: config.apiConfig.isTeamDrive, + ...(config.apiConfig.isTeamDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: config.apiConfig.rootFolder, + corpora: "drive", + }), }); if (!data.files?.length) return null; @@ -634,8 +650,12 @@ export async function GetBanner( orderBy: config.apiConfig.defaultOrder, pageSize: config.apiConfig.itemsPerPage, pageToken: undefined, - supportsAllDrives: config.apiConfig.isTeamDrive, - includeItemsFromAllDrives: config.apiConfig.isTeamDrive, + ...(config.apiConfig.isTeamDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: config.apiConfig.rootFolder, + corpora: "drive", + }), }); if (!data.files?.length) return null; From a7bbbc09271f7aabe7305c95914abe928f794727 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:53:19 +0700 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Add=20shared=20drive?= =?UTF-8?q?=20into=20schema=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/actions.ts | 44 ++++++++++++++++++++++++++++--------- src/config/gIndex.config.ts | 19 ++++++++++++++-- src/schema.ts | 1 + 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/app/actions.ts b/src/app/actions.ts index cd00fee..3e6e22a 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -207,6 +207,10 @@ export async function CheckPassword( for (const path of paths) { ids.push(await decryptData(path.id)); } + let decryptedSharedDrive; + if (config.apiConfig.isTeamDrive && config.apiConfig.sharedDrive) { + decryptedSharedDrive = await decryptData(config.apiConfig.sharedDrive); + } const query: string[] = [ `name = '${config.apiConfig.specialFile.password}'`, `trashed = false`, @@ -216,10 +220,10 @@ export async function CheckPassword( q: query.join(" and "), fields: "files(id, name, mimeType, parents)", pageSize: 1000, - ...(config.apiConfig.isTeamDrive && { + ...(decryptedSharedDrive && { supportsAllDrives: true, includeItemsFromAllDrives: true, - driveId: config.apiConfig.rootFolder, + driveId: decryptedSharedDrive, corpora: "drive", }), }); @@ -342,6 +346,11 @@ export async function GetFiles({ if (id) decryptedId = await decryptData(id); else decryptedId = await decryptData(config.apiConfig.rootFolder); + let decryptedSharedDrive; + if (config.apiConfig.isTeamDrive && config.apiConfig.sharedDrive) { + decryptedSharedDrive = await decryptData(config.apiConfig.sharedDrive); + } + const filterName = config.apiConfig.hiddenFiles .map((item) => `not name = '${item}'`) .join(" and "); @@ -357,10 +366,10 @@ export async function GetFiles({ orderBy: config.apiConfig.defaultOrder, pageSize: config.apiConfig.itemsPerPage, pageToken: pageToken, - ...(config.apiConfig.isTeamDrive && { + ...(decryptedSharedDrive && { supportsAllDrives: true, includeItemsFromAllDrives: true, - driveId: config.apiConfig.rootFolder, + driveId: decryptedSharedDrive, corpora: "drive", }), }); @@ -466,6 +475,11 @@ export async function SearchFile( nextPageToken?: string; }> { try { + let decryptedSharedDrive; + if (config.apiConfig.isTeamDrive && config.apiConfig.sharedDrive) { + decryptedSharedDrive = await decryptData(config.apiConfig.sharedDrive); + } + const query: string[] = [ ...config.apiConfig.defaultQuery, `name contains '${keyword}'`, @@ -479,10 +493,10 @@ export async function SearchFile( orderBy: "name_natural desc", pageSize: config.apiConfig.searchResult, pageToken: nextPageToken, - ...(config.apiConfig.isTeamDrive && { + ...(decryptedSharedDrive && { supportsAllDrives: true, includeItemsFromAllDrives: true, - driveId: config.apiConfig.rootFolder, + driveId: decryptedSharedDrive, corpora: "drive", }), }); @@ -594,6 +608,11 @@ export async function GetReadme( if (encryptedId) decryptedId = await decryptData(encryptedId); else decryptedId = await decryptData(config.apiConfig.rootFolder); + let decryptedSharedDrive; + if (config.apiConfig.isTeamDrive && config.apiConfig.sharedDrive) { + decryptedSharedDrive = await decryptData(config.apiConfig.sharedDrive); + } + const query: string[] = [ ...config.apiConfig.defaultQuery, `name = '${config.apiConfig.specialFile.readme}'`, @@ -605,10 +624,10 @@ export async function GetReadme( orderBy: config.apiConfig.defaultOrder, pageSize: config.apiConfig.itemsPerPage, pageToken: undefined, - ...(config.apiConfig.isTeamDrive && { + ...(decryptedSharedDrive && { supportsAllDrives: true, includeItemsFromAllDrives: true, - driveId: config.apiConfig.rootFolder, + driveId: decryptedSharedDrive, corpora: "drive", }), }); @@ -639,6 +658,11 @@ export async function GetBanner( if (encryptedId) decryptedId = await decryptData(encryptedId); else decryptedId = await decryptData(config.apiConfig.rootFolder); + let decryptedSharedDrive; + if (config.apiConfig.isTeamDrive && config.apiConfig.sharedDrive) { + decryptedSharedDrive = await decryptData(config.apiConfig.sharedDrive); + } + const query: string[] = [ ...config.apiConfig.defaultQuery, `name contains '${config.apiConfig.specialFile.banner}'`, @@ -650,10 +674,10 @@ export async function GetBanner( orderBy: config.apiConfig.defaultOrder, pageSize: config.apiConfig.itemsPerPage, pageToken: undefined, - ...(config.apiConfig.isTeamDrive && { + ...(decryptedSharedDrive && { supportsAllDrives: true, includeItemsFromAllDrives: true, - driveId: config.apiConfig.rootFolder, + driveId: decryptedSharedDrive, corpora: "drive", }), }); diff --git a/src/config/gIndex.config.ts b/src/config/gIndex.config.ts index 8780264..ccd6912 100644 --- a/src/config/gIndex.config.ts +++ b/src/config/gIndex.config.ts @@ -48,9 +48,24 @@ const config: z.input = { * You need to create a new folder and share it with the service account * Then, copy the folder id and paste it here */ + // rootFolder: + // "c760fc0eae9990d4accbc2134af21e45a378d412af2c78020070a9f9ac548b98fe61c4f6be953a8d7be6a035e6f7766c", rootFolder: - "c760fc0eae9990d4accbc2134af21e45a378d412af2c78020070a9f9ac548b98fe61c4f6be953a8d7be6a035e6f7766c", - isTeamDrive: false, // Set this to true if you're using Team Drive + "b76c7c22083307a3aa99c28ab7cc69851d682f5a250d995679d4be5276cab16ab6c37f4d5b7ad1a9b93fb9bf768e752c", + /** + * If your root folder inside a shared drive, set this to true + * If not, set this to false + * + * You need to set the shared drive id to make it work + * Where to get the shared drive id? + * Go to your Shared Drives -> Click on the shared drive -> Copy the id from the url + * ex: https://drive.google.com/drive/u/0/folders/:shared_drive_id + * + * Then encrypt it using `/api/internal/encrypt?q=:shared_drive_id` route + */ + isTeamDrive: true, + sharedDrive: + "77bfa156c9c9d159112fcb0494ed8545bdaf7a3d567cd760ba2e2e2cd33fcbfc", defaultQuery: [ "trashed = false", "(not mimeType contains 'google-apps' or mimeType contains 'folder')", diff --git a/src/schema.ts b/src/schema.ts index 30f090a..ea3f7af 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -42,6 +42,7 @@ export const Schema_Config = z.object({ apiConfig: z.object({ rootFolder: z.string(), isTeamDrive: z.boolean(), + sharedDrive: z.string().optional(), defaultQuery: z.array(z.string()), defaultField: z.string(), defaultOrder: z.string(), From 5fb3c2ba0d8fad02c19dff2cf5bfcddf5a77a6e8 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:57:57 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Missing=20`supportAll?= =?UTF-8?q?Drives`=20when=20getting=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/[...rest]/page.tsx | 3 +++ src/app/actions.ts | 2 ++ src/app/api/download/[encryptedId]/route.ts | 1 + 3 files changed, 6 insertions(+) diff --git a/src/app/[...rest]/page.tsx b/src/app/[...rest]/page.tsx index 97baa60..ad3f6e9 100644 --- a/src/app/[...rest]/page.tsx +++ b/src/app/[...rest]/page.tsx @@ -11,6 +11,8 @@ import { decryptData } from "~/utils/encryptionHelper/hash"; import gdrive from "~/utils/gdriveInstance"; import { getFileType } from "~/utils/previewHelper"; +import config from "~/config/gIndex.config"; + import FileBrowser from "../@explorer"; import Header from "../@header"; import HeaderButton from "../@header.button"; @@ -102,6 +104,7 @@ export default async function RestPage({ params: { rest } }: Props) { const { data: file } = await gdrive.files.get({ fileId: await decryptData(encryptedId), fields: "mimeType, fileExtension", + supportsAllDrives: config.apiConfig.isTeamDrive, }); if (!file.mimeType?.includes("folder")) { promise.push(GetFile(encryptedId)); diff --git a/src/app/actions.ts b/src/app/actions.ts index 3e6e22a..f123aea 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -258,6 +258,7 @@ export async function CheckPassword( { fileId: protectedFolder.id as string, alt: "media", + supportsAllDrives: config.apiConfig.isTeamDrive, }, { responseType: "text", @@ -637,6 +638,7 @@ export async function GetReadme( { fileId: data.files[0].id as string, alt: "media", + supportsAllDrives: config.apiConfig.isTeamDrive, }, { responseType: "text", diff --git a/src/app/api/download/[encryptedId]/route.ts b/src/app/api/download/[encryptedId]/route.ts index bba8c4e..2b6c2b0 100644 --- a/src/app/api/download/[encryptedId]/route.ts +++ b/src/app/api/download/[encryptedId]/route.ts @@ -1,4 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; + import { CheckDownloadToken, CheckPassword, From 324e4a87178f2a180b669893407258677aadb069 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:19:24 +0700 Subject: [PATCH 4/6] Add @types/nprogress to dev deps, since it's causing build error --- package.json | 1 + src/app/[...rest]/page.tsx | 4 +++- src/app/actions.ts | 29 ++++++++++++++++++----------- yarn.lock | 3 ++- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 723b166..c9a1a5c 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "@types/jsonwebtoken": "^9.0.1", "@types/mime-types": "^2.1.1", "@types/node": "^20", + "@types/nprogress": "^0.2.3", "@types/react": "^18", "@types/react-dom": "^18", "@types/three": "^0.150.2", diff --git a/src/app/[...rest]/page.tsx b/src/app/[...rest]/page.tsx index ad3f6e9..8415381 100644 --- a/src/app/[...rest]/page.tsx +++ b/src/app/[...rest]/page.tsx @@ -86,7 +86,9 @@ export default async function RestPage({ params: { rest } }: Props) { if (!unlocked.success) { if (!unlocked.path) - throw new Error("No path returned from password checking"); + throw new Error( + `No path returned from password checking, ${unlocked.message}`, + ); return ( `'${id}' in parents`).join(" or ")})`, // Filter by paths id ]; - const { data: password } = await gdrive.files.list({ - q: query.join(" and "), - fields: "files(id, name, mimeType, parents)", - pageSize: 1000, - ...(decryptedSharedDrive && { - supportsAllDrives: true, - includeItemsFromAllDrives: true, - driveId: decryptedSharedDrive, - corpora: "drive", - }), - }); + const { data: password } = await gdrive.files + .list({ + q: query.join(" and "), + fields: "files(id, name, mimeType, parents)", + pageSize: 1000, + ...(decryptedSharedDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: decryptedSharedDrive, + corpora: "drive", + }), + }) + .catch((error) => { + console.error(error); + throw new Error("Failed to get password file"); + }); + + console.log(password); // To save processing time, skip if password file not found if (!password.files?.length) return { success: true }; diff --git a/yarn.lock b/yarn.lock index a459694..e6dc034 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1924,7 +1924,7 @@ __metadata: languageName: node linkType: hard -"@types/nprogress@npm:^0.2.2": +"@types/nprogress@npm:^0.2.2, @types/nprogress@npm:^0.2.3": version: 0.2.3 resolution: "@types/nprogress@npm:0.2.3" checksum: 10c0/cac0fe73aca79bc1472a1556f56303df72026f2fcd8dbe311fe84b1f46e454b9040c1e69223d94e3bf156a5986382170c52ebda19aa70f555f1b6855d8f744a6 @@ -6160,6 +6160,7 @@ __metadata: "@types/jsonwebtoken": "npm:^9.0.1" "@types/mime-types": "npm:^2.1.1" "@types/node": "npm:^20" + "@types/nprogress": "npm:^0.2.3" "@types/react": "npm:^18" "@types/react-dom": "npm:^18" "@types/three": "npm:^0.150.2" From 61587c245168349bef9b08e52ae114f8b4fa6728 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:37:16 +0700 Subject: [PATCH 5/6] Fix getting the files on the root folder --- src/app/actions.ts | 23 +++++++++++++++++------ src/config/gIndex.config.ts | 8 +++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/app/actions.ts b/src/app/actions.ts index 97ee949..45dbf77 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -120,6 +120,11 @@ export async function CheckPaths(paths: string[]): Promise< } > { try { + let decryptedSharedDrive; + if (config.apiConfig.isTeamDrive && config.apiConfig.sharedDrive) { + decryptedSharedDrive = await decryptData(config.apiConfig.sharedDrive); + } + const promises = []; for (const path of paths) { promises.push( @@ -127,8 +132,12 @@ export async function CheckPaths(paths: string[]): Promise< .list({ q: `name = '${decodeURIComponent(path)}' and trashed = false`, fields: "files(id, name, mimeType, parents)", - supportsAllDrives: config.apiConfig.isTeamDrive, - includeItemsFromAllDrives: config.apiConfig.isTeamDrive, + ...(decryptedSharedDrive && { + supportsAllDrives: true, + includeItemsFromAllDrives: true, + driveId: decryptedSharedDrive, + corpora: "drive", + }), }) .then(({ data }) => { if (!data.files?.length) return null; @@ -155,9 +164,13 @@ export async function CheckPaths(paths: string[]): Promise< const decryptedRootId = await decryptData(config.apiConfig.rootFolder); for (const [index, path] of data.entries()) { if (!valid) break; - // if first path, check if it's in root + if (index === 0) { - if (path?.data[0].parents === decryptedRootId) break; + if ( + path?.data[0].parents === decryptedRootId || + path?.data[0].parents === decryptedSharedDrive + ) + break; } else { if (path?.data[0].parents === data[index - 1]?.data[0].id) break; } @@ -233,8 +246,6 @@ export async function CheckPassword( throw new Error("Failed to get password file"); }); - console.log(password); - // To save processing time, skip if password file not found if (!password.files?.length) return { success: true }; diff --git a/src/config/gIndex.config.ts b/src/config/gIndex.config.ts index ccd6912..0b49789 100644 --- a/src/config/gIndex.config.ts +++ b/src/config/gIndex.config.ts @@ -48,10 +48,8 @@ const config: z.input = { * You need to create a new folder and share it with the service account * Then, copy the folder id and paste it here */ - // rootFolder: - // "c760fc0eae9990d4accbc2134af21e45a378d412af2c78020070a9f9ac548b98fe61c4f6be953a8d7be6a035e6f7766c", rootFolder: - "b76c7c22083307a3aa99c28ab7cc69851d682f5a250d995679d4be5276cab16ab6c37f4d5b7ad1a9b93fb9bf768e752c", + "c760fc0eae9990d4accbc2134af21e45a378d412af2c78020070a9f9ac548b98fe61c4f6be953a8d7be6a035e6f7766c", /** * If your root folder inside a shared drive, set this to true * If not, set this to false @@ -64,8 +62,8 @@ const config: z.input = { * Then encrypt it using `/api/internal/encrypt?q=:shared_drive_id` route */ isTeamDrive: true, - sharedDrive: - "77bfa156c9c9d159112fcb0494ed8545bdaf7a3d567cd760ba2e2e2cd33fcbfc", + sharedDrive: undefined, + defaultQuery: [ "trashed = false", "(not mimeType contains 'google-apps' or mimeType contains 'folder')", From 74b066ee48249d515a0e09eb60d437e51a73670a Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:42:28 +0700 Subject: [PATCH 6/6] Test shared on deployment --- src/config/gIndex.config.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/config/gIndex.config.ts b/src/config/gIndex.config.ts index 0b49789..b46f114 100644 --- a/src/config/gIndex.config.ts +++ b/src/config/gIndex.config.ts @@ -6,7 +6,7 @@ const config: z.input = { * If possible, please don't change this value * Even if you're creating a PR, just let me change it myself */ - version: "2.0.1", + version: "2.0.2", /** * Base path of the app, used for generating links * @@ -48,8 +48,10 @@ const config: z.input = { * You need to create a new folder and share it with the service account * Then, copy the folder id and paste it here */ + // rootFolder: + // "c760fc0eae9990d4accbc2134af21e45a378d412af2c78020070a9f9ac548b98fe61c4f6be953a8d7be6a035e6f7766c", rootFolder: - "c760fc0eae9990d4accbc2134af21e45a378d412af2c78020070a9f9ac548b98fe61c4f6be953a8d7be6a035e6f7766c", + "b76c7c22083307a3aa99c28ab7cc69851d682f5a250d995679d4be5276cab16ab6c37f4d5b7ad1a9b93fb9bf768e752c", /** * If your root folder inside a shared drive, set this to true * If not, set this to false @@ -62,7 +64,8 @@ const config: z.input = { * Then encrypt it using `/api/internal/encrypt?q=:shared_drive_id` route */ isTeamDrive: true, - sharedDrive: undefined, + sharedDrive: + "77bfa156c9c9d159112fcb0494ed8545bdaf7a3d567cd760ba2e2e2cd33fcbfc", defaultQuery: [ "trashed = false",