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",