Merge branch 'release-2.14' into dev

This commit is contained in:
Laurent Cozic
2024-05-21 10:10:29 +01:00
3 changed files with 17 additions and 31 deletions

View File

@@ -1,9 +1,6 @@
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) {
@@ -100,14 +97,14 @@ class FileApiDriverDropbox {
}
}
async list(path, options) {
async list(path) {
let response = await this.api().exec('POST', 'files/list_folder', {
path: this.makePath_(path),
});
let output = this.metadataToStats_(response.entries);
while (response.has_more && !options?.firstPageOnly) {
while (response.has_more) {
response = await this.api().exec('POST', 'files/list_folder/continue', {
cursor: response.cursor,
});
@@ -117,7 +114,7 @@ class FileApiDriverDropbox {
return {
items: output,
hasMore: !!response.has_more,
hasMore: false,
context: { cursor: response.cursor },
};
}
@@ -135,12 +132,12 @@ class FileApiDriverDropbox {
// 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 fetchPath = (method, path) => {
const fetchPath = (method, path, extraHeaders) => {
return this.api().exec(
method,
'files/download',
null,
{ 'Dropbox-API-Arg': JSON.stringify({ path: this.makePath_(path) }) },
{ 'Dropbox-API-Arg': JSON.stringify({ path: this.makePath_(path) }), ...extraHeaders },
options,
);
};
@@ -149,27 +146,14 @@ class FileApiDriverDropbox {
if (!needsFetchWorkaround) {
response = await fetchPath('POST', path);
} else {
try {
response = await fetchPath('GET', path);
} 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('', { firstPageOnly: true });
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);
}
// Use a random If-None-Match value to prevent React Native from using the cache.
// Passing "cache: no-store" doesn't seem to be sufficient, so If-None-Match is set to a value
// that will never match the ETag.
//
// Something similar is done for WebDAV.
//
// See https://github.com/laurent22/joplin/issues/10396
response = await fetchPath('GET', path, { 'If-None-Match': `JoplinIgnore-${Math.floor(Math.random() * 100000)}` });
}
return response;
} catch (error) {

View File

@@ -775,6 +775,8 @@ function shimInit(options: ShimInitOptions = null) {
url: path,
// https://github.com/mozilla/pdf.js/issues/4244#issuecomment-1479534301
useSystemFonts: true,
// IMPORTANT: Set to false to mitigate CVE-2024-4367.
isEvalSupported: false,
});
return await loadingTask.promise;
};

View File

@@ -22,9 +22,9 @@ export default class PdfDocument {
this.rendererMutex = withTimeout(new Mutex(), 40 * 1000);
}
public loadDoc = async (url: string | Uint8Array) => {
public loadDoc = async (url: string) => {
this.url = url;
const loadingTask = pdfjsLib.getDocument(url);
const loadingTask = pdfjsLib.getDocument({ url, isEvalSupported: false });
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const pdfDocument: any = await loadingTask.promise;