This commit is contained in:
parent
465769a00d
commit
c7c23b9e75
1 changed files with 25 additions and 0 deletions
25
main.go
25
main.go
|
@ -175,6 +175,8 @@ func process(_ context.Context, w gemini.ResponseWriter, r *gemini.Request) {
|
||||||
renderTag(w, r, client)
|
renderTag(w, r, client)
|
||||||
case regexp.MustCompile(`^/__a/`).MatchString(r.URL.Path):
|
case regexp.MustCompile(`^/__a/`).MatchString(r.URL.Path):
|
||||||
downloadAttachment(w, r, client)
|
downloadAttachment(w, r, client)
|
||||||
|
case regexp.MustCompile(`^/r/.+`).MatchString(r.URL.Path):
|
||||||
|
redirectAction(w, r, client)
|
||||||
default:
|
default:
|
||||||
w.WriteHeader(gemini.StatusNotFound, "Out of space")
|
w.WriteHeader(gemini.StatusNotFound, "Out of space")
|
||||||
}
|
}
|
||||||
|
@ -522,3 +524,26 @@ func renderTag(w gemini.ResponseWriter, r *gemini.Request, client TreeManagerCli
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func redirectAction(w gemini.ResponseWriter, r *gemini.Request, client TreeManagerClient) {
|
||||||
|
urlParts := strings.Split(r.URL.Path, "/")
|
||||||
|
id := urlParts[1]
|
||||||
|
|
||||||
|
fr := FileRequest{Id: id}
|
||||||
|
file, err := client.GetFile(context.Background(), &fr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("client.GetFile failed: %v", err)
|
||||||
|
w.WriteHeader(gemini.StatusTemporaryFailure, "Internal server error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(
|
||||||
|
gemini.StatusPermanentRedirect,
|
||||||
|
fmt.Sprintf(
|
||||||
|
"/f/%s/%s/%s",
|
||||||
|
strings.Join(file.File.Category, "/"),
|
||||||
|
file.File.Id,
|
||||||
|
file.File.GmiName(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue