1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Fixed resource error handling

This commit is contained in:
Laurent Cozic 2021-05-04 16:00:40 +02:00
parent f76f99b423
commit 606a64f49c

View File

@ -5,7 +5,6 @@ import BaseModel from '@joplin/lib/BaseModel';
import Resource from '@joplin/lib/models/Resource';
const bridge = require('electron').remote.require('./bridge').default;
import ResourceFetcher from '@joplin/lib/services/ResourceFetcher';
import { reg } from '@joplin/lib/registry';
import htmlUtils from '@joplin/lib/htmlUtils';
import Logger from '@joplin/lib/Logger';
const joplinRendererUtils = require('@joplin/renderer').utils;
@ -14,6 +13,8 @@ const mimeUtils = require('@joplin/lib/mime-utils.js').mime;
const md5 = require('md5');
const path = require('path');
const logger = Logger.create('resourceHandling');
export async function handleResourceDownloadMode(noteBody: string) {
if (noteBody && Setting.value('sync.resourceDownloadMode') === 'auto') {
const resourceIds = await Note.linkedResourceIds(noteBody);
@ -72,21 +73,21 @@ export async function commandAttachFileToBody(body: string, filePaths: string[]
for (let i = 0; i < filePaths.length; i++) {
const filePath = filePaths[i];
try {
reg.logger().info(`Attaching ${filePath}`);
logger.info(`Attaching ${filePath}`);
const newBody = await shim.attachFileToNoteBody(body, filePath, options.position, {
createFileURL: options.createFileURL,
resizeLargeImages: 'ask',
});
if (!newBody) {
reg.logger().info('File attachment was cancelled');
logger.info('File attachment was cancelled');
return null;
}
body = newBody;
reg.logger().info('File was attached.');
logger.info('File was attached.');
} catch (error) {
reg.logger().error(error);
logger.error(error);
bridge().showErrorMessageBox(error.message);
}
}
@ -157,9 +158,8 @@ export async function processPastedHtml(html: string) {
await shim.fsDriver().remove(filePath);
mappedResources[imageSrc] = `file://${Resource.fullPath(createdResource)}`;
}
} catch (err) {
const logger = Logger.create('resourceHandling');
logger.warn(`Error creating a resource for ${imageSrc}.`, err);
} catch (error) {
logger.warn(`Error creating a resource for ${imageSrc}.`, error);
mappedResources[imageSrc] = imageSrc;
}
}