Repostcheck via Checksum
This commit is contained in:
parent
2018167d49
commit
4063ccd706
57
src/main.js
57
src/main.js
|
@ -5,6 +5,7 @@ var https = require('https');
|
|||
var mysql = require('mysql');
|
||||
var bot = require('coffea')();
|
||||
var uuid = require('uuid');
|
||||
var crypto = require('crypto');
|
||||
const path = require('path');
|
||||
|
||||
var sql;
|
||||
|
@ -48,18 +49,29 @@ bot.on('message', (e) => {
|
|||
dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
||||
if(cb.status === true) {
|
||||
var tmpuser = getUser(e.user.getNick(), e.network);
|
||||
sql.query("insert into `f0ck`.`items` (`src`,`dest`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?)", [
|
||||
entry,
|
||||
"./b/"+tmpdest+"."+cb.infos.ext,
|
||||
tmpuser['nick'],
|
||||
e.channel.getName(),
|
||||
e.network,
|
||||
Math.floor(new Date() / 1000),
|
||||
0
|
||||
]).on('result', (result) => {
|
||||
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")");
|
||||
}).on('error', (msg) => {
|
||||
e.reply(msg);
|
||||
getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
|
||||
checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||||
if(cbcrcs) {
|
||||
sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [
|
||||
entry,
|
||||
"./b/"+tmpdest+"."+cb.infos.ext,
|
||||
cb.infos.mime,
|
||||
cb.infos.size,
|
||||
cbcs,
|
||||
tmpuser['nick'],
|
||||
e.channel.getName(),
|
||||
e.network,
|
||||
Math.floor(new Date() / 1000),
|
||||
0
|
||||
]).on('result', (result) => {
|
||||
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")");
|
||||
}).on('error', (msg) => {
|
||||
e.reply(msg);
|
||||
});
|
||||
}
|
||||
else
|
||||
e.reply("repost motherf0cker");
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -80,6 +92,11 @@ bot.on('message', (e) => {
|
|||
e.reply(msg);
|
||||
});
|
||||
}
|
||||
else if(orig.match(/^\.hash/) && e.channel.getName() == "#f0ck") {
|
||||
getCheckSum('./b/1fbd8b80.png', (cbcs) => {
|
||||
e.reply(cbcs);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var getUser = (u, n) => {
|
||||
|
@ -127,12 +144,28 @@ var checkRepost = (url, cbcr) => {
|
|||
cbcr((rows[0].count == 0)?true:false);
|
||||
});
|
||||
};
|
||||
var checkRepostCheckSum = (cs, cbcrcs) => {
|
||||
sql.query("select count(*) as count from `f0ck`.`items` where `checksum` = ?", cs, (err, rows, fields) => {
|
||||
cbcrcs((rows[0].count == 0)?true:false);
|
||||
});
|
||||
};
|
||||
|
||||
var formatSize = (size) => {
|
||||
var i = Math.floor(Math.log(size) / Math.log(1024));
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||
};
|
||||
|
||||
var getCheckSum = (file, cbcs) => {
|
||||
var sha256sum = crypto.createHash('sha256');
|
||||
var s = fs.ReadStream(file);
|
||||
s.on('data', (d) => {
|
||||
sha256sum.update(d);
|
||||
});
|
||||
s.on('end', () => {
|
||||
var generated_hash = sha256sum.digest('hex');
|
||||
cbcs(generated_hash);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Webserver
|
||||
|
|
Loading…
Reference in New Issue
Block a user