feat: images

This commit is contained in:
Florian Sylvain
2024-06-13 13:34:10 +02:00
parent eb98a1003e
commit c25fb1b0a3
19 changed files with 387 additions and 100 deletions
+3 -8
View File
@@ -1,18 +1,13 @@
package api
import (
"embed"
"github.com/go-chi/chi/v5"
"html/template"
"io/fs"
"net/http"
"path/filepath"
"strings"
)
//go:embed static
var staticFolder embed.FS
var headTmpl template.HTML
var contentTypes = map[string]string{
@@ -97,11 +92,10 @@ func InitHeadTmpl() {
func NewPageRouter() http.Handler {
r := chi.NewRouter()
contentStatic := fs.FS(staticFolder)
InitHeadTmpl()
r.Handle("/static/*", StaticFileServerWithContentType(http.FS(contentStatic)))
fileServer := StaticFileServerWithContentType(http.Dir("api/static"))
r.Handle("/static/*", http.StripPrefix("/static/", fileServer))
r.Get("/", GetLogin)
r.Get(LoginRoute, GetLoginPageHandler(EmptyLoginPage))
@@ -128,6 +122,7 @@ func NewPageRouter() http.Handler {
r.Get("/post/{id}/delete", GetPostDeletePage)
r.Get("/post/create", GetPostCreatePage)
r.Post("/post/create", PostPostCreatePage)
r.Post("/post/{id}/image/create", postImage)
})
return r