aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
authorcel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-06-26 07:23:22 -0400
committercel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-06-26 07:23:22 -0400
commit4e6e5fcf95f5b07e6d6017ab14f755a34c03e12e (patch)
tree8c696fdd53678018e4abc893652240c13238bba4 /lib/app.js
parentdba98ce1cf2df6aaa92315ee830b45ae5e414cb0 (diff)
downloadpatchfoo-4e6e5fcf95f5b07e6d6017ab14f755a34c03e12e.tar.gz
patchfoo-4e6e5fcf95f5b07e6d6017ab14f755a34c03e12e.zip
Allow subdirectories in drafts
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/app.js b/lib/app.js
index 814bfb6..15aa796 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -1572,7 +1572,6 @@ App.prototype.saveDraft = function (id, url, form, content, cb) {
mkdirp.sync(self.draftsDir)
self.madeDraftsDir = true
}
- if (/[\/:\\]/.test(id)) return cb(new Error('draft id cannot contain path seperators'))
var draft = {
url: url,
form: form,
@@ -1587,6 +1586,7 @@ App.prototype.getDraft = function (id, cb) {
var self = this
var filename = path.join(self.draftsDir, id)
fs.readFile(filename, 'utf8', function (err, data) {
+ if (err && err.code === 'EISDIR') return cb(null, {id: id, isDir: true})
if (err) return cb(err)
var draft
try { draft = JSON.parse(data) }
@@ -1621,19 +1621,21 @@ function statAll(files, dir, cb) {
)
}
-App.prototype.listDrafts = function () {
+App.prototype.listDrafts = function (dir) {
var self = this
+ var draftsDir = dir ? path.join(self.draftsDir, dir) : self.draftsDir
return u.readNext(function (cb) {
- fs.readdir(self.draftsDir, function (err, files) {
+ fs.readdir(draftsDir, function (err, files) {
if (err && err.code === 'ENOENT') return cb(null, pull.empty())
if (err) return cb(err)
- statAll(files, self.draftsDir, function (err, stats) {
+ statAll(files, draftsDir, function (err, stats) {
if (err) return cb(err)
stats.sort(compareMtime)
cb(null, pull(
pull.values(stats),
paramap(function (stat, cb) {
- self.getDraft(stat.name, cb)
+ var name = dir ? path.join(dir, stat.name) : stat.name
+ self.getDraft(name, cb)
}, 4)
))
})