From f203d5cc515cf74a8e0d2e86f262251a2f0829f1 Mon Sep 17 00:00:00 2001 From: ngn Date: Sun, 5 May 2024 22:16:02 +0300 Subject: [PATCH] new: add config redirect --- main.go | 2 +- routes/configs.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 8c956dc..78b9aac 100644 --- a/main.go +++ b/main.go @@ -50,7 +50,7 @@ func main(){ app.Get("/wiki/:id", routes.WikiRoute) app.Get("/hub", routes.ConfigsRoute) - app.Get("/hub/:id", routes.ConfigRoute) + app.Get("/hub/:name", routes.ConfigRoute) app.Get("*", func(c *fiber.Ctx) error { return lib.RenderError(c, 404) diff --git a/routes/configs.go b/routes/configs.go index 077e47e..73b6902 100644 --- a/routes/configs.go +++ b/routes/configs.go @@ -122,5 +122,19 @@ func ConfigsRoute(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) }