Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
TNYCL committed Jul 17, 2021
0 parents commit 5f1cd7a
Show file tree
Hide file tree
Showing 9 changed files with 729 additions and 0 deletions.
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const log = require('./log');
const settings = require('./settings');
const utilSQL = require('./mysql/util');
const util = require('./util');

var link = process.argv.slice(2);
var uuid = util.createUUID();
var key;

main();

function main() {
utilSQL.getData(link, (error, data) => {
if(error) throw error;
key = data;
});
setTimeout(() => {
if(key != null) {
log.error('This link already shorted: ' + settings.websiteLink + key);
process.exit();
return;
}
if(!util.checkLink(link)) {
log.error('Link as wrong, please check link.');
process.exit();
return;
}
short();
process.exit();
}, 400);
}

function short() {
var shortedLink = settings.websiteLink + uuid;
utilSQL.setData(uuid, link);
log.success('Link successfully shorted: ' + shortedLink);
util.copyString(shortedLink);
log.success('Link copied to clipboard.');
}
7 changes: 7 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off
title
cls
npm i --save mysql clipboardy
cls
echo Install completed.
pause
14 changes: 14 additions & 0 deletions log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

function info(message){
return console.log('[INFO] ' + message);
}

function success(message){
return console.log('[SUCCESS] ' + message)
}

function error(message){
return console.log('[ERROR] ' + message);
}

module.exports = {info,success,error};
16 changes: 16 additions & 0 deletions mysql/connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mysql = require('mysql');
const log = require('../log');

var connection = mysql.createConnection({
host: null,
user: 'TNYCL',
password: null,
database: null,
port: '3306'
});

connection.connect(function(error) {
if(error) throw error;
});

module.exports = {connection};
23 changes: 23 additions & 0 deletions mysql/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const mysql = require('./connect');
const log = require('../log');

async function setData(key, value) {
var sql = "INSERT INTO short_link (short_key, link) VALUES ('"+key+"', '"+value+"')";
mysql.connection.query(sql, (error) => {
if(error) throw error;
});
}

async function getData(key, callback) {
var sql = "SELECT * FROM short_link WHERE link='"+key+"'";
mysql.connection.query(sql, (error, result) => {
if(error) throw error;
if(result == '') {
return callback(null, null);
} else {
return callback(null, result[0].short_key);
}
});
}

module.exports = {setData,getData};
Loading

0 comments on commit 5f1cd7a

Please sign in to comment.