From a8c16e00e422d54e52fcb630040e53026bef69e4 Mon Sep 17 00:00:00 2001 From: rasmus Date: Sat, 31 May 2025 12:30:25 +0300 Subject: [PATCH] Pass locationCompartment to Inventory Currently to avoid 'Invalid slug' in links, inventory ignores it for now. --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index c10d07d..a238a6c 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log" "net/http" "os" @@ -55,6 +56,8 @@ func lookupHandler(ctx context.Context, coll *mongo.Collection) func(w http.Resp return } + slug, locationCompartment, _ := strings.Cut(slug, "-") + if match := regexValid.MatchString(slug); !match { counterInvalidSlug.Inc() @@ -84,6 +87,11 @@ func lookupHandler(ctx context.Context, coll *mongo.Collection) func(w http.Resp redirURL = strings.Replace(redirectFound, "%s", doc.ID.Hex(), 1) } + if locationCompartment != "" { + // always expecting 0 query elements, not parsing as URL and dumb appending + redirURL += fmt.Sprintf("?locationCompartment=%s", locationCompartment) + } + http.Redirect(w, r, redirURL, 302) log.Printf("Redirecting %s to %s\n", slug, redirURL) }