You've already forked joplin
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:
@ -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;
|
Reference in New Issue
Block a user