Skip to content

Commit

Permalink
Get next page if end of files not reached
Browse files Browse the repository at this point in the history
  • Loading branch information
calculuschild committed May 9, 2023
1 parent b2ebf72 commit 0e1b30e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions server/googleActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,31 @@ const GoogleActions = {
listGoogleBrews : async (auth)=>{
const drive = googleDrive.drive({ version: 'v3', auth });

const obj = await drive.files.list({
pageSize : 1000,
fields : 'nextPageToken, files(id, name, description, createdTime, modifiedTime, properties)',
q : 'mimeType != \'application/vnd.google-apps.folder\' and trashed = false'
})
.catch((err)=>{
console.log(`Error Listing Google Brews`);
console.error(err);
throw (err);
//TODO: Should break out here, but continues on for some reason.
});
const fileList = [];
let NextPageToken = "";

do {
const obj = await drive.files.list({
pageSize : 1000,
pageToken : NextPageToken || "",
fields : 'nextPageToken, files(id, name, description, createdTime, modifiedTime, properties)',
q : 'mimeType != \'application/vnd.google-apps.folder\' and trashed = false'
})
.catch((err)=>{
console.log(`Error Listing Google Brews`);
console.error(err);
throw (err);
//TODO: Should break out here, but continues on for some reason.
});
fileList.push(...obj.data.files);
NextPageToken = obj.data.nextPageToken;
} while (NextPageToken);

if(!obj.data.files.length) {
if(!fileList.length) {
console.log('No files found.');
}

const brews = obj.data.files.map((file)=>{
const brews = fileList.map((file)=>{
return {
text : '',
shareId : file.properties.shareId,
Expand Down

0 comments on commit 0e1b30e

Please sign in to comment.