🐞 fix: Add shared drive into schema config

This commit is contained in:
mbaharip
2024-04-23 11:53:19 +07:00
parent 163ef9b5db
commit a7bbbc0927
3 changed files with 52 additions and 12 deletions
+34 -10
View File
@@ -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",
}),
});
+17 -2
View File
@@ -48,9 +48,24 @@ const config: z.input<typeof Schema_Config> = {
* 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')",
+1
View File
@@ -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(),