discord_embed: Fix encodeURIComponent on url stuff
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded

discord_embed: Create a test redirect
This commit is contained in:
Jonatan Nilsson 2022-10-29 12:03:30 +00:00
parent 3a60332bdf
commit 17e266e89a
5 changed files with 47 additions and 16 deletions

View file

@ -6,7 +6,7 @@ export default class StaticRoutes {
} }
register(server) { register(server) {
server.flaska.get('/health', this.health.bind(this)) server.flaska.get('/api/health', this.health.bind(this))
} }
health(ctx) { health(ctx) {

View file

@ -16,6 +16,40 @@ export default class IndexPost {
server.flaska.post('/', [ server.flaska.post('/', [
server.formidable({ maxFileSize: 8 * 1024 * 1024, }), server.formidable({ maxFileSize: 8 * 1024 * 1024, }),
], this.createNewLink.bind(this)) ], this.createNewLink.bind(this))
server.flaska.get('/video/:id', this.videoRedirect.bind(this))
}
async videoRedirect(ctx) {
try {
let id = AlphabeticID.decode(ctx.params.id)
let videoLink = null
if (id) {
let res = await ctx.db.safeCallProc('discord_embed.link_get', [id - 3843])
if (res.first.length) {
videoLink = res.first[0].video_link
} else {
ctx.status = 404
}
}
if (videoLink) {
ctx.status = 302
ctx.headers['Location'] = videoLink
ctx.type = 'application/octet-stream'
ctx.body = `
Redirecting
<a href="${videoLink}">Click here if it doesn't redirect</a>
`
return
} else {
ctx.status = 404
ctx.state.error = 'Video not found.'
}
} catch (err) {
ctx.log.error(err, 'Unable to fetch resource ' + ctx.url.slice(1))
ctx.state.error = 'Unknown error while fetching link.'
}
return this.serve.serveIndex(ctx)
} }
hasErrors(ctx, hasMedia) { hasErrors(ctx, hasMedia) {
@ -96,8 +130,6 @@ export default class IndexPost {
if (!error) { if (!error) {
try { try {
let id = 'health'
while (id === 'health') {
let params = [ let params = [
ctx.state.video, ctx.state.video,
ctx.state.image, ctx.state.image,
@ -105,7 +137,6 @@ export default class IndexPost {
] ]
let res = await ctx.db.safeCallProc('discord_embed.link_add', params) let res = await ctx.db.safeCallProc('discord_embed.link_add', params)
id = AlphabeticID.encode(res.first[0].id + 3843) id = AlphabeticID.encode(res.first[0].id + 3843)
}
redirect = `${this.frontend}/${id}` redirect = `${this.frontend}/${id}`
} }
catch (err) { catch (err) {

View file

@ -37,8 +37,8 @@ export default class ServeHandler extends Parent {
if (id) { if (id) {
let res = await ctx.db.safeCallProc('discord_embed.link_get', [id - 3843]) let res = await ctx.db.safeCallProc('discord_embed.link_get', [id - 3843])
if (res.first.length) { if (res.first.length) {
videoLink = res.first[0].video_link videoLink = encodeURIComponent(res.first[0].video_link)
imageLink = res.first[0].image_link imageLink = encodeURIComponent(res.first[0].image_link)
} else { } else {
ctx.status = 404 ctx.status = 404
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "discord_embed", "name": "discord_embed",
"version": "1.0.4", "version": "1.0.5",
"port": 4120, "port": 4120,
"description": "AV1 discord server embed helper", "description": "AV1 discord server embed helper",
"main": "index.js", "main": "index.js",

View file

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Discord Embedder from AV1 server 1.0.4</title> <title>Discord Embedder from AV1 server 1.0.5</title>
<base href="/"> <base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
{{ if (imageLink) { }} {{ if (imageLink) { }}
@ -226,7 +226,7 @@ video {
if (isExample) { if (isExample) {
generateurl.innerText = baseSite + '?v=<video link>&i=<image link>'; generateurl.innerText = baseSite + '?v=<video link>&i=<image link>';
} else { } else {
generateurl.innerText = baseSite + '?v=' + encodeURI(inputVideo.value) + '&i=' + encodeURI(inputImage.value); generateurl.innerText = baseSite + '?v=' + encodeURIComponent(inputVideo.value) + '&i=' + encodeURIComponent(inputImage.value);
} }
}; };