hoffentlich klappt das xD

This commit is contained in:
Flummi 2016-11-02 17:16:06 +01:00
parent 53a8ad26bc
commit 38511be786

View File

@ -48,9 +48,14 @@ module.exports = (lib) => {
} }
}); });
} }
else else {
if(cb.msg !== '') if(path.existsSync('./b/' + cb.file)) {
e.reply(cb.msg); fs.unlinkSync('./b/' + cb.file);
if(cb.msg !== '') {
e.reply(cb.msg);
}
}
}
}); });
} }
}); });
@ -64,8 +69,8 @@ module.exports = (lib) => {
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) => {
var tmpdest = uuid.v1().split('-')[0];
if(cbcr === true) { if(cbcr === true) {
var tmpdest = uuid.v1().split('-')[0];
var dat = fs.createWriteStream('./b/' + tmpdest); var dat = fs.createWriteStream('./b/' + tmpdest);
var info; var info;
@ -80,8 +85,7 @@ module.exports = (lib) => {
if(res.headers['content-length'] > cfg.maxFileSize) { if(res.headers['content-length'] > cfg.maxFileSize) {
res.destroy(); res.destroy();
dat.close(); dat.close();
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
} }
else { else {
info = { info = {
@ -95,15 +99,13 @@ module.exports = (lib) => {
}) })
.on('error', (err) => { .on('error', (err) => {
dat.close(); dat.close();
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: ex });
cb({ success: false, msg: ex });
}) })
.pipe(dat); .pipe(dat);
} }
catch(ex) { catch(ex) {
//dat.close(); dat.close();
//fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: ex.message });
cb({ success: false, msg: ex.message });
} }
} }
}); });
@ -124,8 +126,7 @@ module.exports = (lib) => {
} }
else { else {
dat.close(); dat.close();
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: 'f0ck sc-api' });
cb({ success: false, msg: 'f0ck sc-api' });
} }
}); });
} }
@ -141,7 +142,6 @@ module.exports = (lib) => {
lib.log('MimeType: '+type); lib.log('MimeType: '+type);
var length = res.headers['content-length']; var length = res.headers['content-length'];
if(cfg.allowedMimes.hasOwnProperty(type)) { if(cfg.allowedMimes.hasOwnProperty(type)) {
//if(length <= cfg.maxFileSize) {
if(data.length <= cfg.maxFileSize) { if(data.length <= cfg.maxFileSize) {
var s = new Readable var s = new Readable
s.push(data); s.push(data);
@ -157,20 +157,17 @@ module.exports = (lib) => {
} }
else { else {
dat.close(); dat.close();
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
} }
} }
else { else {
dat.close(); dat.close();
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: '' });
cb({ success: false, msg: '' });
} }
} }
else { else {
dat.close(); dat.close();
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: err });
cb({ success: false, msg: err });
} }
}); });
} }
@ -180,7 +177,7 @@ module.exports = (lib) => {
var size = dat.bytesWritten; var size = dat.bytesWritten;
dat.close(); dat.close();
if(size > cfg.maxFileSize) if(size > cfg.maxFileSize)
cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' }); cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
else { else {
lib.getCheckSum('./b/' + tmpdest, (cbcs) => { lib.getCheckSum('./b/' + tmpdest, (cbcs) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => { lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
@ -189,21 +186,20 @@ module.exports = (lib) => {
if(cfg.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud') if(cfg.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud')
cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs }); cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs });
else else
cb({ success: false, msg: 'lol, go f0ck yourself ('+mime+')' }); cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime+')' });
} }
else else
cb({ success: false, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs }); cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs });
}); });
}); });
} }
}) })
.on('error', (err) => { .on('error', (err) => {
fs.unlinkSync('./b/' + tmpdest); cb({ success: false, file: tmpdest, msg: err });
cb({ success: false, msg: err });
}); });
} }
else else
cb({ success: false, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr }); cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr });
}); });
}; };
}; };