feat(gallery): routes
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package gallery
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"path"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
|
||||
)
|
||||
|
||||
func (s *Service) GetImages(ctx context.Context) (imgs []images.Image, err error) {
|
||||
files, err := s.fs.ReadDir(s.cfg.Path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
imagePath := path.Join(s.cfg.Path, file.Name())
|
||||
img, err := s.img.GetImage(imagePath)
|
||||
if err != nil {
|
||||
slog.Warn("can not read image in gallery", "path", imagePath, "err", err)
|
||||
}
|
||||
imgs = append(imgs, img)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package gallery
|
||||
|
||||
import (
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/filesystem"
|
||||
)
|
||||
|
||||
type getImager interface {
|
||||
GetImage(path string) (img images.Image, err error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
fs filesystem.FS
|
||||
cfg *config.Gallery
|
||||
img getImager
|
||||
}
|
||||
|
||||
func New(fs filesystem.FS, cfg *config.Gallery, img getImager) *Service {
|
||||
return &Service{
|
||||
fs: fs,
|
||||
cfg: cfg,
|
||||
img: img,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user