diff options
Diffstat (limited to 'docs/index.js.html')
-rw-r--r-- | docs/index.js.html | 234 |
1 files changed, 0 insertions, 234 deletions
diff --git a/docs/index.js.html b/docs/index.js.html deleted file mode 100644 index 72f5245..0000000 --- a/docs/index.js.html +++ /dev/null @@ -1,234 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width,initial-scale=1"> - <title>index.js - Documentation</title> - - <script src="scripts/prettify/prettify.js"></script> - <script src="scripts/prettify/lang-css.js"></script> - <!--[if lt IE 9]> - <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> - <![endif]--> - <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> - <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> - <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> -</head> -<body> - -<input type="checkbox" id="nav-trigger" class="nav-trigger" /> -<label for="nav-trigger" class="navicon-button x"> - <div class="navicon"></div> -</label> - -<label for="nav-trigger" class="overlay"></label> - -<nav> - <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading"><a href="global.html">Globals</a></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#connect">connect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#createPackage">createPackage</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#decrypt">decrypt</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#decryptJSON">decryptJSON</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#encrypt">encrypt</a></span></li><li class="nav-item"><span class="nav-item-type type-member">M</span><span class="nav-item-name"><a href="global.html#http">http</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#isVerification">isVerification</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#mergerString">mergerString</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#send">send</a></span></li> -</nav> - -<div id="main"> - - <h1 class="page-title">index.js</h1> - - - - - - - - <section> - <article> - <pre class="prettyprint source linenums"><code>/** - * @project iii-client - * @author Valentin Popov <info@valentineus.link> - * @license See LICENSE.md file included in this distribution. - */ -var http = require('http'); - -exports.connect = connect; -/** - * Connects to the server and returns the connection data. - * @param {String} uuid - The bot UUID. - * @param {requestCallback} callback - The callback that handles the response. - */ -function connect(uuid, callback) { - uuid = uuid || ''; - - if (!isVerification(uuid)) { - throw new Error('The UUID is not a valid value!'); - } - - const query = { - port: 80, - hostname: 'iii.ru', - path: '/api/2.0/json/Chat.init/' + uuid + '/', - method: 'GET', - }; - - const request = http.request(query, function(response) { - var json = ''; - response.on('data', (raw) => json = decryptJSON(raw)); - response.on('end', () => { - if (json.error) throw new Error(json.error.message); - callback(json.result); - }); - }); - - request.on('error', (error) => Error(error.message)); - - request.end(); -} - -exports.send = send; -/** - * Send a message to the server and return a response. - * @param {Object} raw - The data to send. - * @param {String} raw.cuid - Session identifier. - * @param {String} raw.text - Message text. - * @param {requestCallback} callback - The callback that handles the response. - */ -function send(raw, callback) { - raw = raw || {}; - - const query = { - port: 80, - hostname: 'iii.ru', - path: '/api/2.0/json/Chat.request', - method: 'POST', - }; - - const data = createPackage(raw); - - const request = http.request(query, function(response) { - var json = ''; - response.on('data', (raw) => json = decryptJSON(raw)); - response.on('end', () => { - if (json.error) throw new Error(json.error.message); - callback(json.result); - }); - }); - - request.on('error', (error) => Error(error)); - - request.write(data); - request.end(); -} - -exports.encrypt = encrypt; -/** - * Encrypts the incoming data. - * @param {String} raw - Decrypted data. - * @returns {String} - Encrypted string. - */ -function encrypt(raw) { - raw = raw || ''; - - var base64 = Buffer.from(raw).toString('base64'); - var string = Buffer.from(base64); - return mergerString(string).toString('base64'); -} - -exports.decrypt = decrypt; -/** - * Decrypts the incoming data. - * @param {String} raw - Encrypted data. - * @returns {String} - Decrypted string. - */ -function decrypt(raw) { - raw = raw || ''; - - var string = Buffer.from(raw, 'base64'); - var decrypted = mergerString(string).toString(); - return Buffer.from(decrypted, 'base64'); -} - -exports.decryptJSON = decryptJSON; -/** - * Decrypts an encrypted JSON object. - * @param {String} raw - Encrypted data. - * @returns {Object} - Decrypted JSON. - */ -function decryptJSON(raw) { - raw = raw || ''; - - var string = raw.toString('ascii'); - var data = decrypt(string); - return JSON.parse(data); -} - -exports.mergerString = mergerString; -/** - * Merge and convert a string. - * @param {String} raw - The string to convert. - * @returns {String} - The converted string. - */ -function mergerString(data) { - data = data || ''; - - const salt = Buffer.from('some very-very long string without any non-latin characters due to different string representations inside of variable programming languages'); - - for (var i = 0; i < data.length; i++) { - data[i] = data[i] ^ salt[i % salt.length]; - } - - return data; -} - -exports.createPackage = createPackage; -/** - * Creates an encrypted package to send. - * @param {Object} raw - The data to send. - * @param {String} raw.cuid - Session identifier. - * @param {String} raw.text - Message text. - * @returns {String} - Encrypted string. - */ -function createPackage(raw) { - raw = raw || {}; - - if (!raw.text) { - throw new Error('There is no data to send!'); - } - - if (!isVerification(raw.cuid)) { - throw new Error('Parameter \'CUID\' is not a valid UUID value!'); - } - - var data = []; - data.push(raw.cuid); - data.push(raw.text.toString()); - - var json = JSON.stringify(data); - return encrypt(json); -} - -exports.isVerification = isVerification; -/** - * Validation UUID format string. - * @param {String} data - The string to check. - * @returns {Boolean} - */ -function isVerification(data) { - data = data || ''; - const regexp = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', 'i'); - return regexp.test(data); -} -</code></pre> - </article> - </section> - - - - -</div> - -<br class="clear"> - -<footer> - Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jun 14 2017 22:00:09 GMT+0000 (UTC) using the Minami theme. -</footer> - -<script>prettyPrint();</script> -<script src="scripts/linenumber.js"></script> -</body> -</html> |