Merge pull request #1084 from dsprenkels/export-subdirs

Prevent subdirectories in user export
This commit is contained in:
Christoph (Sheogorath) Kern 2018-11-28 10:26:41 +01:00 committed by GitHub
commit 769a1c4ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -90,18 +90,20 @@ UserRouter.get('/me/export', function (req, res) {
ownerId: user.id
}
}).then(function (notes) {
let list = []
let filenames = {}
async.each(notes, function (note, callback) {
let title
let extension = ''
let basename = note.title.replace(/\//g, '-') // Prevent subdirectories
let filename
let suffix = ''
do {
title = note.title + extension
extension++
} while (list.indexOf(title) !== -1)
let seperator = typeof suffix === 'number' ? '-' : ''
filename = basename + seperator + suffix + '.md'
suffix++
} while (filenames[filename])
filenames[filename] = true
list.push(title)
logger.debug('Write: ' + title + '.md')
archive.append(Buffer.from(note.content), { name: title + '.md', date: note.lastchangeAt })
logger.debug('Write: ' + filename)
archive.append(Buffer.from(note.content), { name: filename, date: note.lastchangeAt })
callback(null, null)
}, function (err) {
if (err) {