75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"encoding/base64"
|
|
"io/fs"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"next-terminal/server/branding"
|
|
"next-terminal/server/common/maps"
|
|
"next-terminal/server/repository"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
//go:embed logos/*
|
|
var logoFS embed.FS
|
|
|
|
func Branding(c echo.Context) error {
|
|
properties := repository.PropertyRepository.FindAllMap(context.TODO())
|
|
|
|
name := branding.Name
|
|
if val, ok := properties["system-name"]; ok && val != "" && val != "-" {
|
|
name = val
|
|
}
|
|
|
|
copyright := branding.Copyright
|
|
if val, ok := properties["system-copyright"]; ok && val != "" && val != "-" {
|
|
copyright = val
|
|
}
|
|
|
|
icp := ""
|
|
if val, ok := properties["system-icp"]; ok && val != "" && val != "-" {
|
|
icp = val
|
|
}
|
|
|
|
return Success(c, maps.Map{
|
|
"name": name,
|
|
"copyright": copyright,
|
|
"icp": icp,
|
|
})
|
|
}
|
|
|
|
func Logo(c echo.Context) error {
|
|
properties := repository.PropertyRepository.FindAllMap(context.TODO())
|
|
|
|
if logo, ok := properties["system-logo"]; ok && logo != "" && logo != "-" {
|
|
if strings.HasPrefix(logo, "data:image/") {
|
|
parts := strings.SplitN(logo, ",", 2)
|
|
if len(parts) == 2 {
|
|
if imageData, err := base64.StdEncoding.DecodeString(parts[1]); err == nil {
|
|
contentType := "image/png"
|
|
if strings.Contains(parts[0], "image/jpeg") {
|
|
contentType = "image/jpeg"
|
|
} else if strings.Contains(parts[0], "image/gif") {
|
|
contentType = "image/gif"
|
|
} else if strings.Contains(parts[0], "image/svg") {
|
|
contentType = "image/svg+xml"
|
|
}
|
|
return c.Blob(http.StatusOK, contentType, imageData)
|
|
}
|
|
}
|
|
}
|
|
return c.Blob(http.StatusOK, "image/png", []byte(logo))
|
|
}
|
|
|
|
data, err := fs.ReadFile(logoFS, "logos/logo.png")
|
|
if err != nil {
|
|
return c.String(http.StatusNotFound, "Logo not found")
|
|
}
|
|
return c.Blob(http.StatusOK, "image/png", data)
|
|
}
|