teafolio/page_imageredir.go

26 lines
495 B
Go
Raw Normal View History

2022-12-31 00:47:07 +00:00
package main
import (
"fmt"
"net/http"
)
func (this *Application) Bannerpage(w http.ResponseWriter, r *http.Request, repoName string) {
ctx := r.Context()
2022-12-31 01:06:43 +00:00
images, err := this.gitea.ImageFilesForRepo(ctx, repoName)
2022-12-31 00:47:07 +00:00
if err != nil {
this.internalError(w, r, fmt.Errorf("listing images: %w", err))
return
}
if len(images) == 0 {
w.Header().Set(`Location`, `/static/no_image.png`)
w.WriteHeader(301)
return
}
w.Header().Set(`Location`, images[0].RawURL)
w.WriteHeader(301)
}