feat(template): add multi page upload capability
build / Go-Build (push) Successful in 1m30s

This commit is contained in:
2026-05-27 00:59:25 +02:00
parent 7017af9f3f
commit 2aab1bcdd2
11 changed files with 306 additions and 89 deletions
+23 -12
View File
@@ -13,12 +13,13 @@ import (
)
type SvgStorage interface {
Create(id string, svg io.Reader) (string, error)
Get(id string) (io.ReadCloser, error)
Delete(id string) error
Create(name string, svg io.Reader) (string, error)
Get(name string) (io.ReadCloser, error)
Delete(name string) error
List() ([]os.DirEntry, error)
AddFont(reader io.Reader, format string) error
GetFonts() ([]string, error)
GetFontsDir() (string, error)
GetFontsDir() string
CreatePublic(data io.Reader, filetype string) (string, error)
GetPublic(path string) (io.ReadCloser, error)
GetPublicDir() http.Dir
@@ -44,8 +45,8 @@ func NewFileStorage(path, publicSubPath, fontssubpath string) *FileSvgStorage {
return &FileSvgStorage{path, publicSubPath, fontssubpath}
}
func (f FileSvgStorage) Create(id string, svg io.Reader) (string, error) {
file, err := os.Create(filepath.Join(f.basepath, id+".svg"))
func (f FileSvgStorage) Create(name string, svg io.Reader) (string, error) {
file, err := os.Create(filepath.Join(f.basepath, name+".svg"))
if err != nil {
return "", err
@@ -61,20 +62,30 @@ func (f FileSvgStorage) Create(id string, svg io.Reader) (string, error) {
return file.Name(), nil
}
func (f FileSvgStorage) Get(id string) (io.ReadCloser, error) {
file, err := os.Open(filepath.Join(f.basepath, id+".svg"))
func (f FileSvgStorage) Get(name string) (io.ReadCloser, error) {
file, err := os.Open(filepath.Join(f.basepath, name+".svg"))
if err != nil {
return nil, err
}
return file, nil
}
func (f FileSvgStorage) Delete(id string) error {
path := filepath.Join(f.basepath, id+".svg")
func (f FileSvgStorage) Delete(name string) error {
var path string
if strings.HasSuffix(name, ".svg") {
path = filepath.Join(f.basepath, name)
} else {
path = filepath.Join(f.basepath, name+".svg")
}
defer log.Println("Deleted File: " + path)
return os.Remove(path)
}
func (f FileSvgStorage) List() ([]os.DirEntry, error) {
return os.ReadDir(f.basepath)
}
func (f FileSvgStorage) CreatePublic(data io.Reader, filetype string) (string, error) {
path := filepath.Join(f.basepath, f.publicSubPath)
if err := os.MkdirAll(path, 0755); err != nil {
@@ -164,8 +175,8 @@ func (f FileSvgStorage) GetFonts() ([]string, error) {
return fonts, nil
}
func (f FileSvgStorage) GetFontsDir() (string, error) {
return filepath.Join(f.basepath, f.fontssubpath), nil
func (f FileSvgStorage) GetFontsDir() string {
return filepath.Join(f.basepath, f.fontssubpath)
}
func getFontName(svgblob []byte) (string, error) {