|
|
|
|
@ -28,7 +28,7 @@ var getTimeStamp = () => {
@@ -28,7 +28,7 @@ var getTimeStamp = () => {
|
|
|
|
|
|
|
|
|
|
app.use(express.static(__dirname + '/resources/public')); |
|
|
|
|
|
|
|
|
|
var log = function () { |
|
|
|
|
var log = function() { |
|
|
|
|
var date = new Date(); |
|
|
|
|
var timestamp = date.getDate() + "/" + date.getMonth() + " " + date.getHours() + ":" + |
|
|
|
|
date.getMinutes() + ":" + date.getSeconds() + "." + date.getMilliseconds(); |
|
|
|
|
@ -38,12 +38,12 @@ var log = function () {
@@ -38,12 +38,12 @@ var log = function () {
|
|
|
|
|
console.log.apply(console, message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
app.get('/new', function (req, res) { |
|
|
|
|
app.get('/new', function(req, res) { |
|
|
|
|
log(req.ip, "opens /new"); |
|
|
|
|
res.send(view.newNotePage(getTimeStamp() + md5(Math.random()))); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.post('/note', function (req, res) { |
|
|
|
|
app.post('/note', function(req, res) { |
|
|
|
|
var body = req.body, |
|
|
|
|
session = body.session, |
|
|
|
|
note = body.note, |
|
|
|
|
@ -61,12 +61,20 @@ app.post('/note', function (req, res) {
@@ -61,12 +61,20 @@ app.post('/note', function (req, res) {
|
|
|
|
|
storage.addNote(note, password).then(goToNote); |
|
|
|
|
else { |
|
|
|
|
CACHE.del(id); |
|
|
|
|
if (body.button == "Delete") { |
|
|
|
|
log("deleting note", id); |
|
|
|
|
storage.deleteNote(id, password).then( |
|
|
|
|
() => sendResponse(res, 200, "Note deleted"), |
|
|
|
|
error => sendResponse(res, 403, error.message)); |
|
|
|
|
} else { |
|
|
|
|
log("updating note", id); |
|
|
|
|
storage.updateNote(id, password, note).then(goToNote, |
|
|
|
|
error => sendResponse(res, 403, error.message)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get("/:year/:month/:day/:title", function (req, res) { |
|
|
|
|
app.get("/:year/:month/:day/:title", function(req, res) { |
|
|
|
|
var P = req.params, url = P.year + "/" + P.month + "/" + P.day + "/" + P.title; |
|
|
|
|
log(req.ip, "resolves deprecated id", url); |
|
|
|
|
if (CACHE.has(url)) { |
|
|
|
|
@ -86,7 +94,7 @@ app.get("/:year/:month/:day/:title", function (req, res) {
@@ -86,7 +94,7 @@ app.get("/:year/:month/:day/:title", function (req, res) {
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get(/\/([a-z0-9]+\/edit)/, function (req, res) { |
|
|
|
|
app.get(/\/([a-z0-9]+\/edit)/, function(req, res) { |
|
|
|
|
var link = req.params["0"].replace("/edit", ""); |
|
|
|
|
log(req.ip, "calls /edit on", link); |
|
|
|
|
storage.getNote(link).then(note => res.send(note |
|
|
|
|
@ -94,7 +102,7 @@ app.get(/\/([a-z0-9]+\/edit)/, function (req, res) {
@@ -94,7 +102,7 @@ app.get(/\/([a-z0-9]+\/edit)/, function (req, res) {
|
|
|
|
|
: notFound(res))); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get(/\/([a-z0-9]+\/export)/, function (req, res) { |
|
|
|
|
app.get(/\/([a-z0-9]+\/export)/, function(req, res) { |
|
|
|
|
var link = req.params["0"].replace("/export", ""); |
|
|
|
|
log(req.ip, "calls /export on", link); |
|
|
|
|
res.set({ 'Content-Type': 'text/plain', 'Charset': 'utf-8' }); |
|
|
|
|
@ -103,7 +111,7 @@ app.get(/\/([a-z0-9]+\/export)/, function (req, res) {
@@ -103,7 +111,7 @@ app.get(/\/([a-z0-9]+\/export)/, function (req, res) {
|
|
|
|
|
: notFound(res)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get(/\/([a-z0-9]+\/stats)/, function (req, res) { |
|
|
|
|
app.get(/\/([a-z0-9]+\/stats)/, function(req, res) { |
|
|
|
|
var link = req.params["0"].replace("/stats", ""); |
|
|
|
|
log(req.ip, "calls /stats on", link); |
|
|
|
|
var promise = link in MODELS |
|
|
|
|
@ -114,7 +122,7 @@ app.get(/\/([a-z0-9]+\/stats)/, function (req, res) {
@@ -114,7 +122,7 @@ app.get(/\/([a-z0-9]+\/stats)/, function (req, res) {
|
|
|
|
|
: notFound(res)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.get(/\/([a-z0-9]+)/, function (req, res) { |
|
|
|
|
app.get(/\/([a-z0-9]+)/, function(req, res) { |
|
|
|
|
var link = req.params["0"]; |
|
|
|
|
log(req.ip, "open note", link, "from", req.get("Referer")); |
|
|
|
|
if (CACHE.has(link)) { |
|
|
|
|
@ -144,8 +152,8 @@ var sendResponse = (res, code, message) => {
@@ -144,8 +152,8 @@ var sendResponse = (res, code, message) => {
|
|
|
|
|
|
|
|
|
|
var notFound = res => sendResponse(res, 404, "Not found"); |
|
|
|
|
|
|
|
|
|
var server = app.listen(process.env.PORT || 3000, function () { |
|
|
|
|
log('NoteHub server listening on port %s', server.address().port); |
|
|
|
|
var server = app.listen(process.env.PORT || 3000, function() { |
|
|
|
|
log('NoteHub server listening on port', server.address().port); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
setInterval(() => { |
|
|
|
|
|