From 0d4d150792bdeb45562dfb92e9dc69617dc31506 Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 25 May 2021 14:43:43 +0200 Subject: [PATCH] bugfix --- src/inc/trigger/parser.mjs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 58746a4..56f80ea 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -2,6 +2,7 @@ import cfg from "../../../config.json"; import sql from "../sql.mjs"; import lib from "../lib.mjs"; import { getLevel } from "../admin.mjs"; +import fetch from "flumm-fetch-cookies"; import fs from "fs"; import { exec as _exec } from "child_process"; @@ -56,8 +57,12 @@ export default async bot => { return; } - if(!cfg.ext.includes(meta.ext.toLowerCase())) - return; + if(!Object.values(cfg.mimes).includes(meta.ext.toLowerCase())) { + const tmphead = (await fetch(link, { method: "HEAD" })).headers["content-type"]; + if(!Object.keys(cfg.mimes).includes(tmphead)) + return; + meta.ext = cfg.mimes[tmphead]; + } let filename = `${uuid}.${meta.ext}`; @@ -87,28 +92,11 @@ export default async bot => { // mime check const mime = (await exec(`file --mime-type -b ./tmp/${filename}`)).stdout.trim(); - if(!cfg.allowed.includes(mime)) + if(!Object.keys(cfg.mimes).includes(mime)) return e.reply(`lol, go f0ck yourself (${mime})`); - if(!cfg.ext.includes(meta.ext)) { - let tmpext = ""; - if(mime === "image/png") - tmpext = "png"; - else if(mime === "video/webm") - tmpext = "webm"; - else if(mime === "image/gif") - tmpext = "gif"; - else if(mime === "image/jpeg") - tmpext = "jpg"; - else if(mime === "video/mp4" || mime === "video/quicktime") - tmpext = "mp4"; - else if(mime === "audio/mpeg") - tmpext = "mp3"; - else if(mime === "audio/ogg") - tmpext = "ogg"; - else if(mime === "audio/flac" || mime === "audio/x-flac") - tmpext = "flac"; - + if(!Object.values(cfg.mimes).includes(meta.ext.toLowerCase())) { + let tmpext = cfg.mimes[meta.ext.toLowerCase()]; fs.renameSync(`./tmp/${filename}`, `./tmp/${uuid}.${tmpext}`); filename = `${uuid}.${tmpext}`; } @@ -161,9 +149,7 @@ export default async bot => { speed = !Number.isFinite(speed) ? "yes" : `${speed.toFixed(2)} Mbit/s`; e.reply([ - //`title: ${meta.fulltitle}`, `link: ${cfg.main.url}/${insertq} | size: ${lib.formatSize(size)} | speed: ${speed}` - //`link: ${cfg.main.url}/${insertq}` ]); });