1
Fork 0
mirror of https://github.com/diced/zipline.git synced 2025-04-11 23:31:17 -05:00

better extention figuringing outing & version update

This commit is contained in:
dicedtomatoreal 2020-08-11 15:15:58 -07:00
parent b699a0f979
commit e718506c2f
2 changed files with 7 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{
"name": "typex",
"version": "2.1.1",
"version": "2.1.3",
"scripts": {
"build": "tsc -p .",
"start": "node out/src"

View file

@ -35,20 +35,19 @@ export class APIController {
if (!users[0]) return res.status(FORBIDDEN).json({ code: FORBIDDEN, message: "Unauthorized" })
if (req.headers['authorization'] !== users[0].token) return res.status(FORBIDDEN).json({ code: FORBIDDEN, message: "Unauthorized" })
const user = users[0];
const file = req.file;
const id = randomId(config.uploader.length);
const extension = getExtension(file.mimetype);
const source = createReadStream(file.path);
if (config.uploader.blacklistedExt.includes(req.file.originalname.split('.').pop())) return res.status(BAD_REQUEST).json({ code: BAD_REQUEST, message: 'The extension used in this file is blacklisted.' })
const source = createReadStream(req.file.path);
if (!existsSync(config.uploader.upload)) mkdirSync(config.uploader.upload);
const destination = createWriteStream(`${config.upload.uploadDir}${sep}${id}.${extension}`);
const destination = createWriteStream(`${config.upload.uploadDir}${sep}${id}.${req.file.originalname.split('.').pop()}`);
source.pipe(destination, { end: false });
source.on("end", function () {
unlinkSync(file.path);
unlinkSync(req.file.path);
});
const img = await getImage(this.orm, `${req.protocol}://${req.headers['host']}${config.uploader.route}/${id}.${extension}`, user.id)
const img = await getImage(this.orm, `${req.protocol}://${req.headers['host']}${config.uploader.route}/${id}.${req.file.originalname.split('.').pop()}`, user.id)
Logger.get('TypeX.Uploader').info(`New image uploaded ${img.url} (${img.id}) by ${user.username} (${user.id})`)
if (config.discordWebhook.enabled) new DiscordWebhook(config.discordWebhook.url).sendImageUpdate(user, ImageUtil.parseURL(img.url), config);
return res.status(200).send(`${req.protocol}://${req.headers['host']}${config.uploader.route}/${id}.${extension}`)
return res.status(200).send(`${req.protocol}://${req.headers['host']}${config.uploader.route}/${id}.${req.file.originalname.split('.').pop()}`)
}
@Post('shorten')