mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 18:20:33 +09:00
GO-3170 Merge branch 'main' of github.com:anyproto/anytype-heart into go-3170-check-objects-and-files-are-synced-with-responsible-peers-in
This commit is contained in:
commit
2b0f77b31e
8 changed files with 58 additions and 30 deletions
|
@ -2,11 +2,13 @@ package block
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/anyproto/anytype-heart/core/block/editor/smartblock"
|
||||
"github.com/anyproto/anytype-heart/core/domain"
|
||||
"github.com/anyproto/anytype-heart/core/event"
|
||||
"github.com/anyproto/anytype-heart/core/files/fileobject"
|
||||
"github.com/anyproto/anytype-heart/pb"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
|
||||
coresb "github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
|
||||
|
@ -42,7 +44,7 @@ func (s *Service) DeleteObjectByFullID(id domain.FullID) error {
|
|||
return fmt.Errorf("subobjects deprecated")
|
||||
case coresb.SmartBlockTypeFileObject:
|
||||
err = s.fileObjectService.DeleteFileData(id.ObjectID)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, fileobject.ErrEmptyFileId) {
|
||||
return fmt.Errorf("delete file data: %w", err)
|
||||
}
|
||||
err = spc.DeleteTree(context.Background(), id.ObjectID)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"image"
|
||||
"io"
|
||||
"math/big"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -90,17 +91,23 @@ func (m *ImageExif) Mill(r io.ReadSeeker, name string) (*Result, error) {
|
|||
|
||||
tag, err = exf.Get(exif.ExposureTime)
|
||||
if tag != nil {
|
||||
exposureTimeRat, _ := tag.Rat(0)
|
||||
if exposureTimeRat != nil {
|
||||
exposureTime = exposureTimeRat.String()
|
||||
num, denom, err := tag.Rat2(0)
|
||||
if err == nil {
|
||||
if denom == 0 {
|
||||
exposureTime = "inf"
|
||||
} else {
|
||||
exposureTime = big.NewRat(num, denom).String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tag, err = exf.Get(exif.FNumber)
|
||||
if tag != nil {
|
||||
fNumberRat, _ := tag.Rat(0)
|
||||
if fNumberRat != nil {
|
||||
fNumber, _ = fNumberRat.Float64()
|
||||
num, denom, err := tag.Rat2(0)
|
||||
if err == nil {
|
||||
if denom != 0 {
|
||||
fNumber, _ = big.NewRat(num, denom).Float64()
|
||||
}
|
||||
}
|
||||
}
|
||||
tag, err = exf.Get(exif.ISOSpeedRatings)
|
||||
|
|
|
@ -12,30 +12,32 @@ func TestImageExif_Mill(t *testing.T) {
|
|||
m := &ImageExif{}
|
||||
|
||||
for _, i := range testdata.Images {
|
||||
file, err := os.Open(i.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Run(i.Path, func(t *testing.T) {
|
||||
file, err := os.Open(i.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err := m.Mill(file, "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := m.Mill(file, "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var exif *ImageExifSchema
|
||||
var exif *ImageExifSchema
|
||||
|
||||
if err := json.NewDecoder(res.File).Decode(&exif); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := json.NewDecoder(res.File).Decode(&exif); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if exif.Width != i.Width {
|
||||
t.Errorf("wrong width")
|
||||
}
|
||||
if exif.Height != i.Height {
|
||||
t.Errorf("wrong height")
|
||||
}
|
||||
if exif.Format != i.Format {
|
||||
t.Errorf("wrong format")
|
||||
}
|
||||
if exif.Width != i.Width {
|
||||
t.Errorf("wrong width")
|
||||
}
|
||||
if exif.Height != i.Height {
|
||||
t.Errorf("wrong height")
|
||||
}
|
||||
if exif.Format != i.Format {
|
||||
t.Errorf("wrong format")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ func TestImageResize_Mill_ShouldNotBeReencoded(t *testing.T) {
|
|||
func TestImageResize_Mill(t *testing.T) {
|
||||
m := &ImageResize{
|
||||
Opts: ImageResizeOpts{
|
||||
Width: "200",
|
||||
Width: "100",
|
||||
Quality: "80",
|
||||
},
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ func TestImageResize_Mill(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res.Meta["width"] != 200 {
|
||||
if res.Meta["width"] != 100 {
|
||||
t.Errorf("wrong width")
|
||||
}
|
||||
|
||||
|
|
BIN
pkg/lib/mill/testdata/image_inf_exposure_time.jpeg
vendored
Normal file
BIN
pkg/lib/mill/testdata/image_inf_exposure_time.jpeg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
pkg/lib/mill/testdata/image_invalid_f_number.jpeg
vendored
Normal file
BIN
pkg/lib/mill/testdata/image_invalid_f_number.jpeg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
14
pkg/lib/mill/testdata/images.go
vendored
14
pkg/lib/mill/testdata/images.go
vendored
|
@ -51,4 +51,18 @@ var Images = []TestImage{
|
|||
Width: 1440,
|
||||
Height: 960,
|
||||
},
|
||||
{
|
||||
Path: "testdata/image_inf_exposure_time.jpeg",
|
||||
Format: "jpeg",
|
||||
HasExif: true,
|
||||
Width: 102,
|
||||
Height: 79,
|
||||
},
|
||||
{
|
||||
Path: "testdata/image_invalid_f_number.jpeg",
|
||||
Format: "jpeg",
|
||||
HasExif: true,
|
||||
Width: 102,
|
||||
Height: 79,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package bufferpool
|
|||
|
||||
import (
|
||||
"io"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -37,6 +38,7 @@ func TestBuffer_Close(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuffer_GetReadSeekCloser(t *testing.T) {
|
||||
debug.SetGCPercent(-1)
|
||||
pool := NewPool()
|
||||
buf := pool.Get()
|
||||
|
||||
|
@ -81,4 +83,5 @@ func TestBuffer_GetReadSeekCloser(t *testing.T) {
|
|||
|
||||
err = rsc.Close()
|
||||
require.NoError(t, err, "Close after Close should not return an error")
|
||||
debug.SetGCPercent(100)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue