diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-06-26 07:23:22 -0400 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-06-26 07:23:22 -0400 |
commit | 4e6e5fcf95f5b07e6d6017ab14f755a34c03e12e (patch) | |
tree | 8c696fdd53678018e4abc893652240c13238bba4 /lib/app.js | |
parent | dba98ce1cf2df6aaa92315ee830b45ae5e414cb0 (diff) | |
download | patchfoo-4e6e5fcf95f5b07e6d6017ab14f755a34c03e12e.tar.gz patchfoo-4e6e5fcf95f5b07e6d6017ab14f755a34c03e12e.zip |
Allow subdirectories in drafts
Diffstat (limited to 'lib/app.js')
-rw-r--r-- | lib/app.js | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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) )) }) |