This commit is contained in:
Flummi 2021-05-25 14:43:43 +02:00
parent 6c6dc7e0f8
commit 0d4d150792

View File

@ -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}`
]);
});