From 7467792ae9bb3e2a6ebc2fe06e6c2f1dac489507 Mon Sep 17 00:00:00 2001 From: video-prize-ranch Date: Thu, 10 Aug 2023 02:39:15 +0000 Subject: [PATCH] Redirect links in search --- pages/search.go | 4 ++++ utils/regex.go | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 utils/regex.go diff --git a/pages/search.go b/pages/search.go index 6b8a2ec..4a2164e 100644 --- a/pages/search.go +++ b/pages/search.go @@ -13,6 +13,10 @@ func HandleSearch(c *fiber.Ctx) error { query := c.Query("q") + if utils.ImgurRe.MatchString(query) { + return c.Redirect(utils.ImgurRe.ReplaceAllString(query, "")) + } + /*page := "1" if c.Query("page") != "" { page = c.Query("page") diff --git a/utils/regex.go b/utils/regex.go new file mode 100644 index 0000000..839dd88 --- /dev/null +++ b/utils/regex.go @@ -0,0 +1,5 @@ +package utils + +import "regexp" + +var ImgurRe = regexp.MustCompile(`https?://(i\.)?imgur\.com`) \ No newline at end of file