11
0

Pass locationCompartment to Inventory
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

Currently to avoid 'Invalid slug' in links, inventory ignores it for now.
This commit is contained in:
2025-05-31 12:30:25 +03:00
parent 81240636e2
commit a8c16e00e4

View File

@@ -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)
}