thumbnails :/

This commit is contained in:
Flummi 2016-08-15 17:25:50 +02:00
parent aa607db2a7
commit ff08c5e13f
2 changed files with 46 additions and 9 deletions

View File

@ -4,9 +4,8 @@
"main": "src/main.js",
"dependencies": {
"coffea": "^0.4.24",
"mysql": "^2.11.1",
"repl": "^0.1.3",
"request": "^2.74.0",
"mysql": "^2.11.1"
},
"repository": {
"type": "git",

View File

@ -7,6 +7,9 @@ var bot = require('coffea')();
var uuid = require('uuid');
var crypto = require('crypto');
var path = require('path');
var exec = require('child_process').exec;
var neu = true;
var sql;
var haDC = () => {
@ -52,7 +55,7 @@ bot.on('message', (e) => {
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 (?,?,?,?,?,?,?,?,?,?)", [
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,
@ -62,8 +65,10 @@ bot.on('message', (e) => {
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);
@ -177,16 +182,18 @@ http.createServer((req, res) => {
'.gif': 'image/gif',
'.mp3': 'audio/mpeg',
'.mp4': 'video/mp4',
'.webm': 'video/webm'
'.webm': 'video/webm',
'.css': 'text/css'
};
if(filePath == "./index.html") { // mainpage
sql.query("select * from `f0ck`.`items`", (err, rows, fields) => {
var tmpres = "";
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 += e.src+"\n";
tmpres += "<a href='./"+e.id+"'><img src='./t/"+e.id+".png' /></a>\n";
});
res.writeHead(200);
tmpres += "</body></html>";
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(tmpres, 'utf-8');
});
}
@ -195,8 +202,10 @@ http.createServer((req, res) => {
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";
@ -219,7 +228,7 @@ http.createServer((req, res) => {
res.end(tmpres, 'utf-8');
});
}
else if(filePath.match(/^\.\/b\/.*/)) { // file
else if(filePath.match(/^\.\/(b|s|t)\/.*/)) { // file
contentType = mimeTypes[extname] || 'application/octect-stream';
fs.readFile(filePath, (error, content) => {
if(error) {
@ -244,3 +253,32 @@ http.createServer((req, res) => {
res.end('404 - not found', 'utf-8');
}
}).listen(cfg.webserver.port);
// Thumbnailbackgroundworker
setInterval(()=>{generateThumbs();}, 300000); // 5 minutes
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');
}
});
}
});
});
}
};