From d3ac67161846f4265b1e3de7448f001041b1ae0c Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Mon, 21 Jan 2019 15:27:24 -0800 Subject: [PATCH] Added paste from clipboard support to uploads page. --- Teknik/Areas/Upload/Views/Upload/Index.cshtml | 4 +- Teknik/Scripts/Upload/Upload.js | 57 ++++++++++++------- Teknik/Scripts/common.js | 49 ++++++++++++++++ Teknik/Teknik.csproj | 4 -- 4 files changed, 88 insertions(+), 26 deletions(-) diff --git a/Teknik/Areas/Upload/Views/Upload/Index.cshtml b/Teknik/Areas/Upload/Views/Upload/Index.cshtml index d64555c..8c6ef0e 100644 --- a/Teknik/Areas/Upload/Views/Upload/Index.cshtml +++ b/Teknik/Areas/Upload/Views/Upload/Index.cshtml @@ -40,12 +40,12 @@
-

Or just click here

+

Or paste them

-

Your Choice

+

Or click

diff --git a/Teknik/Scripts/Upload/Upload.js b/Teknik/Scripts/Upload/Upload.js index 7c8c280..fea5aee 100644 --- a/Teknik/Scripts/Upload/Upload.js +++ b/Teknik/Scripts/Upload/Upload.js @@ -26,6 +26,19 @@ $(document).ready(function () { linkExpireSelect($('#uploadSettings').find("#expireunit")); }); + + document.onpaste = function (event) { + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + for (index in items) { + var item = items[index]; + if (item.kind === 'file') { + // Convert file to blob + var file = item.getAsFile(); + // Upload the file + upload(file); + } + } + } }); function linkExpireSelect(element) { @@ -182,32 +195,36 @@ var dropZone = new Dropzone(document.body, { clickable: "#uploadButton", previewTemplate: function () { }, addedfile: function (file) { - - // Convert file to blob - var blob = file.slice(0, file.size); - - // Create a token for this upload - var token = { - callback: null, - cancel: function() { - this.callback(); - }, - isCancelable: function() { - return this.callback !== null; - } - }; - - // Create the Upload - var fileID = createUpload(file.name, token); - - // Process the file - processFile(blob, file.name, file.type, file.size, fileID, token); + // Upload the file to the server + upload(file); // Remove this file from the dropzone set this.removeFile(file); } }); +function upload(file) { + // Convert file to blob + var blob = file.slice(0, file.size); + + // Create a token for this upload + var token = { + callback: null, + cancel: function () { + this.callback(); + }, + isCancelable: function () { + return this.callback !== null; + } + }; + + // Create the Upload + var fileID = createUpload(file.name, token); + + // Process the file + processFile(blob, file.name, file.type, file.size, fileID, token); +} + var fileCount = 0; function createUpload(fileName, token) { diff --git a/Teknik/Scripts/common.js b/Teknik/Scripts/common.js index c1d3e30..f915ed6 100644 --- a/Teknik/Scripts/common.js +++ b/Teknik/Scripts/common.js @@ -305,6 +305,55 @@ function parseErrorMessage(errorObj) { } return errorMsg; } +var re_weburl = new RegExp( + "^" + + // protocol identifier (optional) + // short syntax // still required + "(?:(?:(?:https?|ftp):)?\\/\\/)" + + // user:pass BasicAuth (optional) + "(?:\\S+(?::\\S*)?@)?" + + "(?:" + + // IP address exclusion + // private & local networks + "(?!(?:10|127)(?:\\.\\d{1,3}){3})" + + "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" + + "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" + + // IP address dotted notation octets + // excludes loopback network 0.0.0.0 + // excludes reserved space >= 224.0.0.0 + // excludes network & broacast addresses + // (first & last IP address of each class) + "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + + "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + + "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + + "|" + + // host & domain names, may end with dot + // can be replaced by a shortest alternative + // (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+ + "(?:" + + "(?:" + + "[a-z0-9\\u00a1-\\uffff]" + + "[a-z0-9\\u00a1-\\uffff_-]{0,62}" + + ")?" + + "[a-z0-9\\u00a1-\\uffff]\\." + + ")+" + + // TLD identifier name, may end with dot + "(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" + + ")" + + // port number (optional) + "(?::\\d{2,5})?" + + // resource path (optional) + "(?:[/?#]\\S*)?" + + "$", "i" +); + +function isValidURL(str) { + if (!re_weburl.test(str)) { + return false; + } else { + return true; + } +} /***************************** TIMER Page Load *******************************/ var loopTime; diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 42cf0c8..0b57050 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -88,10 +88,6 @@ Never PreserveNewest - - Never - PreserveNewest - Never PreserveNewest