better thumbnails
This commit is contained in:
parent
415c6e9b44
commit
01f1e68888
92
src/main.js
92
src/main.js
@ -8,11 +8,13 @@ var uuid = require('uuid');
|
||||
var crypto = require('crypto');
|
||||
var path = require('path');
|
||||
var exec = require('child_process').exec;
|
||||
var probe = require('node-ffprobe');
|
||||
|
||||
var swig = require('swig');
|
||||
|
||||
var templates = {};
|
||||
var debug = false;
|
||||
var debug = true;
|
||||
var upload = true;
|
||||
var admins = [];
|
||||
|
||||
var sql;
|
||||
@ -54,7 +56,7 @@ bot.on('motd', (e) => {
|
||||
|
||||
bot.on('message', (e) => {
|
||||
var orig = e.message;
|
||||
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi) && e.channel.getName() == "#f0ck") { // shitpostcatcher
|
||||
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi) && e.channel.getName() == "#f0ck" && upload) { // shitpostcatcher
|
||||
if(!orig.match(/\!ignore$/)) {
|
||||
var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
|
||||
tmp.forEach((entry,i,a) => {
|
||||
@ -115,6 +117,16 @@ bot.on('message', (e) => {
|
||||
e.reply("debugmessages activated");
|
||||
}
|
||||
}
|
||||
else if(orig.match(/^\!toggle catcher$/)) {
|
||||
if(upload) {
|
||||
upload = false;
|
||||
e.reply("catcher deactivated");
|
||||
}
|
||||
else {
|
||||
upload = true;
|
||||
e.reply("catcher activated");
|
||||
}
|
||||
}
|
||||
else if(orig.match(/^\!load user$/)) {
|
||||
loadUser((cb) => {
|
||||
//e.reply(admins);
|
||||
@ -139,6 +151,19 @@ bot.on('message', (e) => {
|
||||
e.reply("no permission");
|
||||
});
|
||||
}
|
||||
else if(orig.match(/^\!thumbs$/i)) {
|
||||
var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names;
|
||||
getUserlevel(e, e.user.getNick(), tmp_channel, (cb) => {
|
||||
if(cb.level >= 100) {
|
||||
//exec('rm ./t/*.png', (error) => {
|
||||
e.reply("generating Thumbnails...");
|
||||
generateThumbs();
|
||||
//});
|
||||
}
|
||||
else
|
||||
e.reply("no permission");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var getUser = (u, n) => {
|
||||
@ -190,10 +215,21 @@ var dl = (url, dest, cb) => {
|
||||
response.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length'], 'ext':cfg.allowedMimes[response.headers['content-type']]}});
|
||||
probe(dest+"."+cfg.allowedMimes[response.headers['content-type']], (err, probeData) => {
|
||||
if(probeData.streams[0].height !== undefined || probeData.streams[0].width !== undefined) {
|
||||
if(probeData.streams[0].height <= cfg.minRes || probeData.streams[0].width <= cfg.minRes) {
|
||||
cb({'status':false, 'msg':'f0ck! your file is too large ('+probeData.streams[0].width+' x '+probeData.streams[0].height+'), min '+cfg.minRes+' x '+cfg.minRes+' required', 'type':1});
|
||||
}
|
||||
else
|
||||
cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length'], 'ext':cfg.allowedMimes[response.headers['content-type']]}});
|
||||
}
|
||||
else {
|
||||
cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length'], 'ext':cfg.allowedMimes[response.headers['content-type']]}});
|
||||
}
|
||||
});
|
||||
});
|
||||
file.on('error', (err) => {
|
||||
fs.unlink(dest);
|
||||
fs.unlink(dest+"."+cfg.allowedMimes[response.headers['content-type']]);
|
||||
file.close();
|
||||
cb({'status':false, 'msg':err.message, 'type':1});
|
||||
});
|
||||
@ -275,7 +311,10 @@ http.createServer((req, res) => {
|
||||
});
|
||||
}
|
||||
else if(Number.isInteger(parseInt(url))) { // itempage
|
||||
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1; select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); select `id` from `f0ck`.`items` where `id` = (select max(`id`) from `f0ck`.`items` where `id` < ?)", [url, url, url], (err, rows, fields) => {
|
||||
var query = "select * from `f0ck`.`items` where `id` = ? limit 1; " // get item
|
||||
+ "select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); " // get previous item
|
||||
+ "select `id` from `f0ck`.`items` where `id` = (select max(`id`) from `f0ck`.`items` where `id` < ?)"; // get next item
|
||||
sql.query(query, [url, url, url], (err, rows, fields) => {
|
||||
var tpl = swig.compile(templates.item);
|
||||
var data = {
|
||||
id: '',
|
||||
@ -434,16 +473,18 @@ var getTpls = () => {
|
||||
};
|
||||
};
|
||||
|
||||
var generateThumbs = () => {
|
||||
/*var generateThumbs = () => {
|
||||
var outdir = './t/';
|
||||
sql.query("select * from `f0ck`.`items` where `thumb` = ''", (err, rows, fields) => {
|
||||
var thumbnail = '';
|
||||
sql.query("select * from `f0ck`.`items`", (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) => {
|
||||
thumbnail = outdir+e.id+'.png';
|
||||
if(!fs.existsSync(thumbnail)) {
|
||||
exec('ffmpegthumbnailer -i'+e.dest+' -o'+thumbnail+' -a', (error) => {
|
||||
if(error) {
|
||||
log("failed thumbnail for "+e.id+" ("+e.mime+")");
|
||||
fs.unlink(outdir+e.id+'.png'); //
|
||||
fs.copySync('./s/mp3.png', outdir+e.id+'.png'); // copy standardthumbnail
|
||||
fs.unlink(thumbnail); //
|
||||
fs.copySync('./s/mp3.png', thumbnail); // copy standardthumbnail
|
||||
}
|
||||
else
|
||||
log("generated thumbnail for "+e.id+" ("+e.mime+")");
|
||||
@ -451,6 +492,35 @@ var generateThumbs = () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
};*/
|
||||
|
||||
var generateThumbs = () => {
|
||||
var outdir = './t/';
|
||||
sql.query("select * from `f0ck`.`items`", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
var thumbnail = outdir+e.id+'.png';
|
||||
if(!fs.existsSync(thumbnail)) {
|
||||
exec('ffmpegthumbnailer -i'+e.dest+' -s256 -o'+thumbnail, (error) => {
|
||||
if(error) {
|
||||
log('failed thumbnail for '+e.id+' ('+e.mime+') 1');
|
||||
//fs.unlink(thumbnail);
|
||||
fs.copySync('./s/mp3.png', thumbnail); // copy standardthumbnail
|
||||
}
|
||||
else {
|
||||
exec('convert '+thumbnail+' -resize "128x128^" -gravity center -crop 128x128+0+0 +repage '+thumbnail, (error) => {
|
||||
if(error) {
|
||||
log('failed thumbnail for '+e.id+' ('+e.mime+') 2');
|
||||
//fs.unlink(thumbnail);
|
||||
}
|
||||
else {
|
||||
log("generated thumbnail for "+e.id+" ("+e.mime+")");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
loadUser((cb)=>{
|
||||
|
Loading…
Reference in New Issue
Block a user