modified: package.json
modified: src/main.js
This commit is contained in:
parent
ff08c5e13f
commit
7e192acae0
@ -4,8 +4,9 @@
|
||||
"main": "src/main.js",
|
||||
"dependencies": {
|
||||
"coffea": "^0.4.24",
|
||||
"fs-extra": "^0.30.0",
|
||||
"mysql": "^2.11.1",
|
||||
"repl": "^0.1.3",
|
||||
"repl": "^0.1.3"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
207
src/main.js
207
src/main.js
@ -1,5 +1,5 @@
|
||||
var cfg = require('../../cfg.json');
|
||||
var fs = require('fs');
|
||||
var fs = require('fs-extra');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var mysql = require('mysql');
|
||||
@ -9,8 +9,6 @@ var crypto = require('crypto');
|
||||
var path = require('path');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var neu = true;
|
||||
|
||||
var sql;
|
||||
var haDC = () => {
|
||||
sql = mysql.createConnection(cfg.mysql);
|
||||
@ -45,47 +43,49 @@ bot.on('motd', (e) => {
|
||||
|
||||
bot.on('message', (e) => {
|
||||
var orig = e.message;
|
||||
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher
|
||||
var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
|
||||
tmp.forEach((entry,i,a) => {
|
||||
var tmpdest = uuid.v1().split('-')[0];
|
||||
dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
||||
if(cb.status === true) {
|
||||
var tmpuser = getUser(e.user.getNick(), e.network);
|
||||
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`,`thumb`,`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) => {
|
||||
neu = true;
|
||||
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 {
|
||||
fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost
|
||||
e.reply("repost motherf0cker");
|
||||
}
|
||||
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi) && e.channel.getName() == "#f0ck") { // shitpostcatcher
|
||||
if(!orig.match(/\!ignore$/)) {
|
||||
var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
|
||||
tmp.forEach((entry,i,a) => {
|
||||
var tmpdest = uuid.v1().split('-')[0];
|
||||
dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
||||
if(cb.status === true) {
|
||||
var tmpuser = getUser(e.user.getNick(), e.network);
|
||||
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`,`thumb`,`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) => {
|
||||
generateThumbs();
|
||||
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 {
|
||||
fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost
|
||||
e.reply("repost motherf0cker");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
if(cb.type == 1)
|
||||
e.reply(cb.msg);
|
||||
}
|
||||
else
|
||||
if(cb.type == 1)
|
||||
e.reply(cb.msg);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
else if(orig.match(/^\.user/)) { // (debug) get userinfos
|
||||
var tmp = getUser(e.user.getNick(), e.network);
|
||||
@ -187,10 +187,10 @@ http.createServer((req, res) => {
|
||||
};
|
||||
|
||||
if(filePath == "./index.html") { // mainpage
|
||||
sql.query("select * from `f0ck`.`items`", (err, rows, fields) => {
|
||||
sql.query("select * from `f0ck`.`items` order by `id` desc", (err, rows, fields) => {
|
||||
var tmpres = "<!DOCTYPE blah><html><head><title>f0ck me!</title><link rel=\"stylesheet\" type=\"text/css\" href=\"./s/style.css\"></head><body>";
|
||||
rows.forEach((e,i,a) => {
|
||||
tmpres += "<a href='./"+e.id+"'><img src='./t/"+e.id+".png' /></a>\n";
|
||||
tmpres += "<div class='mrhankyisteinneger'><a href='./"+e.id+"'><img src='./t/"+e.id+".png' /></a></div>\n";
|
||||
});
|
||||
tmpres += "</body></html>";
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
@ -199,30 +199,38 @@ http.createServer((req, res) => {
|
||||
}
|
||||
else if(Number.isInteger(parseInt(url))) { // itempage
|
||||
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1", url, (err, rows, fields) => {
|
||||
var tmpres = "";
|
||||
var tmpres = "";
|
||||
rows.forEach((e,i,a) => {
|
||||
tmpres += "ID: "+e.id+"<br />\n";
|
||||
tmpres += "src: "+e.src+"<br />\n";
|
||||
tmpres += "dest: "+e.dest+"<br />\n";
|
||||
tmpres += "mime: "+e.mime+"<br />\n";
|
||||
tmpres += "size: "+formatSize(e.size)+"<br />\n";
|
||||
tmpres += "nick: "+e.username+"<br />\n";
|
||||
tmpres += "channel: "+e.userchannel+"<br />\n";
|
||||
tmpres += "network: "+e.usernetwork+"<br />\n";
|
||||
tmpres = "<!DOCTYPE blah>\n<html>\n<head>\n<title>"+url+" - f0ck.me</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"./s/style.css\">\n</head>\n<body>\n<h4><a href='/'>f0ck.me</a></h4>\n";
|
||||
tmpres += "<div class='id'>[ID: "+e.id+" | by: "+e.username+"]</div>\n";
|
||||
tmpres += "<div class='medium'>";
|
||||
switch(e.mime) {
|
||||
case "image/png":
|
||||
case "image/jpeg":
|
||||
case "image/gif":
|
||||
tmpres += "<img src='"+e.dest+"' />";
|
||||
tmpres += "<img src='"+e.dest+"' style='max-width: 1024px' />";
|
||||
break;
|
||||
case "video/webm":
|
||||
case "video/mp4":
|
||||
tmpres += "<video src='"+e.dest+"' autoplay controls loop></video>";
|
||||
tmpres += "<video src='"+e.dest+"' style='max-width: 1024px' autoplay controls loop></video>";
|
||||
break;
|
||||
case "audio/mpeg":
|
||||
tmpres += "<audio controls src='"+e.dest+"' type='audio/mp3' autoplay></audio>";
|
||||
break;
|
||||
}
|
||||
tmpres += "</div><br />\n";
|
||||
tmpres += "<div class='controls'>controls für vor und zurück :^)</div><br />\n";
|
||||
tmpres += "<div class='info'>";
|
||||
|
||||
tmpres += "<span class='src'>src: <a href='"+e.src+"' target='_blank'>"+e.src+"</a></span><br />";
|
||||
tmpres += "<span class='dest'>dest: "+e.dest+"</span><br />";
|
||||
tmpres += "<span class='mime'>mime: "+e.mime+"</span> ";
|
||||
tmpres += "<span class='size'>size: "+formatSize(e.size)+"</span><br />";
|
||||
tmpres += "<span class='channel'>channel: "+e.userchannel+"</span> ";
|
||||
tmpres += "<span class='network'>network: "+e.usernetwork+"</span>";
|
||||
|
||||
tmpres += "</div>\n</body>\n</html>";
|
||||
|
||||
});
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
res.end(tmpres, 'utf-8');
|
||||
@ -230,6 +238,56 @@ http.createServer((req, res) => {
|
||||
}
|
||||
else if(filePath.match(/^\.\/(b|s|t)\/.*/)) { // file
|
||||
contentType = mimeTypes[extname] || 'application/octect-stream';
|
||||
|
||||
switch(contentType) {
|
||||
case "video/webm":
|
||||
case "video/mp4":
|
||||
case "audio/mpeg":
|
||||
var start = 0;
|
||||
var end = 0;
|
||||
var range = req.headers['range'];
|
||||
var stat = fs.statSync(filePath);
|
||||
if(range != null) {
|
||||
start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-')));
|
||||
end = parseInt(range.slice(range.indexOf('-')+1, range.length));
|
||||
}
|
||||
if(isNaN(end) || end == 0) end = stat.size-1;
|
||||
if(start > end) return;
|
||||
res.writeHead(206, {
|
||||
'Connection':'close',
|
||||
'Content-Type':contentType,
|
||||
'Content-Length':end - start,
|
||||
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
|
||||
// 'Accept-Ranges':'bytes',
|
||||
// 'Server':'CustomStreamer/0.0.1',
|
||||
'Transfer-Encoding':'chunked'
|
||||
});
|
||||
var stream = fs.createReadStream(filePath,
|
||||
{ flags: 'r', start: start, end: end});
|
||||
stream.pipe(res);
|
||||
break;
|
||||
default:
|
||||
fs.readFile(filePath, (error, content) => {
|
||||
if(error) {
|
||||
if(error.code == 'ENOENT') {
|
||||
res.writeHead(200, { 'Content-Type': contentType });
|
||||
res.end('404 - file not found', 'utf-8');
|
||||
}
|
||||
else {
|
||||
res.writeHead(500);
|
||||
res.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
|
||||
res.end();
|
||||
}
|
||||
}
|
||||
else {
|
||||
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': content.length });
|
||||
res.end(content, 'utf-8');
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
fs.readFile(filePath, (error, content) => {
|
||||
if(error) {
|
||||
if(error.code == 'ENOENT') {
|
||||
@ -243,8 +301,7 @@ http.createServer((req, res) => {
|
||||
}
|
||||
}
|
||||
else {
|
||||
res.writeHead(200, { 'Content-Type': contentType, 'Content-Length': content.length });
|
||||
res.end(content, 'utf-8');
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -257,28 +314,26 @@ http.createServer((req, res) => {
|
||||
|
||||
// Thumbnailbackgroundworker
|
||||
|
||||
setInterval(()=>{generateThumbs();}, 300000); // 5 minutes
|
||||
setInterval(()=>{generateThumbs();}, 60000); // 1 minute
|
||||
setTimeout(()=>{generateThumbs();}, 5000); // 5 seconds (start)
|
||||
|
||||
var generateThumbs = () => {
|
||||
var outdir = './t/';
|
||||
|
||||
if(neu) {
|
||||
sql.query("select * from `f0ck`.`items` where `thumb` = ''", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
if(!fs.existsSync(outdir+e.id+'.png')) {
|
||||
exec('ffmpegthumbnailer -i'+e.dest+' -o'+outdir+e.id+'.png -a', (error) => {
|
||||
if(error) {
|
||||
//console.log(error);
|
||||
//bot.send("#f0ck", "failed thumbnail for "+e.id, 'n0xy');
|
||||
}
|
||||
else {
|
||||
//bot.send("#f0ck", "generated thumbnail for "+e.id, 'n0xy');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
sql.query("select * from `f0ck`.`items` where `thumb` = ''", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
if(!fs.existsSync(outdir+e.id+'.png')) {
|
||||
exec('ffmpegthumbnailer -i'+e.dest+' -o'+outdir+e.id+'.png -a', (error) => {
|
||||
if(error) {
|
||||
bot.send("#f0ck", "failed thumbnail for "+e.id+" ("+e.mime+")", 'n0xy');
|
||||
fs.unlink(outdir+e.id+'.png');
|
||||
fs.copySync('./s/mp3.png', outdir+e.id+'.png');
|
||||
// Standardthumb reinkopieren
|
||||
}
|
||||
else {
|
||||
bot.send("#f0ck", "generated thumbnail for "+e.id+" ("+e.mime+")", 'n0xy');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user