Skip to content

Commit

Permalink
Merge branch 'release-2.14' of github.com:laurent22/joplin into relea…
Browse files Browse the repository at this point in the history
…se-2.14
  • Loading branch information
laurent22 committed May 8, 2024
2 parents 966fe38 + 3042e61 commit fb345b1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/lib/file-api-driver-dropbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const time = require('./time').default;
const shim = require('./shim').default;
const JoplinError = require('./JoplinError').default;
const Logger = require('@joplin/utils/Logger').default;

const logger = Logger.create('file-api-driver-dropbox');

class FileApiDriverDropbox {
constructor(api) {
Expand Down Expand Up @@ -97,14 +100,14 @@ class FileApiDriverDropbox {
}
}

async list(path) {
async list(path, options) {
let response = await this.api().exec('POST', 'files/list_folder', {
path: this.makePath_(path),
});

let output = this.metadataToStats_(response.entries);

while (response.has_more) {
while (response.has_more && !options?.firstPageOnly) {
response = await this.api().exec('POST', 'files/list_folder/continue', {
cursor: response.cursor,
});
Expand All @@ -114,7 +117,7 @@ class FileApiDriverDropbox {

return {
items: output,
hasMore: false,
hasMore: !!response.has_more,
context: { cursor: response.cursor },
};
}
Expand Down Expand Up @@ -148,15 +151,16 @@ class FileApiDriverDropbox {
} else {
try {
response = await fetchPath('GET', path);
} catch (_error) {
} catch (error) {
logger.warn('Request to files/download failed. Retrying with workaround. Error: ', error);
// May 2024: Sending a GET request to files/download sometimes fails
// until another file is requested. Because POST requests with empty bodies don't work on iOS,
// we send a request for a different file, then re-request the original.
//
// See https://github.com/laurent22/joplin/issues/10396

// This workaround requires that the file we request exist.
const { items } = await this.list();
const { items } = await this.list('', { firstPageOnly: true });
const files = items.filter(item => !item.isDir && item.path !== path);

if (files.length > 0) {
Expand Down

0 comments on commit fb345b1

Please sign in to comment.