mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
parent
a1a06dd7d0
commit
d6480e50d2
@ -130,16 +130,42 @@ class FileApiDriverDropbox {
|
||||
// support POST requests with an empty body:
|
||||
//
|
||||
// https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-1017-quot-cannot-parse-response-quot/td-p/589595
|
||||
const needsFetchWorkaround = shim.mobilePlatform() === 'ios';
|
||||
|
||||
const response = await this.api().exec(
|
||||
'GET',
|
||||
'files/download',
|
||||
null,
|
||||
{
|
||||
'Dropbox-API-Arg': JSON.stringify({ path: this.makePath_(path) }),
|
||||
},
|
||||
options,
|
||||
);
|
||||
const fetchPath = (method, path) => {
|
||||
return this.api().exec(
|
||||
method,
|
||||
'files/download',
|
||||
null,
|
||||
{ 'Dropbox-API-Arg': JSON.stringify({ path: this.makePath_(path) }) },
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
let response;
|
||||
if (!needsFetchWorkaround) {
|
||||
response = await fetchPath('POST', path);
|
||||
} else {
|
||||
try {
|
||||
response = await fetchPath('GET', path);
|
||||
} catch (_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 files = items.filter(item => !item.isDir && item.path !== path);
|
||||
|
||||
if (files.length > 0) {
|
||||
await fetchPath('GET', files[0].path);
|
||||
}
|
||||
|
||||
response = await fetchPath('GET', path);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (this.hasErrorCode_(error, 'not_found')) {
|
||||
|
Loading…
Reference in New Issue
Block a user