♻️ Refactored resources repositories
This commit is contained in:
parent
4026fb9192
commit
542348f635
|
@ -15,15 +15,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
File Path
|
|
||||||
|
|
||||||
modTime time.Time
|
modTime time.Time
|
||||||
params map[string]any // TODO(toby3d): set from Page configuration
|
params map[string]any
|
||||||
|
File Path
|
||||||
mediaType MediaType
|
mediaType MediaType
|
||||||
key string
|
key string
|
||||||
name string // TODO(toby3d): set from Page configuration
|
name string
|
||||||
title string // TODO(toby3d): set from Page configuration
|
|
||||||
resourceType ResourceType
|
resourceType ResourceType
|
||||||
|
title string
|
||||||
image image.Config
|
image image.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +68,13 @@ func (r Resource) MediaType() MediaType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Width returns width if current r is an image.
|
// Width returns width if current r is an image.
|
||||||
func (r Resource) Width() int {
|
func (r Resource) Width() uint {
|
||||||
return r.image.Width
|
return uint(r.image.Width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Height returns height if current r is an image.
|
// Height returns height if current r is an image.
|
||||||
func (r Resource) Height() int {
|
func (r Resource) Height() uint {
|
||||||
return r.image.Height
|
return uint(r.image.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Resource) ResourceType() ResourceType {
|
func (r Resource) ResourceType() ResourceType {
|
||||||
|
|
|
@ -6,26 +6,10 @@ import (
|
||||||
"source.toby3d.me/toby3d/home/internal/domain"
|
"source.toby3d.me/toby3d/home/internal/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type Repository interface {
|
||||||
Repository interface {
|
// Get returns Resource on path if exists.
|
||||||
// Get returns Resource on path if exists.
|
Get(ctx context.Context, path string) (*domain.Resource, error)
|
||||||
Get(ctx context.Context, path string) (*domain.Resource, error)
|
|
||||||
|
|
||||||
// Fetch returns all resources from dir recursevly.
|
// Fetch returns all resources from dir recursevly.
|
||||||
Fetch(ctx context.Context, pattern string) (domain.Resources, int, error)
|
Fetch(ctx context.Context, pattern string) (domain.Resources, int, error)
|
||||||
}
|
|
||||||
|
|
||||||
dummyRepository struct{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewDummyRepository() dummyRepository {
|
|
||||||
return dummyRepository{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dummyRepository) Get(ctx context.Context, path string) (*domain.Resource, error) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dummyRepository) Fetch(ctx context.Context, pattern string) (domain.Resources, int, error) {
|
|
||||||
return nil, 0, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package dummy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"source.toby3d.me/toby3d/home/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type dummyResourceRepository struct{}
|
||||||
|
|
||||||
|
func NewDummyResourceRepository() dummyResourceRepository {
|
||||||
|
return dummyResourceRepository{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dummyResourceRepository) Get(_ context.Context, _ string) (*domain.Resource, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dummyResourceRepository) Fetch(_ context.Context, _ string) (domain.Resources, int, error) {
|
||||||
|
return nil, 0, nil
|
||||||
|
}
|
|
@ -3,14 +3,8 @@ package fs
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "image/gif"
|
|
||||||
_ "image/jpeg"
|
|
||||||
_ "image/png"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
|
||||||
_ "golang.org/x/image/bmp"
|
|
||||||
_ "golang.org/x/image/webp"
|
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/home/internal/domain"
|
"source.toby3d.me/toby3d/home/internal/domain"
|
||||||
"source.toby3d.me/toby3d/home/internal/resource"
|
"source.toby3d.me/toby3d/home/internal/resource"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,17 +5,11 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "image/gif"
|
|
||||||
_ "image/jpeg"
|
|
||||||
_ "image/png"
|
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
_ "golang.org/x/image/bmp"
|
|
||||||
_ "golang.org/x/image/webp"
|
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/home/internal/domain"
|
"source.toby3d.me/toby3d/home/internal/domain"
|
||||||
"source.toby3d.me/toby3d/home/internal/static"
|
"source.toby3d.me/toby3d/home/internal/static"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue