Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GoogleDrive): Sort files by modified date #1718

Merged
merged 2 commits into from
Sep 10, 2024
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
6 changes: 3 additions & 3 deletions src/lib/adapters/GoogleDrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -404,8 +404,8 @@ export default class GoogleDriveAdapter extends CachingAdapter {
}
}

async listFiles(query: string) : Promise<any> {
const res = await this.request('GET', this.getUrl() + '/files?corpora=user&q=' + encodeURIComponent(query))
async listFiles(query: string, limit = 1) : Promise<any> {
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()
}

Expand Down
28 changes: 20 additions & 8 deletions src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
})
Expand Down Expand Up @@ -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)
Expand Down
Loading