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

All: Fixes #992: Allow non-ASCII chars when exporting MD and handle duplicate filenames

This commit is contained in:
Laurent Cozic
2018-11-20 00:42:21 +00:00
parent 7bfc3e1256
commit 07b724d65b
10 changed files with 135 additions and 20 deletions

View File

@ -1,3 +1,5 @@
const { filename, fileExtension } = require('lib/path-utils');
class FsDriverBase {
async isDirectory(path) {
@ -19,6 +21,23 @@ class FsDriverBase {
return output;
}
async findUniqueFilename(name) {
let counter = 1;
let nameNoExt = filename(name, true);
let extension = fileExtension(name);
if (extension) extension = '.' + extension;
let nameToTry = nameNoExt + extension;
while (true) {
const exists = await this.exists(nameToTry);
if (!exists) return nameToTry;
nameToTry = nameNoExt + ' (' + counter + ')' + extension;
counter++;
if (counter >= 1000) nameToTry = nameNoExt + ' (' + ((new Date()).getTime()) + ')' + extension;
if (counter >= 10000) throw new Error('Cannot find unique title');
}
}
}
module.exports = FsDriverBase;