这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/actions/google/drive/google_drive.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export declare class GoogleDriveAction extends Hub.OAuthAction {
oauthCheck(request: Hub.ActionRequest): Promise<boolean>;
oauth2Client(redirectUri: string | undefined): OAuth2Client;
sendData(filename: string, request: Hub.ActionRequest, drive: Drive): Promise<GaxiosResponse<drive_v3.Schema$File>>;
getDrives(drive: Drive): Promise<{
name: string;
label: string;
}[]>;
getDrives(drive: Drive, accumulatedFolders: drive_v3.Schema$Drive[], response: GaxiosResponse<drive_v3.Schema$DriveList>): Promise<drive_v3.Schema$Drive[]>;
getMimeType(request: Hub.ActionRequest): string | undefined;
sanitizeGaxiosError(err: any): void;
protected getAccessTokenCredentialsFromCode(redirect: string, code: string): Promise<Credentials>;
Expand Down
22 changes: 12 additions & 10 deletions lib/actions/google/drive/google_drive.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class GoogleDriveAction extends Hub.OAuthAction {
throw "Domain Verification Failed";
});
const drive = await this.driveClientFromRequest(stateJson.redirect, stateJson.tokens);
const driveSelections = await this.getDrives(drive);
const paginatedDrives = await this.getDrives(drive, [], await drive.drives.list({ pageSize: 50 }));
const driveSelections = paginatedDrives.filter((_drive) => (!(_drive.id === undefined) && !(_drive.name === undefined)))
.map((folder) => ({ name: folder.id, label: folder.name }));
driveSelections.unshift({ name: "mydrive", label: "My Drive" });
form.fields.push({
description: "Google Drive where your file will be saved",
label: "Select Drive to save file",
Expand Down Expand Up @@ -291,15 +294,14 @@ class GoogleDriveAction extends Hub.OAuthAction {
});
});
}
async getDrives(drive) {
const driveList = [{ name: "mydrive", label: "My Drive" }];
const drives = await drive.drives.list({
pageSize: 50,
});
if (drives.data.drives) {
drives.data.drives.forEach((d) => {
driveList.push({ name: d.id, label: d.name });
});
async getDrives(drive, accumulatedFolders, response) {
const driveList = accumulatedFolders.concat(response.data.drives);
if (response.data.nextPageToken) {
const pageOptions = {
pageSize: 50,
pageToken: response.data.nextPageToken,
};
return this.getDrives(drive, driveList, await drive.drives.list(pageOptions));
}
return driveList;
}
Expand Down
28 changes: 18 additions & 10 deletions src/actions/google/drive/google_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ export class GoogleDriveAction extends Hub.OAuthAction {

const drive = await this.driveClientFromRequest(stateJson.redirect, stateJson.tokens)

const driveSelections = await this.getDrives(drive)
const paginatedDrives = await this.getDrives(drive, [], await drive.drives.list({pageSize: 50}))
const driveSelections = paginatedDrives.filter((_drive) => (
!(_drive.id === undefined) && !(_drive.name === undefined)))
.map((folder) => ({name: folder.id!, label: folder.name!}))
driveSelections.unshift({name: "mydrive", label: "My Drive"})

form.fields.push({
description: "Google Drive where your file will be saved",
label: "Select Drive to save file",
Expand Down Expand Up @@ -338,16 +343,19 @@ export class GoogleDriveAction extends Hub.OAuthAction {
})
}

async getDrives(drive: Drive) {
const driveList = [{name: "mydrive", label: "My Drive"}]
const drives: GaxiosResponse<drive_v3.Schema$DriveList> = await drive.drives.list({
pageSize: 50,
})
if (drives.data.drives) {
drives.data.drives.forEach((d) => {
driveList.push({name: d.id!, label: d.name!})
})
async getDrives(drive: Drive,
accumulatedFolders: drive_v3.Schema$Drive[],
response: GaxiosResponse<drive_v3.Schema$DriveList>): Promise<drive_v3.Schema$Drive[]> {
const driveList = accumulatedFolders.concat(response.data.drives!)

if (response.data.nextPageToken) {
const pageOptions = {
pageSize: 50,
pageToken: response.data.nextPageToken,
}
return this.getDrives(drive, driveList, await drive.drives.list(pageOptions))
}

return driveList
}

Expand Down