[NO-TICKET] Cleanup - remove unused code (#16828)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
57f2e7dcd4
Коммит
a31f666019
10
app/file.go
10
app/file.go
@@ -1026,13 +1026,13 @@ func (a *App) HandleImages(previewPathList []string, thumbnailPathList []string,
|
|||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
|
|
||||||
for i := range fileData {
|
for i := range fileData {
|
||||||
img, width, height := prepareImage(fileData[i])
|
img, width, _ := prepareImage(fileData[i])
|
||||||
if img != nil {
|
if img != nil {
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
go func(img image.Image, path string, width int, height int) {
|
go func(img image.Image, path string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
a.generateThumbnailImage(img, path, width, height)
|
a.generateThumbnailImage(img, path)
|
||||||
}(img, thumbnailPathList[i], width, height)
|
}(img, thumbnailPathList[i])
|
||||||
|
|
||||||
go func(img image.Image, path string, width int) {
|
go func(img image.Image, path string, width int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
@@ -1109,7 +1109,7 @@ func getImageOrientation(input io.Reader) (int, error) {
|
|||||||
return orientation, nil
|
return orientation, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) generateThumbnailImage(img image.Image, thumbnailPath string, width int, height int) {
|
func (a *App) generateThumbnailImage(img image.Image, thumbnailPath string) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := jpeg.Encode(buf, genThumbnail(img), &jpeg.Options{Quality: 90}); err != nil {
|
if err := jpeg.Encode(buf, genThumbnail(img), &jpeg.Options{Quality: 90}); err != nil {
|
||||||
mlog.Error("Unable to encode image as jpeg", mlog.String("path", thumbnailPath), mlog.Err(err))
|
mlog.Error("Unable to encode image as jpeg", mlog.String("path", thumbnailPath), mlog.Err(err))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -319,3 +320,32 @@ func TestCopyFileInfos(t *testing.T) {
|
|||||||
assert.NotEqual(t, info1.Id, info2.Id, "should not be equal")
|
assert.NotEqual(t, info1.Id, info2.Id, "should not be equal")
|
||||||
assert.Equal(t, info2.PostId, "", "should be empty string")
|
assert.Equal(t, info2.PostId, "", "should be empty string")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateThumbnailImage(t *testing.T) {
|
||||||
|
t.Run("test generating thumbnail image", func(t *testing.T) {
|
||||||
|
// given
|
||||||
|
th := Setup(t)
|
||||||
|
defer th.TearDown()
|
||||||
|
img := createDummyImage()
|
||||||
|
dataPath, _ := fileutils.FindDir("data")
|
||||||
|
thumbailName := "thumb.jpg"
|
||||||
|
thumbnailPath := filepath.Join(dataPath, thumbailName)
|
||||||
|
|
||||||
|
// when
|
||||||
|
th.App.generateThumbnailImage(img, thumbailName)
|
||||||
|
defer os.Remove(thumbnailPath)
|
||||||
|
|
||||||
|
// then
|
||||||
|
outputImage, err := os.Stat(thumbnailPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, int64(957), outputImage.Size())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func createDummyImage() *image.RGBA {
|
||||||
|
width := 200
|
||||||
|
height := 100
|
||||||
|
upperLeftCorner := image.Point{0, 0}
|
||||||
|
lowerRightCorner := image.Point{width, height}
|
||||||
|
return image.NewRGBA(image.Rectangle{upperLeftCorner, lowerRightCorner})
|
||||||
|
}
|
||||||
|
|||||||
@@ -133,18 +133,6 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
|||||||
return th
|
return th
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupEnterprise(tb testing.TB) *TestHelper {
|
|
||||||
if testing.Short() {
|
|
||||||
tb.SkipNow()
|
|
||||||
}
|
|
||||||
dbStore := mainHelper.GetStore()
|
|
||||||
dbStore.DropAllTables()
|
|
||||||
dbStore.MarkSystemRanUnitTests()
|
|
||||||
mainHelper.PreloadMigrations()
|
|
||||||
|
|
||||||
return setupTestHelper(dbStore, true, true, tb, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Setup(tb testing.TB) *TestHelper {
|
func Setup(tb testing.TB) *TestHelper {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
tb.SkipNow()
|
tb.SkipNow()
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ type Actions struct {
|
|||||||
CreateGroupChannel func([]string, string) (*model.Channel, *model.AppError)
|
CreateGroupChannel func([]string, string) (*model.Channel, *model.AppError)
|
||||||
CreateChannel func(*model.Channel, bool) (*model.Channel, *model.AppError)
|
CreateChannel func(*model.Channel, bool) (*model.Channel, *model.AppError)
|
||||||
DoUploadFile func(time.Time, string, string, string, string, []byte) (*model.FileInfo, *model.AppError)
|
DoUploadFile func(time.Time, string, string, string, string, []byte) (*model.FileInfo, *model.AppError)
|
||||||
GenerateThumbnailImage func(image.Image, string, int, int)
|
GenerateThumbnailImage func(image.Image, string)
|
||||||
GeneratePreviewImage func(image.Image, string, int)
|
GeneratePreviewImage func(image.Image, string, int)
|
||||||
InvalidateAllCaches func()
|
InvalidateAllCaches func()
|
||||||
MaxPostSize func() int
|
MaxPostSize func() int
|
||||||
@@ -771,9 +771,9 @@ func (si *SlackImporter) oldImportFile(timestamp time.Time, file io.Reader, team
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fileInfo.IsImage() && fileInfo.MimeType != "image/svg+xml" {
|
if fileInfo.IsImage() && fileInfo.MimeType != "image/svg+xml" {
|
||||||
img, width, height := si.actions.PrepareImage(data)
|
img, width, _ := si.actions.PrepareImage(data)
|
||||||
if img != nil {
|
if img != nil {
|
||||||
si.actions.GenerateThumbnailImage(img, fileInfo.ThumbnailPath, width, height)
|
si.actions.GenerateThumbnailImage(img, fileInfo.ThumbnailPath)
|
||||||
si.actions.GeneratePreviewImage(img, fileInfo.PreviewPath, width)
|
si.actions.GeneratePreviewImage(img, fileInfo.PreviewPath, width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user