mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
Merge pull request #1084 from dsprenkels/export-subdirs
Prevent subdirectories in user export
This commit is contained in:
commit
769a1c4ccb
1 changed files with 11 additions and 9 deletions
|
@ -90,18 +90,20 @@ UserRouter.get('/me/export', function (req, res) {
|
||||||
ownerId: user.id
|
ownerId: user.id
|
||||||
}
|
}
|
||||||
}).then(function (notes) {
|
}).then(function (notes) {
|
||||||
let list = []
|
let filenames = {}
|
||||||
async.each(notes, function (note, callback) {
|
async.each(notes, function (note, callback) {
|
||||||
let title
|
let basename = note.title.replace(/\//g, '-') // Prevent subdirectories
|
||||||
let extension = ''
|
let filename
|
||||||
|
let suffix = ''
|
||||||
do {
|
do {
|
||||||
title = note.title + extension
|
let seperator = typeof suffix === 'number' ? '-' : ''
|
||||||
extension++
|
filename = basename + seperator + suffix + '.md'
|
||||||
} while (list.indexOf(title) !== -1)
|
suffix++
|
||||||
|
} while (filenames[filename])
|
||||||
|
filenames[filename] = true
|
||||||
|
|
||||||
list.push(title)
|
logger.debug('Write: ' + filename)
|
||||||
logger.debug('Write: ' + title + '.md')
|
archive.append(Buffer.from(note.content), { name: filename, date: note.lastchangeAt })
|
||||||
archive.append(Buffer.from(note.content), { name: title + '.md', date: note.lastchangeAt })
|
|
||||||
callback(null, null)
|
callback(null, null)
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Reference in a new issue