new: add config redirect

This commit is contained in:
ngn 2024-05-05 22:16:02 +03:00
parent 12e3b0c2d4
commit f203d5cc51
2 changed files with 16 additions and 2 deletions

View File

@ -50,7 +50,7 @@ func main(){
app.Get("/wiki/:id", routes.WikiRoute) app.Get("/wiki/:id", routes.WikiRoute)
app.Get("/hub", routes.ConfigsRoute) app.Get("/hub", routes.ConfigsRoute)
app.Get("/hub/:id", routes.ConfigRoute) app.Get("/hub/:name", routes.ConfigRoute)
app.Get("*", func(c *fiber.Ctx) error { app.Get("*", func(c *fiber.Ctx) error {
return lib.RenderError(c, 404) return lib.RenderError(c, 404)

View File

@ -122,5 +122,19 @@ func ConfigsRoute(c *fiber.Ctx) error{
} }
func ConfigRoute(c *fiber.Ctx) error{ func ConfigRoute(c *fiber.Ctx) error{
return c.Redirect("/configs") name := c.Params("name")
configs, err := GetConfigs()
if err != nil {
log.Printf("GetConfigs failed: %s", err.Error())
return lib.RenderError(c, 500)
}
for _, cur := range configs {
if cur.Name == name {
return c.Redirect(cur.Redirect)
}
}
return lib.RenderError(c, 404)
} }