diff --git a/Dockerfile b/Dockerfile index 7b7d5ac..0efa8ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ ENV HOST=0.0.0.0\ USER node:node +VOLUME /usr/src/app/data + EXPOSE ${PORT} STOPSIGNAL SIGINT ENTRYPOINT [ "bash", "docker-entrypoint.sh" ] diff --git a/README.md b/README.md index 34fcab2..e0bb352 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Test it in seconds : ```bash -docker run --rm -d -p 7777:7777 hastepad:0.5 +docker run --rm -d -p 7777:7777 mtudury/hastepad:0.6 ``` Open your browser and type url : http://127.0.0.1:7777/ diff --git a/docker-compose.yaml b/docker-compose.yaml index 352ee74..f870bee 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ version: '3.6' services: haste-server: build: . - image: hastepad:0.5 + image: hastepad:0.6 ports: - 7777:7777 volumes: diff --git a/static/application.css b/static/application.css index 8bd3131..68b4fc4 100644 --- a/static/application.css +++ b/static/application.css @@ -133,6 +133,30 @@ textarea { font-weight: normal; } +#box4 ul { + margin-block-start: 3px; + margin-block-end: 3px; + padding-inline-start: 0; + background: #00222b; +} + +#box4 li { + display: block; + font-family: monospace; +} + +#box4 a { + display:block; + padding-left: 10px; + text-decoration: none; + color: #fff; +} + +#box4 a:hover { + background: #173e48; + font-weight: bold; +} + #box2 .function.save { background-position: -5px top; } #box2 .function.enabled.save { background-position: -5px center; } #box2 .function.enabled.save:hover { background-position: -5px bottom; } @@ -141,17 +165,21 @@ textarea { #box2 .function.enabled.new { background-position: -42px center; } #box2 .function.enabled.new:hover { background-position: -42px bottom; } -#box2 .function.duplicate { background-position: -79px top; } -#box2 .function.enabled.duplicate { background-position: -79px center; } -#box2 .function.enabled.duplicate:hover { background-position: -79px bottom; } +#box2 .function.edit { background-position: -79px top; } +#box2 .function.enabled.edit { background-position: -79px center; } +#box2 .function.enabled.edit:hover { background-position: -79px bottom; } #box2 .function.raw { background-position: -116px top; } #box2 .function.enabled.raw { background-position: -116px center; } #box2 .function.enabled.raw:hover { background-position: -116px bottom; } -#box2 .function.twitter { background-position: -153px top; } -#box2 .function.enabled.twitter { background-position: -153px center; } -#box2 .function.enabled.twitter:hover { background-position: -153px bottom; } +#box2 .function.duplicate { background-position: -153px top; } +#box2 .function.enabled.duplicate { background-position: -153px center; } +#box2 .function.enabled.duplicate:hover { background-position: -153px bottom; } + +#box2 .function.delete { background-position: -190px top; } +#box2 .function.enabled.delete { background-position: -190px center; } +#box2 .function.enabled.delete:hover { background-position: -190px bottom; } #box2 .button-picture{ border-width: 0; font-size: inherit; } #messages { diff --git a/static/application.js b/static/application.js index 1959d7c..ffe7dfc 100644 --- a/static/application.js +++ b/static/application.js @@ -86,6 +86,28 @@ haste_document.prototype.save = function(key, data, callback) { }); }; +// Save this document to the server and lock it here +haste_document.prototype.deleteDocument = function(key, callback) { + if (!this.locked) { + return false; + } + var _this = this; + $.ajax('/documents/' + key, { + type: 'delete', + success: function(res) { + callback(null, res); + }, + error: function(res) { + try { + callback($.parseJSON(res.responseText)); + } + catch (e) { + callback({message: 'Something went wrong!'}); + } + } + }); +}; + // get a valid key from server haste_document.prototype.getkey = function(callback) { $.ajax('/key/', { @@ -143,12 +165,12 @@ haste.prototype.lightKey = function() { // Show the full key haste.prototype.fullKey = function() { - this.configureKey(['new', 'duplicate', 'twitter', 'raw']); + this.configureKey(['new', 'duplicate', 'edit', 'raw', 'delete']); }; // Show all the keys haste.prototype.allKey = function() { - this.configureKey(['new', 'save', 'duplicate', 'twitter', 'raw']); + this.configureKey(['new', 'save', 'duplicate', 'edit', 'raw', 'delete']); }; // Set the key up for certain things to be enabled @@ -323,7 +345,7 @@ haste.prototype.unlockDocument = function() { var _this = this; _this.$textarea.val(_this.$code.text()).show().focus(); _this.$box.hide(); - _this.allKey(); + _this.lightKey(); _this.removeLineNumbers(); _this.doc.locked = false; }; @@ -378,16 +400,31 @@ haste.prototype.configureButtons = function() { } }, { - $where: $('#box2 .twitter'), + $where: $('#box2 .edit'), label: 'Edit', shortcut: function(evt) { - return _this.options.twitter && _this.doc.locked && evt.shiftKey && evt.ctrlKey && evt.keyCode == 84; + return _this.doc.locked && evt.shiftKey && evt.ctrlKey && evt.keyCode == 84; }, shortcutDescription: 'control + shift + t', action: function() { - //window.open('https://twitter.com/share?url=' + encodeURI(window.location.href)); _this.unlockDocument(); } + }, + { + $where: $('#box2 .delete'), + label: 'Delete', + shortcut: function(evt) { + return false; + }, + shortcutDescription: 'none', + action: function() { + _this.doc.deleteDocument(_this.getCurrentKey(), function () { + _this.$box.html(''); + _this.removeLineNumbers(); + _this.showMessage("Deleted"); + _this.updateList(); + }); + } } ]; for (var i = 0; i < this.buttons.length; i++) { @@ -422,8 +459,11 @@ haste.prototype.updateList = function () { _this.getList(function (lst) { if (lst) { var lis = ""; + var cnt = 0; lst.forEach(function (file) { - lis+= '
  • '+file+'
  • '; + if (cnt < 150) + lis+= '
  • '+file+'
  • '; + cnt++; }); $('#list').html(lis); } @@ -461,7 +501,7 @@ haste.prototype.autosave = function() { }); _this.doc.changed = false; } - window.setTimeout(cycle, 15000); + window.setTimeout(cycle, 5000); }; window.setTimeout(cycle, 5000); diff --git a/static/application.min.js b/static/application.min.js index 4119164..d30d4cd 100644 --- a/static/application.min.js +++ b/static/application.min.js @@ -1 +1 @@ -var haste_document=function(){this.locked=!1};haste_document.prototype.htmlEscape=function(t){return t.replace(/&/g,"&").replace(/>/g,">").replace(/'+t+"");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.allKey=function(){this.configureKey(["new","save","duplicate","twitter","raw"])},haste.prototype.configureKey=function(t){var e,o=0;$("#box2 .function").each(function(){for(e=$(this),o=0;o";$("#linenos").html(e)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(t){var e=t.split(".",2),o=this;o.doc=new haste_document,o.doc.load(t,function(t){t?(o.$code.html(t.value),o.setTitle(t.key),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(t.lineCount)):o.newDocument()},this.lookupTypeByExtension(e[1])),this.updateList()},haste.prototype.duplicateDocument=function(){var t=this;if(t.doc.locked){var e=t.doc.data;t.newDocument(!0,function(){t.$textarea.val(e)})}},haste.prototype.lockDocument=function(){var t=this;this.doc.save(this.getCurrentKey(),this.$textarea.val(),function(e,o){e?t.showMessage(e.message,"error"):o&&(t.doc.locked=!0,t.$code.html(o.value),t.setTitle(o.key),t.fullKey(),t.$textarea.val("").hide(),t.$box.show().focus(),t.addLineNumbers(o.lineCount))})},haste.prototype.unlockDocument=function(){var t=this;t.$textarea.val(t.$code.text()).show().focus(),t.$box.hide(),t.allKey(),t.removeLineNumbers(),t.doc.locked=!1},haste.prototype.configureButtons=function(){var t=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(t){return t.ctrlKey&&83===t.keyCode},action:function(){""!==t.$textarea.val().replace(/^\s+|\s+$/g,"")&&t.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(t){return t.ctrlKey&&78===t.keyCode},shortcutDescription:"control + n",action:function(){t.newDocument(!0)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(e){return t.doc.locked&&e.ctrlKey&&68===e.keyCode},shortcutDescription:"control + d",action:function(){t.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(t){return t.ctrlKey&&t.shiftKey&&82===t.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+t.doc.key}},{$where:$("#box2 .twitter"),label:"Edit",shortcut:function(e){return t.options.twitter&&t.doc.locked&&e.shiftKey&&e.ctrlKey&&84==e.keyCode},shortcutDescription:"control + shift + t",action:function(){t.unlockDocument()}}];for(var e=0;e'+t+""}),$("#list").html(e)}})},haste.prototype.configureShortcuts=function(){var t=this;$(document.body).keydown(function(e){for(var o,n=0;n/g,">").replace(/'+t+"");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","edit","raw","delete"])},haste.prototype.allKey=function(){this.configureKey(["new","save","duplicate","edit","raw","delete"])},haste.prototype.configureKey=function(t){var e,o=0;$("#box2 .function").each(function(){for(e=$(this),o=0;o";$("#linenos").html(e)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(t){var e=t.split(".",2),o=this;o.doc=new haste_document,o.doc.load(t,function(t){t?(o.$code.html(t.value),o.setTitle(t.key),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(t.lineCount)):o.newDocument()},this.lookupTypeByExtension(e[1])),this.updateList()},haste.prototype.duplicateDocument=function(){var t=this;if(t.doc.locked){var e=t.doc.data;t.newDocument(!0,function(){t.$textarea.val(e)})}},haste.prototype.lockDocument=function(){var t=this;this.doc.save(this.getCurrentKey(),this.$textarea.val(),function(e,o){e?t.showMessage(e.message,"error"):o&&(t.doc.locked=!0,t.$code.html(o.value),t.setTitle(o.key),t.fullKey(),t.$textarea.val("").hide(),t.$box.show().focus(),t.addLineNumbers(o.lineCount))})},haste.prototype.unlockDocument=function(){var t=this;t.$textarea.val(t.$code.text()).show().focus(),t.$box.hide(),t.lightKey(),t.removeLineNumbers(),t.doc.locked=!1},haste.prototype.configureButtons=function(){var t=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(t){return t.ctrlKey&&83===t.keyCode},action:function(){""!==t.$textarea.val().replace(/^\s+|\s+$/g,"")&&t.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(t){return t.ctrlKey&&78===t.keyCode},shortcutDescription:"control + n",action:function(){t.newDocument(!0)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(e){return t.doc.locked&&e.ctrlKey&&68===e.keyCode},shortcutDescription:"control + d",action:function(){t.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(t){return t.ctrlKey&&t.shiftKey&&82===t.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+t.doc.key}},{$where:$("#box2 .edit"),label:"Edit",shortcut:function(e){return t.doc.locked&&e.shiftKey&&e.ctrlKey&&84==e.keyCode},shortcutDescription:"control + shift + t",action:function(){t.unlockDocument()}},{$where:$("#box2 .delete"),label:"Delete",shortcut:function(t){return!1},shortcutDescription:"none",action:function(){t.doc.deleteDocument(t.getCurrentKey(),function(){t.$box.html(""),t.removeLineNumbers(),t.showMessage("Deleted"),t.updateList()})}}];for(var e=0;e'+t+""),o++}),$("#list").html(e)}})},haste.prototype.configureShortcuts=function(){var t=this;$(document.body).keydown(function(e){for(var o,n=0;n - + - + +