mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-19 10:50:25 -06:00
small refactorings
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
v0proto "github.com/owncloud/ocis-thumbnails/pkg/proto/v0"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/imgsource"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/resolution"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/resolutions"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/storage"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func NewService(opts ...Option) v0proto.ThumbnailServiceHandler {
|
||||
options := newOptions(opts...)
|
||||
logger := options.Logger
|
||||
resolutions, err := resolution.Init(options.Config.Thumbnail.Resolutions)
|
||||
resolutions, err := resolutions.New(options.Config.Thumbnail.Resolutions)
|
||||
if err != nil {
|
||||
logger.Fatal().Err(err).Msg("resolutions not configured correctly")
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler {
|
||||
// Thumbnail implements the GRPC handler.
|
||||
type Thumbnail struct {
|
||||
manager thumbnails.Manager
|
||||
resolutions resolution.Resolutions
|
||||
resolutions resolutions.Resolutions
|
||||
source imgsource.Source
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package resolution
|
||||
package resolutions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package resolution
|
||||
package resolutions
|
||||
|
||||
import "testing"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package resolution
|
||||
package resolutions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Init creates an instance of Resolutions from resolution strings.
|
||||
func Init(rStrs []string) (Resolutions, error) {
|
||||
// New creates an instance of Resolutions from resolution strings.
|
||||
func New(rStrs []string) (Resolutions, error) {
|
||||
var rs Resolutions
|
||||
for _, rStr := range rStrs {
|
||||
r, err := Parse(rStr)
|
||||
@@ -47,8 +47,7 @@ func (r Resolutions) ClosestMatch(width, height int) Resolution {
|
||||
var match Resolution
|
||||
minDiff := math.MaxInt32
|
||||
|
||||
for i := 1; i < len(r); i++ {
|
||||
current := r[i]
|
||||
for _, current := range r {
|
||||
len := dimensionLength(current, isLandscape)
|
||||
diff := givenLen - len
|
||||
if diff > 0 {
|
||||
@@ -1,11 +1,11 @@
|
||||
package resolution
|
||||
package resolutions
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInitWithEmptyArray(t *testing.T) {
|
||||
rs, err := Init([]string{})
|
||||
rs, err := New([]string{})
|
||||
if err != nil {
|
||||
t.Errorf("Init with an empty array should not fail. Error: %s.\n", err.Error())
|
||||
}
|
||||
@@ -15,7 +15,7 @@ func TestInitWithEmptyArray(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInitWithNil(t *testing.T) {
|
||||
rs, err := Init(nil)
|
||||
rs, err := New(nil)
|
||||
if err != nil {
|
||||
t.Errorf("Init with nil parameter should not fail. Error: %s.\n", err.Error())
|
||||
}
|
||||
@@ -25,14 +25,14 @@ func TestInitWithNil(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInitWithInvalidValuesInArray(t *testing.T) {
|
||||
_, err := Init([]string{"invalid"})
|
||||
_, err := New([]string{"invalid"})
|
||||
if err == nil {
|
||||
t.Error("Init with invalid parameter should fail.\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
rs, err := Init([]string{"16x16"})
|
||||
rs, err := New([]string{"16x16"})
|
||||
if err != nil {
|
||||
t.Errorf("Init with valid parameter should not fail. Error: %s.\n", err.Error())
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func TestInit(t *testing.T) {
|
||||
|
||||
func TestInitWithMultipleResolutions(t *testing.T) {
|
||||
rStrs := []string{"16x16", "32x32", "64x64", "128x128"}
|
||||
rs, err := Init(rStrs)
|
||||
rs, err := New(rStrs)
|
||||
if err != nil {
|
||||
t.Errorf("Init with valid parameter should not fail. Error: %s.\n", err.Error())
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func TestInitWithMultipleResolutions(t *testing.T) {
|
||||
|
||||
func TestInitWithMultipleResolutionsShouldBeSorted(t *testing.T) {
|
||||
rStrs := []string{"32x32", "64x64", "16x16", "128x128"}
|
||||
rs, err := Init(rStrs)
|
||||
rs, err := New(rStrs)
|
||||
if err != nil {
|
||||
t.Errorf("Init with valid parameter should not fail. Error: %s.\n", err.Error())
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func TestInitWithMultipleResolutionsShouldBeSorted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestClosestMatchWithEmptyResolutions(t *testing.T) {
|
||||
rs, _ := Init(nil)
|
||||
rs, _ := New(nil)
|
||||
width := 24
|
||||
height := 24
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestClosestMatchWithEmptyResolutions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClosestMatch(t *testing.T) {
|
||||
rs, _ := Init([]string{"16x16", "24x24", "32x32", "64x64", "128x128"})
|
||||
rs, _ := New([]string{"16x16", "24x24", "32x32", "64x64", "128x128"})
|
||||
table := [][]int{
|
||||
// width, height, expectedWidth, expectedHeight
|
||||
[]int{17, 17, 24, 24},
|
||||
@@ -1,12 +1,12 @@
|
||||
package storage
|
||||
|
||||
import "github.com/owncloud/ocis-thumbnails/pkg/thumbnails/resolution"
|
||||
import "github.com/owncloud/ocis-thumbnails/pkg/thumbnails/resolutions"
|
||||
|
||||
// Context combines different attributes needed for storage operations.
|
||||
type Context struct {
|
||||
ETag string
|
||||
Types []string
|
||||
Resolution resolution.Resolution
|
||||
Resolution resolutions.Resolution
|
||||
}
|
||||
|
||||
// Storage defines the interface for a thumbnail store.
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/resolution"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/resolutions"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnails/storage"
|
||||
)
|
||||
|
||||
// Context bundles information needed to generate a thumbnail for afile
|
||||
type Context struct {
|
||||
Resolution resolution.Resolution
|
||||
Resolution resolutions.Resolution
|
||||
ImagePath string
|
||||
Encoder Encoder
|
||||
ETag string
|
||||
|
||||
Reference in New Issue
Block a user