summaryrefslogtreecommitdiff
path: root/lib/web
diff options
context:
space:
mode:
authorChristoph (Sheogorath) Kern2018-11-28 10:26:41 +0100
committerGitHub2018-11-28 10:26:41 +0100
commit769a1c4ccbebfa92d839bc2a6ec2b54017154a0a (patch)
tree20a28721be67e2a9a5d160b593bf6473a5f8fa36 /lib/web
parent8bace89cabd18fdd793c237f47f58ac96d5ef531 (diff)
parent9fba2682888ad93816cf98f749562f4671cb235d (diff)
Merge pull request #1084 from dsprenkels/export-subdirs
Prevent subdirectories in user export
Diffstat (limited to '')
-rw-r--r--lib/web/userRouter.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/web/userRouter.js b/lib/web/userRouter.js
index db786d53..ca364422 100644
--- a/lib/web/userRouter.js
+++ b/lib/web/userRouter.js
@@ -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) {