diff options
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) )) }) |