Merge branch 'dev' into feat/template
All checks were successful
build / Go-Build (push) Successful in 1m8s
build / Go-Build (pull_request) Successful in 28s

This commit is contained in:
2026-02-12 19:46:30 +01:00
6 changed files with 134 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ func HandleCommandline() {
flag.Parse()
if !help {
svg.Storage = svg.NewFileStorage(datapath, "public")
svg.Storage = svg.NewFileStorage(datapath, "public", "fonts")
if err := database.OpenSQLite(datapath); err != nil {
log.Fatal("Failed opening DB:\n", err)
return
@@ -43,6 +43,7 @@ func HandleCommandline() {
} else if help {
flag.PrintDefaults()
} else {
svg.Storage = svg.NewFileStorage(datapath, "public", "fonts")
server.PrepareHTTP()
server.Start()
}

45
internal/routes/font.go Normal file
View File

@@ -0,0 +1,45 @@
package routes
import (
"encoding/json"
"log"
"net/http"
"strings"
"tomatentum.net/svg-templater/pkg/svg"
)
func AddFont(w http.ResponseWriter, r *http.Request) {
contentType := r.Header.Get("Content-Type")
if contentType != "font/ttf" && contentType != "font/otf" {
http.Error(w, "", http.StatusUnsupportedMediaType)
return
}
log.Println("Received font add request")
format := strings.TrimPrefix(contentType, "font/")
if err := svg.Storage.AddFont(r.Body, format); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(err)
return
}
}
func GetFonts(w http.ResponseWriter, r *http.Request) {
log.Println("Serving all available fonts")
fonts, err := svg.Storage.GetFonts()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(err)
return
}
json, err := json.Marshal(fonts)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Println(err)
return
}
w.Header().Add("Content-Type", "application/json")
w.Write(json)
}

View File

@@ -28,6 +28,14 @@ func PrepareHTTP() {
}
routes.DownloadSVG(w, r)
})
registerAuthorizedFunc("/font/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
routes.GetFonts(w, r)
case "POST":
routes.AddFont(w, r)
}
})
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(svg.Storage.GetPublicDir())))
}