From a13ac57bc82937f9448f6577a18490fe58f9ba37 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Mon, 17 Oct 2022 14:57:13 +0000 Subject: [PATCH] discord_embed: Fix logging, fix 404 detection, fix big int problem with mssql (for now), fix adding back /health route --- discord_embed/api/serve.mjs | 8 ++++++-- discord_embed/api/server.mjs | 2 ++ discord_embed/package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/discord_embed/api/serve.mjs b/discord_embed/api/serve.mjs index 79066dc..7b646e2 100644 --- a/discord_embed/api/serve.mjs +++ b/discord_embed/api/serve.mjs @@ -31,7 +31,7 @@ export default class ServeHandler extends Parent { let videoLink = ctx.query.get('v') || '' let imageLink = ctx.query.get('i') || '' - if (ctx.url.match(/^\/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]+$/)) { + if (ctx.url.match(/^\/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]+$/) && ctx.url.length < 7) { try { let id = AlphabeticID.decode(ctx.url.slice(1)) if (id) { @@ -39,12 +39,16 @@ export default class ServeHandler extends Parent { if (res.first.length) { videoLink = res.first[0].video_link imageLink = res.first[0].image_link + } else { + ctx.status = 404 } } } catch (err) { - ctx.log.error(err) + ctx.log.error(err, 'Unable to fetch resource ' + ctx.url.slice(1)) ctx.state.error = 'Unknown error while fetching link.' } + } else if (ctx.url !== '/') { + ctx.status = 404 } let payload = { diff --git a/discord_embed/api/server.mjs b/discord_embed/api/server.mjs index 9b26f02..f3475e8 100644 --- a/discord_embed/api/server.mjs +++ b/discord_embed/api/server.mjs @@ -1,6 +1,7 @@ import Redis from 'ioredis' import config from '../base/config.mjs' import Parent from '../base/server.mjs' +import StaticRoutes from '../base/static_routes.mjs' import IndexPost from './post.mjs' import ServeHandler from './serve.mjs' @@ -16,6 +17,7 @@ export default class Server extends Parent { this.core.log.error(err) }) this.routes = { + static: new StaticRoutes(), post: new IndexPost({ frontend: config.get('frontend:url'), }) diff --git a/discord_embed/package.json b/discord_embed/package.json index 48b46d1..167357c 100644 --- a/discord_embed/package.json +++ b/discord_embed/package.json @@ -1,6 +1,6 @@ { "name": "discord_embed", - "version": "1.0.1", + "version": "1.0.2", "port": 4120, "description": "AV1 discord server embed helper", "main": "index.js",