refactor(images): Move sponsor images to folder and load them dynamicly
This commit is contained in:
parent
99ec0933ea
commit
924f76a100
@ -82,12 +82,11 @@ func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix st
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||
sponsors := []string{
|
||||
"vrbank",
|
||||
"odit",
|
||||
"sparkasse",
|
||||
sponsors, err := ListFilesInStaticSubFolder("images/sponsors")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return GetImage(sponsors[id%len(sponsors)]), nil
|
||||
return GetImage("sponsors/" + strings.TrimSuffix(sponsors[id%len(sponsors)], ".base64")), nil
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) LoadImage(name string) (string, error) {
|
||||
|
@ -16,6 +16,22 @@ func GetTemplate(locale, templateName string) (string, error) {
|
||||
return string(content), nil
|
||||
}
|
||||
|
||||
func ListFilesInStaticSubFolder(folderName string) ([]string, error) {
|
||||
files, err := os.ReadDir(fmt.Sprintf("static/%s", folderName))
|
||||
if err != nil {
|
||||
log.Printf("error reading files from folder %s: %v", folderName, err)
|
||||
return nil, err
|
||||
}
|
||||
var images []string
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
continue
|
||||
}
|
||||
images = append(images, file.Name())
|
||||
}
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func GetImage(imageName string) string {
|
||||
content, err := os.ReadFile("static/images/" + imageName + ".base64")
|
||||
if content == nil || err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user