Skip to content

Commit

Permalink
parrallelize
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Nov 22, 2023
1 parent dc9f91d commit de15b38
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions connectors/src/connectors/google_drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,44 @@ export async function createGoogleDriveConnector(
const driveClient = await getDriveClient(nangoConnectionId);

// Sanity checks to confirm we have sufficient permissions
const sanityCheckAbout = await driveClient.about.get({ fields: "*" });
if (sanityCheckAbout.status !== 200) {
throw new Error(
`Could not get google drive info. Error message: ${
sanityCheckAbout.statusText || "unknown"
}`
);
}
const sanityCheckFilesGet = await driveClient.files.get({
fileId: "root",
});
if (sanityCheckFilesGet.status !== 200) {
throw new Error(
`Could not call google drive files get. Error message: ${
sanityCheckFilesGet.statusText || "unknown"
}`
);
}
const sanityCheckFilesList = await driveClient.drives.list({
pageSize: 10,
fields: "nextPageToken, drives(id, name)",
});
if (sanityCheckFilesList.status !== 200) {
throw new Error(
`Could not call google drive files list. Error message: ${
sanityCheckFilesList.statusText || "unknown"
}`
);
}
const getAbout = () => driveClient.about.get({ fields: "*" });
const getFiles = () => driveClient.files.get({ fileId: "root" });
const listFiles = () =>
driveClient.drives.list({
pageSize: 10,
fields: "nextPageToken, drives(id, name)",
});
Promise.all([getAbout(), getFiles(), listFiles()])
.then(
([sanityCheckAbout, sanityCheckFilesGet, sanityCheckFilesList]) => {
if (sanityCheckAbout.status !== 200) {
throw new Error(
`Could not get google drive info. Error message: ${
sanityCheckAbout.statusText || "unknown"
}`
);
}
if (sanityCheckFilesGet.status !== 200) {
throw new Error(
`Could not call google drive files get. Error message: ${
sanityCheckFilesGet.statusText || "unknown"
}`
);
}
if (sanityCheckFilesList.status !== 200) {
throw new Error(
`Could not call google drive files list. Error message: ${
sanityCheckFilesList.statusText || "unknown"
}`
);
}
}
)
.catch(() => {
throw new Error(
"Error trying to check sufficient permissions from Google."
);
});

const connector = await Connector.create(
{
Expand Down

0 comments on commit de15b38

Please sign in to comment.