diff --git a/src/lib/adapters/GoogleDrive.ts b/src/lib/adapters/GoogleDrive.ts index dab00157f1..63572e5673 100644 --- a/src/lib/adapters/GoogleDrive.ts +++ b/src/lib/adapters/GoogleDrive.ts @@ -214,7 +214,7 @@ export default class GoogleDriveAdapter extends CachingAdapter { this.accessToken = await this.getAccessToken(this.server.refreshToken) - const fileList = await this.listFiles(`name = '${this.server.bookmark_file}'`) + const fileList = await this.listFiles(`name = '${this.server.bookmark_file}'`, 10) const file = fileList.files.filter(file => !file.trashed)[0] if (file) { this.fileId = file.id @@ -404,8 +404,8 @@ export default class GoogleDriveAdapter extends CachingAdapter { } } - async listFiles(query: string) : Promise { - const res = await this.request('GET', this.getUrl() + '/files?corpora=user&q=' + encodeURIComponent(query)) + async listFiles(query: string, limit = 1) : Promise { + const res = await this.request('GET', this.getUrl() + `/files?corpora=user&q=${encodeURIComponent(query)}&orderBy=modifiedTime%20desc&fields=files(id%2Cname%2Ctrashed)&pageSize=${limit}`) return res.json() } diff --git a/src/test/test.js b/src/test/test.js index 63675f83a8..fd921c962c 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -273,10 +273,13 @@ describe('Floccus', function() { } if (ACCOUNT_DATA.type === 'google-drive') { const fileList = await account.server.listFiles('name = ' + "'" + account.server.bookmark_file + "'") - const file = fileList.files[0] - if (file) { + const files = fileList.files + for (const file of files) { await account.server.deleteFile(file.id) } + if (files.length > 1) { + throw new Error('Google Drive sync left more than one file behind') + } } await account.delete() }) @@ -3279,10 +3282,13 @@ describe('Floccus', function() { } if (ACCOUNT_DATA.type === 'google-drive') { const fileList = await account1.server.listFiles('name = ' + "'" + account1.server.bookmark_file + "'") - const file = fileList.files[0] - if (file) { + const files = fileList.files + for (const file of files) { await account1.server.deleteFile(file.id) } + if (files.length > 1) { + throw new Error('Google Drive sync left more than one file behind') + } } try { await browser.bookmarks.removeTree(account1.getData().localRoot) @@ -4704,10 +4710,13 @@ describe('Floccus', function() { } if (ACCOUNT_DATA.type === 'google-drive') { const fileList = await account.server.listFiles('name = ' + "'" + account.server.bookmark_file + "'") - const file = fileList.files[0] - if (file) { + const files = fileList.files + for (const file of files) { await account.server.deleteFile(file.id) } + if (files.length > 1) { + throw new Error('Google Drive sync left more than one file behind') + } } await account.delete() }) @@ -5047,10 +5056,13 @@ describe('Floccus', function() { } if (ACCOUNT_DATA.type === 'google-drive') { const fileList = await account1.server.listFiles('name = ' + "'" + account1.server.bookmark_file + "'") - const file = fileList.files[0] - if (file) { + const files = fileList.files + for (const file of files) { await account1.server.deleteFile(file.id) } + if (files.length > 1) { + throw new Error('Google Drive sync left more than one file behind') + } } await account1.delete() await browser.bookmarks.removeTree(account2.getData().localRoot)