diff options
author | Indrajith K L | 2019-12-30 20:01:49 +0530 |
---|---|---|
committer | Indrajith K L | 2019-12-30 20:01:49 +0530 |
commit | 6534757b525c98abf03f1e04fff77b1b05e4d66e (patch) | |
tree | 158e7532d83457d0ede975edd88e04302302eddd /src/extension.ts | |
parent | e655a66b13b961341bd10156108529937ce2bf5a (diff) | |
download | KopyPlugin-6534757b525c98abf03f1e04fff77b1b05e4d66e.tar.gz KopyPlugin-6534757b525c98abf03f1e04fff77b1b05e4d66e.tar.bz2 KopyPlugin-6534757b525c98abf03f1e04fff77b1b05e4d66e.zip |
* Enchancements
* Fixes - Your clipboard will not be corrupted
* Removed unwanted menus - Now Kopy.io Plugin will show a Notification box with options to Open/Copy your Kopy.io'ed urls
* Adds Encryption to your data - Your data is encrypted by default (Unless you share the url with decryption key -- Key is after the '#' part in the url)
Diffstat (limited to 'src/extension.ts')
-rw-r--r-- | src/extension.ts | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/extension.ts b/src/extension.ts index 0b16250..f9855af 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,55 +4,53 @@ import * as vscode from 'vscode'; import axios from 'axios'; import * as ncp from 'copy-paste'; +import {Utils} from './utils'; +import * as Crypto from 'crypto-js'; // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { - // Use the console to output diagnostic information (console.log) and errors (console.error) - // This line of code will only be executed once when your extension is activated console.log('Congratulations, your extension "kopy-io-plugin" is now active!'); - console.log(ncp); - - // The command has been defined in the package.json file - // Now provide the implementation of the command with registerCommand - // The commandId parameter must match the command field in package.json let olaCommand = vscode.commands.registerCommand('extension.kopyit', (data) => { // The code you place here will be executed every time your command is executed const editor = vscode.window.activeTextEditor; const document = editor.document; - - // console.log(editor.selection); + const supportedLanguageTypes = ["Auto-Detect", "Plain Text", "C", "C++", "CoffeeScript", "CSS", "diff", "Go", "HTML", "Java", "JavaScript", "JSON", "Markdown", "LESS", "Perl", "PHP", "Python", "Ruby", "Sass", "SCSS", "Shell", "SQL", "XML", "APL", "Asterisk", "Cobol", "C#", "Clojure", "Common Lisp", "Cypher", "D", "DTD", "Dylan", "ECL", "Eiffel", "Erlang", "Fortran", "F#", "Gas", "Gherkin", "GitHub Flavored Markdown", "Groovy", "HAML", "Haskell", "Haxe", "ASP.NET", "Embedded Javascript", "JavaServer Pages", "HTTP", "Jade", "JSON-LD", "TypeScript", "Jinja2", "Julia", "Kotlin", "LiveScript", "Lua", "mIRC", "Modelica", "Nginx", "NTriples", "OCaml", "Octave", "Pascal", "PEG.js", "Pig", "Properties files", "Puppet", "Cython", "R", "reStructuredText", "Rust", "Scala", "Scheme", "Sieve", "Slim", "Smalltalk", "Smarty", "SmartyMixed", "Solr", "SPARQL", "MariaDB", "sTeX", "LaTeX", "SystemVerilog", "Tcl", "TiddlyWiki", "Tiki wiki", "TOML", "Turtle", "VB.NET", "VBScript", "Velocity", "Verilog", "XQuery", "YAML", "Z80"]; let selectedText = document.getText(new vscode.Range(editor.selection.start, editor.selection.end)); - // console.log(selectedText); - ncp.copy(selectedText, () => { - console.log("Copied to Clipboard"); - }); + let supportedTimes = { + ten_min: 600, + one_hr: 3600, + one_day: 86400, + three_days: 259200, + one_week: 604800, + one_month: 2592000 + }; + + let randomKey = Utils.createKey(14); + let encryptedData = Crypto.AES.encrypt(selectedText, randomKey).toString(); axios({ method: 'post', url: 'http://kopy.io/documents', - data: "raw:" + selectedText + data: `data=${encodeURI(encryptedData)}&keep=${supportedTimes.one_hr}&language=-1&&security=encrypted&font=Source+Code+Pro&font-size=auto&line-spacing=-1&wrapping=Disabled` }).then((response) => { if(response.status===200){ - // vscode.window.showInformationMessage('kopy.io Url : https://kopy.io/'+response.data.key); - // vscode.window.showInformationMessage('Kopy.io It successfully',...['Open kopy.io',]).then((selection) => { - // vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://kopy.io/'+response.data.key)) - // }); - vscode.window.showQuickPick(['Open kopy.io', 'Copy URL to Clipboard', 'Close']) - .then((val) => { - // vscode.window.showInformationMessage('You picked ' + val) - if (val === 'Open kopy.io') { - vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://kopy.io/'+response.data.key)) - } else if (val === 'Copy URL to Clipboard') { - ncp.copy('https://kopy.io/' + response.data.key, () => { - vscode.window.showInformationMessage('URL is on your Clipboard'); + let openUrl = "Open Url"; + let copyUrl = "Copy Url to your clipboard (!!)"; + let finalUrl = `https://kopy.io/${response.data.key}#${randomKey}`; + vscode.window.showInformationMessage('Your data is Kopied', openUrl, copyUrl).then( + (selectedOption)=>{ + if(selectedOption==openUrl){ + vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(finalUrl)) + }else if(selectedOption==copyUrl){ + ncp.copy(finalUrl, () => { + vscode.window.showInformationMessage('Kopy.io url is on your Clipboard'); }); - } else { - return false; } - }); + } + ); }else{ vscode.window.showErrorMessage('Cannot post the selected text to kopy.io'); } @@ -62,8 +60,6 @@ export function activate(context: vscode.ExtensionContext) { console.log("kopy.io Error", error); vscode.window.showErrorMessage('Cannot post the selected text to kopy.io'); }) - // Display a message box to the user - // vscode.window.showInformationMessage('Hello Worlds!'); }); |