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", "main": "src/main.js",
"dependencies": { "dependencies": {
"coffea": "^0.4.24", "coffea": "^0.4.24",
"mysql": "^2.11.1",
"repl": "^0.1.3", "repl": "^0.1.3",
"request": "^2.74.0",
"mysql": "^2.11.1"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -7,6 +7,9 @@ var bot = require('coffea')();
var uuid = require('uuid'); var uuid = require('uuid');
var crypto = require('crypto'); var crypto = require('crypto');
var path = require('path'); var path = require('path');
var exec = require('child_process').exec;
var neu = true;
var sql; var sql;
var haDC = () => { var haDC = () => {
@ -52,7 +55,7 @@ bot.on('message', (e) => {
getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => { getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
checkRepostCheckSum(cbcs, (cbcrcs) => { checkRepostCheckSum(cbcs, (cbcrcs) => {
if(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, entry,
"./b/"+tmpdest+"."+cb.infos.ext, "./b/"+tmpdest+"."+cb.infos.ext,
cb.infos.mime, cb.infos.mime,
@ -62,8 +65,10 @@ bot.on('message', (e) => {
e.channel.getName(), e.channel.getName(),
e.network, e.network,
Math.floor(new Date() / 1000), Math.floor(new Date() / 1000),
'',
0 0
]).on('result', (result) => { ]).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']+")"); 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) => { }).on('error', (msg) => {
e.reply(msg); e.reply(msg);
@ -177,16 +182,18 @@ http.createServer((req, res) => {
'.gif': 'image/gif', '.gif': 'image/gif',
'.mp3': 'audio/mpeg', '.mp3': 'audio/mpeg',
'.mp4': 'video/mp4', '.mp4': 'video/mp4',
'.webm': 'video/webm' '.webm': 'video/webm',
'.css': 'text/css'
}; };
if(filePath == "./index.html") { // mainpage if(filePath == "./index.html") { // mainpage
sql.query("select * from `f0ck`.`items`", (err, rows, fields) => { 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) => { 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'); res.end(tmpres, 'utf-8');
}); });
} }
@ -195,8 +202,10 @@ http.createServer((req, res) => {
var tmpres = ""; var tmpres = "";
rows.forEach((e,i,a) => { rows.forEach((e,i,a) => {
tmpres += "ID: "+e.id+"<br />\n"; tmpres += "ID: "+e.id+"<br />\n";
tmpres += "src: "+e.src+"<br />\n";
tmpres += "dest: "+e.dest+"<br />\n"; tmpres += "dest: "+e.dest+"<br />\n";
tmpres += "mime: "+e.mime+"<br />\n"; tmpres += "mime: "+e.mime+"<br />\n";
tmpres += "size: "+formatSize(e.size)+"<br />\n";
tmpres += "nick: "+e.username+"<br />\n"; tmpres += "nick: "+e.username+"<br />\n";
tmpres += "channel: "+e.userchannel+"<br />\n"; tmpres += "channel: "+e.userchannel+"<br />\n";
tmpres += "network: "+e.usernetwork+"<br />\n"; tmpres += "network: "+e.usernetwork+"<br />\n";
@ -219,7 +228,7 @@ http.createServer((req, res) => {
res.end(tmpres, 'utf-8'); 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'; contentType = mimeTypes[extname] || 'application/octect-stream';
fs.readFile(filePath, (error, content) => { fs.readFile(filePath, (error, content) => {
if(error) { if(error) {
@ -243,4 +252,33 @@ http.createServer((req, res) => {
res.writeHead(404); res.writeHead(404);
res.end('404 - not found', 'utf-8'); res.end('404 - not found', 'utf-8');
} }
}).listen(cfg.webserver.port); }).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');
}
});
}
});
});
}
};