cpolis/cmd/calls/images.go

27 lines
485 B
Go
Raw Normal View History

2024-08-30 16:06:19 +02:00
package calls
import (
"log"
"net/http"
"path/filepath"
b "streifling.com/jason/cpolis/cmd/backend"
)
2024-10-27 15:12:30 +01:00
func ServeImage(c *b.Config) http.HandlerFunc {
2024-08-30 16:06:19 +02:00
return func(w http.ResponseWriter, r *http.Request) {
if !tokenIsVerified(w, r, c) {
return
}
2024-08-30 16:06:19 +02:00
absFilepath, err := filepath.Abs(c.PicsDir)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
2024-08-30 16:06:19 +02:00
}
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
2024-08-30 16:06:19 +02:00
}
}