modified: package.json

modified:   src/main.js
This commit is contained in:
Flummi 2016-08-15 22:05:20 +02:00
parent ff08c5e13f
commit 7e192acae0
2 changed files with 133 additions and 77 deletions

View File

@ -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",

View File

@ -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,7 +43,8 @@ bot.on('motd', (e) => {
bot.on('message', (e) => {
var orig = e.message;
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher
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];
@ -68,7 +67,7 @@ bot.on('message', (e) => {
'',
0
]).on('result', (result) => {
neu = true;
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);
@ -87,6 +86,7 @@ bot.on('message', (e) => {
});
});
}
}
else if(orig.match(/^\.user/)) { // (debug) get userinfos
var tmp = getUser(e.user.getNick(), e.network);
setTimeout(()=>{ e.reply(tmp); }, 1500);
@ -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' });
@ -201,28 +201,36 @@ http.createServer((req, res) => {
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1", url, (err, rows, fields) => {
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&uuml;r vor und zur&uuml;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>&nbsp;";
tmpres += "<span class='size'>size: "+formatSize(e.size)+"</span><br />";
tmpres += "<span class='channel'>channel: "+e.userchannel+"</span>&nbsp;";
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,35 @@ 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') {
@ -247,6 +284,26 @@ http.createServer((req, res) => {
res.end(content, 'utf-8');
}
});
break;
}
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 {
}
});
}
else { // errorpage
res.writeHead(404);
@ -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');
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, 'n0xy');
bot.send("#f0ck", "generated thumbnail for "+e.id+" ("+e.mime+")", 'n0xy');
}
});
}
});
});
}
};