Merge branch 'f0ckdev' into 'master'

maxfilesize * 2 for Admins

See merge request !87
This commit is contained in:
Flummi 2017-03-15 10:33:36 +00:00
commit be37a79908

View File

@ -20,7 +20,7 @@ module.exports = (lib) => {
var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
tmp.forEach((entry,i,a) => { tmp.forEach((entry,i,a) => {
if(!entry.match(/f0ck\.me/i) && !entry.match(/\.onion/i)) { if(!entry.match(/f0ck\.me/i) && !entry.match(/\.onion/i)) {
getLink(entry, ((e.message.match(/(!|-)force/i) && userlevel >= 100)?true:false), (e.message.match(/(!|-)audio/i)?true:false), (cb) => { getLink(entry, ((e.message.match(/(!|-)force/i) && userlevel >= 100)?true:false), userlevel, (cb) => {
if(cb.success === true) { if(cb.success === true) {
fs.move(cb.file, cb.file + '.' + cb.info.ext, (err) => { fs.move(cb.file, cb.file + '.' + cb.info.ext, (err) => {
if(!err) { if(!err) {
@ -64,7 +64,7 @@ module.exports = (lib) => {
desc: 'muh' desc: 'muh'
}); });
var getLink = (url, force, m4a, cb) => { var getLink = (url, force, userlevel, cb) => {
var yt = /https?:\/\/(www\.)?youtu(\.be\/|be\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi; var yt = /https?:\/\/(www\.)?youtu(\.be\/|be\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi;
var sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi; var sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi;
lib.checkRepost(url, (cbcr) => { lib.checkRepost(url, (cbcr) => {
@ -78,28 +78,22 @@ module.exports = (lib) => {
var title = inf.title; var title = inf.title;
var iurl = inf.iurl; var iurl = inf.iurl;
try { try {
//var dlformat = (m4a?'audioonly':'webm');
var dlformat;
if(m4a)
dlformat = { format: '171' };
else
dlformat = { filter: (format) => { return format.container === 'webm'; } }; dlformat = { filter: (format) => { return format.container === 'webm'; } };
ytdl.downloadFromInfo(inf, dlformat) ytdl.downloadFromInfo(inf, dlformat)
.on('response', (res) => { .on('response', (res) => {
if( ( res.headers['content-length'] <= lib.cfg.main.maxFileSize ) || force ) { if( ( res.headers['content-length'] <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 70 && res.headers['content-length'] <= (lib.cfg.main.maxFileSize * 2) ) ) {
info = { info = {
type: 'youtube', type: 'youtube',
title: title, title: title,
mime: (m4a?'audio/mpeg':'video/webm'), mime: 'video/webm',
ext: (m4a?'mp3':'webm'), ext: 'webm',
thumb: iurl thumb: iurl
}; };
} }
else { else {
res.destroy(); res.destroy();
dat.end(); dat.end();
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize( ( userlevel >= 70?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
} }
}) })
.on('error', (err) => { .on('error', (err) => {
@ -145,10 +139,9 @@ module.exports = (lib) => {
if(!err) { if(!err) {
var type = res.headers['content-type']; var type = res.headers['content-type'];
lib.log('MimeType: '+type); lib.log('MimeType: '+type);
var length = res.headers['content-length'];
if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) { if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) {
if( ( data.length <= lib.cfg.main.maxFileSize ) || force ) { if( ( data.length <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 70 && data.length <= (lib.cfg.main.maxFileSize * 2) ) ) {
var s = new Readable var s = new Readable;
s.push(data); s.push(data);
s.push(null); s.push(null);
s.pipe(dat); s.pipe(dat);
@ -162,7 +155,7 @@ module.exports = (lib) => {
} }
else { else {
dat.end(); dat.end();
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize( ( userlevel >= 70?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
} }
} }
else { else {
@ -181,7 +174,7 @@ module.exports = (lib) => {
.on('finish', () => { .on('finish', () => {
var size = dat.bytesWritten; var size = dat.bytesWritten;
dat.end(); dat.end();
if( ( size <= lib.cfg.main.maxFileSize ) || force ) { if( ( size <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 70 && size <= (lib.cfg.main.maxFileSize * 2) ) ) {
fs.stat('./b/' + tmpdest, (err, stat) => { fs.stat('./b/' + tmpdest, (err, stat) => {
if(!err && stat.isFile() && stat.size > 300) { if(!err && stat.isFile() && stat.size > 300) {
lib.log('Datei '+tmpdest+' existiert'); lib.log('Datei '+tmpdest+' existiert');
@ -204,7 +197,7 @@ module.exports = (lib) => {
}); });
} }
else { else {
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize( ( userlevel >= 70?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
} }
}) })
.on('error', (err) => { .on('error', (err) => {