-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5f1cd7a
Showing
9 changed files
with
729 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
Oops, something went wrong.