1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Desktop: Create fileURLs via drag and drop (#1653)

* enable drag and drop fileURLs

* fix windows fileURL syntax

* introduce encodeURI function

* fixed encoding issue

* use path-utils.js to deal with fileURL path conversion

* add changes as requested

* Minor rewording 'On the' -> 'In the', additional info about attaching files

* change call of toFileProtocolPath

* enable test script to check syntax for all OS-platforms
This commit is contained in:
tfinnberg
2019-07-29 12:16:47 +02:00
committed by Laurent Cozic
parent 38a51070fc
commit f7fcabbf41
5 changed files with 75 additions and 23 deletions

View File

@ -10,6 +10,7 @@ const Note = require('lib/models/Note.js');
const Resource = require('lib/models/Resource.js');
const urlValidator = require('valid-url');
function shimInit() {
shim.fsDriver = () => { throw new Error('Not implemented') }
shim.FileApiDriverLocal = FileApiDriverLocal;
@ -168,8 +169,16 @@ function shimInit() {
return await Resource.save(resource, { isNew: true });
}
shim.attachFileToNote = async function(note, filePath, position = null) {
const resource = await shim.createResourceFromPath(filePath);
shim.attachFileToNote = async function(note, filePath, position = null, createFileURL = false) {
const { basename } = require('path');
const { escapeLinkText } = require('lib/markdownUtils');
const { toFileProtocolPath } = require('lib/path-utils');
let resource = [];
if (!createFileURL) {
resource = await shim.createResourceFromPath(filePath);
}
const newBody = [];
@ -178,7 +187,15 @@ function shimInit() {
}
if (note.body && position) newBody.push(note.body.substr(0, position));
newBody.push(Resource.markdownTag(resource));
if (!createFileURL) {
newBody.push(Resource.markdownTag(resource));
} else {
let filename = escapeLinkText(basename(filePath)); // to get same filename as standard drag and drop
let fileURL = "[" + filename + "]("+ toFileProtocolPath(filePath) +")"
newBody.push(fileURL);
}
if (note.body) newBody.push(note.body.substr(position));
const newNote = Object.assign({}, note, {