feat(upload): add first prototype of File storage, svg database and svg processing. Also added --help command
All checks were successful
build / Go-Build (push) Successful in 1m5s

This commit is contained in:
2026-02-03 00:29:08 +01:00
parent 5bd6f3b312
commit 9574c2d0bc
9 changed files with 258 additions and 37 deletions

50
pkg/svg/storage.go Normal file
View File

@@ -0,0 +1,50 @@
package svg
import (
"io"
"log"
"os"
"path/filepath"
)
type SvgStorage interface {
Create(id string, svg io.Reader) (string, error)
Get(id string) (io.Reader, error)
}
type FileSvgStorage struct {
basepath string
}
func NewFileStorage(path string) *FileSvgStorage {
err := os.MkdirAll(path, 0755)
if err != nil {
panic(err)
}
return &FileSvgStorage{path}
}
func (f FileSvgStorage) Create(id string, svg io.Reader) (string, error) {
file, err := os.Create(filepath.Join(f.basepath, id+".svg"))
if err != nil {
return "", err
}
defer file.Close()
_, err = io.Copy(file, svg)
if err != nil {
return "", err
}
log.Println("Created File: ", file.Name())
return file.Name(), nil
}
func (f FileSvgStorage) Get(id string) (io.Reader, error) {
file, err := os.Open(filepath.Join(f.basepath, "svg", id+".svg"))
if err != nil {
return nil, err
}
return file, nil
}