Note deletion feature added
This commit is contained in:
+7
-7
@@ -23,15 +23,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/chmllr/NoteHub",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.14.1",
|
||||
"express": "^4.13.3",
|
||||
"lru-cache": "^2.6.5",
|
||||
"body-parser": "^1.15.0",
|
||||
"express": "^4.13.4",
|
||||
"lru-cache": "^4.0.0",
|
||||
"marked": "^0.3.5",
|
||||
"md5": "^2.0.0",
|
||||
"sequelize": "^3.8.0",
|
||||
"sqlite3": "^3.1.0"
|
||||
"md5": "^2.1.0",
|
||||
"sequelize": "^3.19.3",
|
||||
"sqlite3": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.7.3"
|
||||
"nodemon": "^1.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@
|
||||
<textarea id="note" name="note">%CONTENT%</textarea>
|
||||
<fieldset id="input-elems">
|
||||
<input class="ui-elem" id="plain-password" name="plain-password" placeholder="Password for editing" type="text">
|
||||
<input class="button ui-elem" id="publish-button" type="submit" value="Publish">
|
||||
<input class="button ui-elem" id="publish-button" name="button" type="submit" value="Publish">
|
||||
<input class="button ui-elem" id="delete-button" name="button" type="submit" value="Delete">
|
||||
<span id="tableau">
|
||||
0 words
|
||||
</span>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<article class="bottom-space">
|
||||
<h2>Changelog</h2>
|
||||
<ul>
|
||||
<li><strong>2016-03</strong>: Note deletion feature added.</li>
|
||||
<li><strong>2015-10</strong>: NoteHub rewritten in Node.js.</li>
|
||||
<li><strong>2015-10</strong>: NoteHub API and note styling discontinued due to low adoption by the user base.</li>
|
||||
<li><strong>2014-09</strong>: text size setting added</li>
|
||||
|
||||
@@ -4,8 +4,7 @@ var $ = function(id) {
|
||||
var iosDetected = navigator.userAgent.match("(iPad|iPod|iPhone)");
|
||||
var timer = null;
|
||||
var timerDelay = iosDetected ? 800 : 400;
|
||||
var $note, $action, $preview, $plain_password,
|
||||
updatePreview, $tableau;
|
||||
var $note, $action, $preview, $plain_password, $tableau;
|
||||
var backendTimer;
|
||||
|
||||
function md2html(input) {
|
||||
@@ -25,7 +24,7 @@ function onLoad() {
|
||||
$preview = $("draft");
|
||||
$tableau = $("tableau");
|
||||
$plain_password = $("plain-password");
|
||||
updatePreview = function() {
|
||||
var updatePreview = function() {
|
||||
clearTimeout(timer);
|
||||
var content = $note.value;
|
||||
var delay = Math.min(timerDelay, timerDelay * (content.length / 400));
|
||||
@@ -36,6 +35,7 @@ function onLoad() {
|
||||
};
|
||||
if ($action == "UPDATE") updatePreview();
|
||||
else {
|
||||
$("delete-button").style.display = "none";
|
||||
$note.value = "";
|
||||
var draft = localStorage.getItem("draft");
|
||||
if (draft) {
|
||||
@@ -44,14 +44,13 @@ function onLoad() {
|
||||
}
|
||||
}
|
||||
$note.onkeyup = updatePreview;
|
||||
$("publish-button").onclick = function(e) {
|
||||
$("delete-button").onclick = $("publish-button").onclick = function(e) {
|
||||
localStorage.removeItem("draft");
|
||||
self.onbeforeunload = null;;
|
||||
self.onbeforeunload = null;
|
||||
if ($plain_password.value != "") $("password").value = md5($plain_password.value);
|
||||
$plain_password.value = null;
|
||||
$("signature").value = md5($("session").value +
|
||||
$note.value.replace(/[\n\r]/g, ""));
|
||||
}
|
||||
$("signature").value = md5($("session").value + $note.value.replace(/[\n\r]/g, ""));
|
||||
};
|
||||
if (iosDetected) $note.className += " ui-border";
|
||||
else $note.focus();
|
||||
self.onbeforeunload = saveDraft;
|
||||
|
||||
@@ -61,9 +61,17 @@ 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) {
|
||||
@@ -145,7 +153,7 @@ 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);
|
||||
log('NoteHub server listening on port', server.address().port);
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
|
||||
+12
-5
@@ -45,11 +45,18 @@ module.exports.addNote = (note, password) => getFreeId().then(id => Note.create(
|
||||
password: password
|
||||
}));
|
||||
|
||||
module.exports.updateNote = (id, password, text) => Note.findById(id).then(note => {
|
||||
if (!note || note.password !== password) return new Promise((resolve, reject) => {
|
||||
reject({ message: "Password is wrong" });
|
||||
});
|
||||
var passwordCheck = (note, password, callback) => (!note || note.password !== password)
|
||||
? new Promise((resolve, reject) => reject({ message: "Password is wrong" }))
|
||||
: callback();
|
||||
|
||||
module.exports.updateNote = (id, password, text) =>
|
||||
Note.findById(id).then(note =>
|
||||
passwordCheck(note, password, () => {
|
||||
note.text = text;
|
||||
note.edited = new Date();
|
||||
return note.save();
|
||||
});
|
||||
}));
|
||||
|
||||
module.exports.deleteNote = (id, password) =>
|
||||
Note.findById(id).then(note =>
|
||||
passwordCheck(note, password, () => note.destroy()));
|
||||
Reference in New Issue
Block a user