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