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-30 03:24:29 +01:00
|
|
|
f "streifling.com/jason/cpolis/cmd/frontend"
|
2024-08-30 16:06:19 +02:00
|
|
|
)
|
|
|
|
|
2025-01-14 20:53:49 +01: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) {
|
2025-01-14 20:53:49 +01:00
|
|
|
if _, err := f.ManageSession(w, r, c, s); err != nil {
|
2024-10-30 03:24:29 +01:00
|
|
|
if !tokenIsVerified(w, r, c) {
|
|
|
|
return
|
|
|
|
}
|
2024-08-30 21:20:29 +02:00
|
|
|
}
|
2024-08-30 16:06:19 +02:00
|
|
|
|
2024-08-30 21:20:29 +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
|
|
|
}
|
2024-08-30 21:20:29 +02:00
|
|
|
|
|
|
|
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
|
2024-08-30 16:06:19 +02:00
|
|
|
}
|
|
|
|
}
|