From 42d1ca6f3c3c6de682596e35a5ea9cebd39dd903 Mon Sep 17 00:00:00 2001 From: ElectricS01 <103579308+ElectricS01@users.noreply.github.com> Date: Sun, 12 Feb 2023 17:01:08 +1100 Subject: [PATCH] Removed redundant code --- backend/lib/resolveEmbeds.js | 4 ++-- backend/routes/mediaproxy.js | 38 +----------------------------------- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/backend/lib/resolveEmbeds.js b/backend/lib/resolveEmbeds.js index da1350f..1819cc0 100644 --- a/backend/lib/resolveEmbeds.js +++ b/backend/lib/resolveEmbeds.js @@ -7,7 +7,7 @@ module.exports = async function (req, message) { return new Promise(async (resolve, reject) => { try { if (message.content) { - const regex = /(https?:\/\/[^\s]+)/g + const regex = /(https?:\/\/\S+)/g let links = message.content.match(regex) if (links && links.length > 3) { links = links.slice(0, 3) @@ -46,7 +46,7 @@ module.exports = async function (req, message) { }) } }) - .catch(async (e) => { + .catch(async () => { await axios .get(link, { headers: { diff --git a/backend/routes/mediaproxy.js b/backend/routes/mediaproxy.js index cc9d5fd..b305d6b 100644 --- a/backend/routes/mediaproxy.js +++ b/backend/routes/mediaproxy.js @@ -4,43 +4,7 @@ const Errors = require("../lib/errors.js") const { Message } = require("../models") const axios = require("axios") -router.get("/:mid/:index/:securityToken", async (req, res, next) => { - try { - const message = await Message.findOne({ - where: { - id: req.params.mid - } - }) - if (!message) { - throw Errors.invalidParameter("message id") - } - const embed = message.embeds.find( - (e) => e.securityToken === req.params.securityToken - ) - if (!embed) { - throw Errors.invalidParameter("securityToken") - } - await axios - .get(embed.link, { - headers: { - "user-agent": "Googlebot/2.1 (+http://www.google.com/bot.html)" - }, - responseType: "arraybuffer" - }) - .then((response) => { - res.setHeader("content-type", response.headers["content-type"]) - res.setHeader("cache-control", "public, max-age=604800") - res.end(response.data, "binary") - }) - .catch(() => { - res.status(404).end() - }) - } catch (e) { - next(e) - } -}) - -router.get("/:mid/:index/:securityToken.:extension", async (req, res, next) => { +router.get(["/:mid/:index/:securityToken","/:mid/:index/:securityToken.:extension"], async (req, res,next) => { try { const message = await Message.findOne({ where: {