url path fix

This commit is contained in:
Arnas Udovic 2024-07-11 23:48:31 +03:00
parent d67ef9fa47
commit e1fe33ce46

View file

@ -148,7 +148,7 @@ func process(_ context.Context, w gemini.ResponseWriter, r *gemini.Request) {
urlParts := strings.Split(r.URL.Path, "/") urlParts := strings.Split(r.URL.Path, "/")
w.WriteHeader( w.WriteHeader(
gemini.StatusPermanentRedirect, gemini.StatusPermanentRedirect,
strings.Join(urlParts[:(len(urlParts)-2)], "/"), strings.Join(urlParts[:(len(urlParts)-1)], "/"),
) )
case regexp.MustCompile(`^/f/([\p{L}\d_+.]+/)+[\d\w]+/[\p{L}\d_+.]+.gmi$`).MatchString(r.URL.Path): case regexp.MustCompile(`^/f/([\p{L}\d_+.]+/)+[\d\w]+/[\p{L}\d_+.]+.gmi$`).MatchString(r.URL.Path):
renderFile(w, r, client) renderFile(w, r, client)
@ -347,7 +347,7 @@ func renderCategory(
client TreeManagerClient, client TreeManagerClient,
) { ) {
urlParts := strings.Split(strings.Trim(r.URL.Path, "/"), "/") urlParts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
path := "/" + strings.Join(urlParts[2:], "/") path := "/" + strings.Join(urlParts[1:], "/")
tr := TreeRequest{Path: &path, Filter: []*TreeRequest_Filter{}} tr := TreeRequest{Path: &path, Filter: []*TreeRequest_Filter{}}
@ -439,7 +439,7 @@ func renderAllFiles(w gemini.ResponseWriter, client TreeManagerClient) {
func renderTag(w gemini.ResponseWriter, r *gemini.Request, client TreeManagerClient) { func renderTag(w gemini.ResponseWriter, r *gemini.Request, client TreeManagerClient) {
urlParts := strings.Split(strings.Trim(r.URL.Path, "/"), "/") urlParts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
tag := urlParts[len(urlParts)-1] tag := urlParts[len(urlParts)]
tagFilter := TreeRequest_Filter{Key: "tag", Value: tag} tagFilter := TreeRequest_Filter{Key: "tag", Value: tag}
filters := []*TreeRequest_Filter{&tagFilter} filters := []*TreeRequest_Filter{&tagFilter}