Move images.go from frontend to calls

This commit is contained in:
2024-08-30 16:06:19 +02:00
parent 2b2ab0d428
commit a33e7f9896
5 changed files with 28 additions and 30 deletions

24
cmd/calls/images.go Normal file
View File

@ -0,0 +1,24 @@
package calls
import (
"log"
"net/http"
"path/filepath"
b "streifling.com/jason/cpolis/cmd/backend"
)
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if tokenIsVerified(w, r, c) {
absFilepath, err := filepath.Abs(c.PicsDir)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
}
}
}