mirror of
https://github.com/jsbin/jsbin.git
synced 2026-02-01 16:46:05 +00:00
Checking for latest revision when returning a 404
This commit is contained in:
parent
7e8d1099cb
commit
b1faabb9d5
@ -351,23 +351,41 @@ module.exports = Observable.extend({
|
||||
}
|
||||
|
||||
results.url = req.param('bin');
|
||||
if (req.url.indexOf('edit') > -1) {
|
||||
_this.render(req, res, results);
|
||||
} else {
|
||||
var options = {edit: true, silent: true};
|
||||
_this.formatPreview(results, options, function (err, formatted) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
if (formatted) {
|
||||
res.send(formatted);
|
||||
} else {
|
||||
res.contentType('js');
|
||||
res.send(req.bin.javascript);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Need to get the most recent revision from the database.
|
||||
_this.models.bin.latest({id: results.url}, function (err, bin) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// We have a missing bin, we check the latest returned bin, if this
|
||||
// is active then we simply render it assuming the user mistyped the
|
||||
// url.
|
||||
if (bin && bin.active) {
|
||||
results = bin;
|
||||
} else {
|
||||
// If we have a bin then take the latest revision plus one.
|
||||
results.revision = bin && (bin.revision + 1);
|
||||
}
|
||||
|
||||
if (req.url.indexOf('edit') > -1) {
|
||||
_this.render(req, res, results);
|
||||
} else {
|
||||
var options = {edit: true, silent: true};
|
||||
_this.formatPreview(results, options, function (err, formatted) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
if (formatted) {
|
||||
res.send(formatted);
|
||||
} else {
|
||||
res.contentType('js');
|
||||
res.send(req.bin.javascript);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
loadBin: function (req, res, next) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user