feat(templates): Get static mounted images
This commit is contained in:
parent
d910a722df
commit
4deda8adf1
@ -81,7 +81,11 @@ func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix st
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||
return templates.GetImage("error"), nil
|
||||
sponsors := []string{
|
||||
"sponsoringheader",
|
||||
"odit",
|
||||
}
|
||||
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||
|
1
static/images/odit.base64
Normal file
1
static/images/odit.base64
Normal file
File diff suppressed because one or more lines are too long
1
static/images/sponsoringheader.base64
Normal file
1
static/images/sponsoringheader.base64
Normal file
File diff suppressed because one or more lines are too long
@ -3,6 +3,8 @@ package templates
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed card/en.html
|
||||
@ -44,10 +46,10 @@ func GetTemplate(locale, templateName string) (string, error) {
|
||||
}
|
||||
|
||||
func GetImage(imageName string) string {
|
||||
switch imageName {
|
||||
case "sponsoringheader":
|
||||
return ImageSponsoringHeaderBase64
|
||||
default:
|
||||
content, err := os.ReadFile("static/images/" + imageName + ".base64")
|
||||
if content == nil || err != nil {
|
||||
log.Printf("error reading image %s: %v", imageName, err)
|
||||
return ImageErrorBase64
|
||||
}
|
||||
return string(content)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user