added the default button set to the image server
This commit is contained in:
+21
-6
@@ -17,11 +17,16 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
)
|
||||
|
||||
//go:embed static_images/*
|
||||
var static_images embed.FS
|
||||
|
||||
//go:embed buttons/*
|
||||
var buttons embed.FS
|
||||
|
||||
/* mimeTypeFromFilenane returns the MIME type of a file, given its filename.
|
||||
* Parameters:
|
||||
* filaname - The name of the file to be tested.
|
||||
@@ -43,12 +48,22 @@ func mimeTypeFromFilename(filename string) string {
|
||||
func AmServeImage(ctxt AmContext) (string, any, error) {
|
||||
components := strings.SplitAfter(ctxt.URLPath(), "/")
|
||||
var err error = nil
|
||||
if len(components) == 4 && components[2] == "builtin/" {
|
||||
var b []byte
|
||||
b, err = static_images.ReadFile(filepath.Join("static_images", components[3]))
|
||||
if err == nil {
|
||||
ctxt.SetOutputType(mimeTypeFromFilename(components[3]))
|
||||
return "bytes", b, nil
|
||||
var b []byte
|
||||
if len(components) == 4 {
|
||||
if components[2] == "builtin/" {
|
||||
b, err = static_images.ReadFile(filepath.Join("static_images", components[3]))
|
||||
if err == nil {
|
||||
ctxt.SetOutputType(mimeTypeFromFilename(components[3]))
|
||||
return "bytes", b, nil
|
||||
}
|
||||
}
|
||||
if components[2] == "button/" {
|
||||
b, err = buttons.ReadFile(filepath.Join("buttons", config.GlobalConfig.Rendering.ButtonSet,
|
||||
components[3]))
|
||||
if err == nil {
|
||||
ctxt.SetOutputType(mimeTypeFromFilename(components[3]))
|
||||
return "bytes", b, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
ctxt.SetRC(http.StatusNotFound)
|
||||
|
||||
Reference in New Issue
Block a user