mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[NO-TICKET] Cleanup - remove unused code (#16828)
This commit is contained in:
committed by
GitHub
parent
57f2e7dcd4
commit
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)
|
||||
|
||||
for i := range fileData {
|
||||
img, width, height := prepareImage(fileData[i])
|
||||
img, width, _ := prepareImage(fileData[i])
|
||||
if img != nil {
|
||||
wg.Add(2)
|
||||
go func(img image.Image, path string, width int, height int) {
|
||||
go func(img image.Image, path string) {
|
||||
defer wg.Done()
|
||||
a.generateThumbnailImage(img, path, width, height)
|
||||
}(img, thumbnailPathList[i], width, height)
|
||||
a.generateThumbnailImage(img, path)
|
||||
}(img, thumbnailPathList[i])
|
||||
|
||||
go func(img image.Image, path string, width int) {
|
||||
defer wg.Done()
|
||||
@@ -1109,7 +1109,7 @@ func getImageOrientation(input io.Reader) (int, error) {
|
||||
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)
|
||||
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))
|
||||
|
||||
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -319,3 +320,32 @@ func TestCopyFileInfos(t *testing.T) {
|
||||
assert.NotEqual(t, info1.Id, info2.Id, "should not be equal")
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
if testing.Short() {
|
||||
tb.SkipNow()
|
||||
|
||||
@@ -88,7 +88,7 @@ type Actions struct {
|
||||
CreateGroupChannel func([]string, string) (*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)
|
||||
GenerateThumbnailImage func(image.Image, string, int, int)
|
||||
GenerateThumbnailImage func(image.Image, string)
|
||||
GeneratePreviewImage func(image.Image, string, int)
|
||||
InvalidateAllCaches func()
|
||||
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" {
|
||||
img, width, height := si.actions.PrepareImage(data)
|
||||
img, width, _ := si.actions.PrepareImage(data)
|
||||
if img != nil {
|
||||
si.actions.GenerateThumbnailImage(img, fileInfo.ThumbnailPath, width, height)
|
||||
si.actions.GenerateThumbnailImage(img, fileInfo.ThumbnailPath)
|
||||
si.actions.GeneratePreviewImage(img, fileInfo.PreviewPath, width)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user