mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-05 12:50:29 +02:00
Fixed handling of resource paths
This commit is contained in:
parent
e43e3c198a
commit
53eba3f062
@ -223,6 +223,8 @@ describe('models_Note', function() {
|
|||||||
const resourceDir = Setting.value('resourceDir');
|
const resourceDir = Setting.value('resourceDir');
|
||||||
const r1 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
const r1 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
||||||
const r2 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
const r2 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
||||||
|
const t1 = r1.updated_time;
|
||||||
|
const t2 = r2.updated_time;
|
||||||
|
|
||||||
const testCases = [
|
const testCases = [
|
||||||
[
|
[
|
||||||
@ -248,12 +250,12 @@ describe('models_Note', function() {
|
|||||||
[
|
[
|
||||||
true,
|
true,
|
||||||
`![](:/${r1.id})`,
|
`![](:/${r1.id})`,
|
||||||
`![](file://${resourceDir}/${r1.id}.jpg)`,
|
`![](file://${resourceDir}/${r1.id}.jpg?t=${t1})`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
true,
|
true,
|
||||||
`![](:/${r1.id}) ![](:/${r1.id}) ![](:/${r2.id})`,
|
`![](:/${r1.id}) ![](:/${r1.id}) ![](:/${r2.id})`,
|
||||||
`![](file://${resourceDir}/${r1.id}.jpg) ![](file://${resourceDir}/${r1.id}.jpg) ![](file://${resourceDir}/${r2.id}.jpg)`,
|
`![](file://${resourceDir}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDir}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDir}/${r2.id}.jpg?t=${t2})`,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -174,13 +174,20 @@ class Note extends BaseItem {
|
|||||||
this.logger().info('replaceResourceExternalToInternalLinks', 'options:', options, 'pathsToTry:', pathsToTry, 'body:', body);
|
this.logger().info('replaceResourceExternalToInternalLinks', 'options:', options, 'pathsToTry:', pathsToTry, 'body:', body);
|
||||||
|
|
||||||
for (const basePath of pathsToTry) {
|
for (const basePath of pathsToTry) {
|
||||||
const reString = `${pregQuote(`${basePath}/`)}[a-zA-Z0-9.]+\\?t=[0-9]+`;
|
const reStrings = [
|
||||||
|
// Handles file://path/to/abcdefg.jpg?t=12345678
|
||||||
|
`${pregQuote(`${basePath}/`)}[a-zA-Z0-9.]+\\?t=[0-9]+`,
|
||||||
|
// Handles file://path/to/abcdefg.jpg
|
||||||
|
`${pregQuote(`${basePath}/`)}[a-zA-Z0-9.]+`,
|
||||||
|
];
|
||||||
|
for (const reString of reStrings) {
|
||||||
const re = new RegExp(reString, 'gi');
|
const re = new RegExp(reString, 'gi');
|
||||||
body = body.replace(re, match => {
|
body = body.replace(re, match => {
|
||||||
const id = Resource.pathToId(match);
|
const id = Resource.pathToId(match);
|
||||||
return `:/${id}`;
|
return `:/${id}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.logger().info('replaceResourceExternalToInternalLinks result', body);
|
this.logger().info('replaceResourceExternalToInternalLinks result', body);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user