cpolis/cmd/calls/images.go

30 lines
620 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"
f "streifling.com/jason/cpolis/cmd/frontend"
2024-08-30 16:06:19 +02:00
)
func ServeImage(c *b.Config, s map[string]*f.Session) http.HandlerFunc {
2024-08-30 16:06:19 +02:00
return func(w http.ResponseWriter, r *http.Request) {
if _, err := f.ManageSession(w, r, c, s); err != nil {
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
}
}