Merge pull request #10 from ElectricS01/main

Removed redundant code
This commit is contained in:
Troplo 2023-02-12 17:01:48 +11:00 committed by GitHub
commit 1b59194a63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 39 deletions

View file

@ -7,7 +7,7 @@ module.exports = async function (req, message) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
if (message.content) { if (message.content) {
const regex = /(https?:\/\/[^\s]+)/g const regex = /(https?:\/\/\S+)/g
let links = message.content.match(regex) let links = message.content.match(regex)
if (links && links.length > 3) { if (links && links.length > 3) {
links = links.slice(0, 3) links = links.slice(0, 3)
@ -46,7 +46,7 @@ module.exports = async function (req, message) {
}) })
} }
}) })
.catch(async (e) => { .catch(async () => {
await axios await axios
.get(link, { .get(link, {
headers: { headers: {

View file

@ -4,43 +4,7 @@ const Errors = require("../lib/errors.js")
const { Message } = require("../models") const { Message } = require("../models")
const axios = require("axios") const axios = require("axios")
router.get("/:mid/:index/:securityToken", async (req, res, next) => { router.get(["/:mid/:index/:securityToken","/:mid/:index/:securityToken.:extension"], 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) => {
try { try {
const message = await Message.findOne({ const message = await Message.findOne({
where: { where: {