feat(fonts): add font endpoints
All checks were successful
build / Go-Build (push) Successful in 27s
All checks were successful
build / Go-Build (push) Successful in 27s
This commit is contained in:
@@ -1,12 +1,45 @@
|
||||
package routes
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"tomatentum.net/svg-templater/pkg/svg"
|
||||
)
|
||||
|
||||
func AddFont(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if r.Header.Get("Content-Type") != "font/ttf" {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user