feat: title on pages
This commit is contained in:
@@ -30,6 +30,7 @@ func (s *Service) getMime(path string) (mimeType string, err error) {
|
||||
|
||||
if mimer, ok := info.(interface{ ContentType() string }); ok {
|
||||
mimeType = mimer.ContentType()
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package images_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/config"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/test/testdata"
|
||||
"github.com/valkey-io/valkey-go"
|
||||
"github.com/valkey-io/valkey-go/mock"
|
||||
"go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
func Setup(ctx context.Context, ctrl *gomock.Controller) (*images.Service, *mock.Client) {
|
||||
valkey := mock.NewClient(ctrl)
|
||||
return images.New(testdata.FS(), &config.ImageConfig{Concurency: 1, Quality: 80}, valkey), valkey
|
||||
}
|
||||
|
||||
func BenchmarkService_GetImage(b *testing.B) {
|
||||
srv, valkeyClient := Setup(b.Context(), gomock.NewController(b))
|
||||
uid, err := images.UIDFromPath("cover.jpg")
|
||||
if err != nil {
|
||||
b.Error("could not get uid", err)
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
for b.Loop() {
|
||||
valkeyClient.EXPECT().Do(gomock.Any(), gomock.Any()).Return(mock.ErrorResult(errors.New("adf")))
|
||||
valkeyClient.EXPECT().Do(gomock.Any(), gomock.Any()).Return(mock.Result(valkey.ValkeyMessage{}))
|
||||
_, _, err = srv.GetImage(b.Context(), uid, images.Options{Width: 500, Quality: 80})
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
sourceSetSteps = 300
|
||||
sourceSetMax = 1500
|
||||
)
|
||||
|
||||
func UIDFromPath(path string) (uid string, err error) {
|
||||
var b bytes.Buffer
|
||||
// NewWriter with NoDict (nil) creates a raw DEFLATE compressor
|
||||
@@ -57,14 +62,11 @@ func PathFromUID(uid string) (string, error) {
|
||||
func SourceSet(src string) string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
const steps = 300
|
||||
const max = 1500
|
||||
|
||||
i := 1
|
||||
for {
|
||||
width := i * steps
|
||||
width := i * sourceSetSteps
|
||||
sb.WriteString(fmt.Sprintf("%s?w=%d %dw, ", src, width, width))
|
||||
if width >= max {
|
||||
if width >= sourceSetMax {
|
||||
return sb.String()
|
||||
}
|
||||
sb.WriteRune(',')
|
||||
|
||||
Reference in New Issue
Block a user