коммит произвёл
GitHub
родитель
22a00104bd
Коммит
4210ae60ab
@@ -5,11 +5,10 @@ package api4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
@@ -222,13 +221,13 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
// Upload a bunch of files, mixed images and non-images
|
// Upload a bunch of files, mixed images and non-images
|
||||||
{
|
{
|
||||||
title: "Happy",
|
title: "Happy",
|
||||||
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test_compressed_tiff.tiff"},
|
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test.tiff"},
|
||||||
expectedCreatorId: th.BasicUser.Id,
|
expectedCreatorId: th.BasicUser.Id,
|
||||||
},
|
},
|
||||||
// Upload a bunch of files, with clientIds
|
// Upload a bunch of files, with clientIds
|
||||||
{
|
{
|
||||||
title: "Happy client_ids",
|
title: "Happy client_ids",
|
||||||
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test_compressed_tiff.tiff"},
|
names: []string{"test.png", "testgif.gif", "testplugin.tar.gz", "test-search.md", "test.tiff"},
|
||||||
clientIds: []string{"1", "2", "3", "4", "5"},
|
clientIds: []string{"1", "2", "3", "4", "5"},
|
||||||
expectedCreatorId: th.BasicUser.Id,
|
expectedCreatorId: th.BasicUser.Id,
|
||||||
},
|
},
|
||||||
@@ -357,18 +356,7 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
// TIFF preview test
|
// TIFF preview test
|
||||||
{
|
{
|
||||||
title: "Happy image thumbnail/preview 9",
|
title: "Happy image thumbnail/preview 9",
|
||||||
names: []string{"test_compressed_tiff.tiff"},
|
names: []string{"test.tiff"},
|
||||||
expectedImageThumbnailNames: []string{"test_expected_tiff_thumb.jpeg"},
|
|
||||||
expectedImagePreviewNames: []string{"test_expected_tiff_preview.jpeg"},
|
|
||||||
expectImage: true,
|
|
||||||
expectedImageWidths: []int{701},
|
|
||||||
expectedImageHeights: []int{701},
|
|
||||||
expectedImageHasPreview: []bool{true},
|
|
||||||
expectedCreatorId: th.BasicUser.Id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "Happy image thumbnail/preview 10",
|
|
||||||
names: []string{"test_raw_tiff.tiff"},
|
|
||||||
expectedImageThumbnailNames: []string{"test_expected_tiff_thumb.jpeg"},
|
expectedImageThumbnailNames: []string{"test_expected_tiff_thumb.jpeg"},
|
||||||
expectedImagePreviewNames: []string{"test_expected_tiff_preview.jpeg"},
|
expectedImagePreviewNames: []string{"test_expected_tiff_preview.jpeg"},
|
||||||
expectImage: true,
|
expectImage: true,
|
||||||
@@ -625,12 +613,7 @@ func TestUploadFiles(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
_, err = io.Copy(tf, bytes.NewReader(data))
|
_, err = io.Copy(tf, bytes.NewReader(data))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
if strings.Contains(name, "test_expected_tiff") {
|
t.Errorf("Actual data mismatched %s, written to %q - expected %d bytes, got %d.", name, tf.Name(), len(expected), len(data))
|
||||||
// TODO: remove this once MM-22056 is fixed.
|
|
||||||
t.Errorf("Actual data mismatched %s, written to %q - expected %d bytes, got %d. Previewer Image: \n\n%s\n", name, tf.Name(), len(expected), len(data), hex.Dump(data))
|
|
||||||
} else {
|
|
||||||
t.Errorf("Actual data mismatched %s, written to %q - expected %d bytes, got %d.", name, tf.Name(), len(expected), len(data))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(tc.expectedPayloadNames) == 0 {
|
if len(tc.expectedPayloadNames) == 0 {
|
||||||
@@ -767,9 +750,6 @@ func TestGetFileThumbnail(t *testing.T) {
|
|||||||
|
|
||||||
fileId := fileResp.FileInfos[0].Id
|
fileId := fileResp.FileInfos[0].Id
|
||||||
|
|
||||||
// Wait a bit for files to ready
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
|
||||||
data, resp := Client.GetFileThumbnail(fileId)
|
data, resp := Client.GetFileThumbnail(fileId)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.NotEqual(t, 0, len(data), "should not be empty")
|
require.NotEqual(t, 0, len(data), "should not be empty")
|
||||||
@@ -826,9 +806,6 @@ func TestGetFileLink(t *testing.T) {
|
|||||||
_, resp = Client.GetFileLink(fileId)
|
_, resp = Client.GetFileLink(fileId)
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
|
|
||||||
// Wait a bit for files to ready
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
|
||||||
link, resp := Client.GetFileLink(fileId)
|
link, resp := Client.GetFileLink(fileId)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -875,9 +852,6 @@ func TestGetFilePreview(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
fileId := fileResp.FileInfos[0].Id
|
fileId := fileResp.FileInfos[0].Id
|
||||||
|
|
||||||
// Wait a bit for files to ready
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
|
||||||
data, resp := Client.GetFilePreview(fileId)
|
data, resp := Client.GetFilePreview(fileId)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.NotEqual(t, 0, len(data), "should not be empty")
|
require.NotEqual(t, 0, len(data), "should not be empty")
|
||||||
@@ -920,9 +894,6 @@ func TestGetFileInfo(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
fileId := fileResp.FileInfos[0].Id
|
fileId := fileResp.FileInfos[0].Id
|
||||||
|
|
||||||
// Wait a bit for files to ready
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
|
||||||
info, resp := Client.GetFileInfo(fileId)
|
info, resp := Client.GetFileInfo(fileId)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
@@ -980,9 +951,6 @@ func TestGetPublicFile(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
link := th.App.GeneratePublicLink(Client.Url, info)
|
link := th.App.GeneratePublicLink(Client.Url, info)
|
||||||
|
|
||||||
// Wait a bit for files to ready
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
|
||||||
resp, err := http.Get(link)
|
resp, err := http.Get(link)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode, "failed to get image with public link")
|
require.Equal(t, http.StatusOK, resp.StatusCode, "failed to get image with public link")
|
||||||
|
|||||||
25
app/file.go
25
app/file.go
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
"github.com/rwcarlsen/goexif/exif"
|
"github.com/rwcarlsen/goexif/exif"
|
||||||
_ "golang.org/x/image/bmp"
|
_ "golang.org/x/image/bmp"
|
||||||
|
_ "golang.org/x/image/tiff"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
@@ -796,29 +797,29 @@ func (t *UploadFileTask) postprocessImage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jpegQuality = 90
|
||||||
writeJPEG := func(img image.Image, path string) {
|
writeJPEG := func(img image.Image, path string) {
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
go func() {
|
go func() {
|
||||||
_, aerr := t.writeFile(r, path)
|
err := jpeg.Encode(w, img, &jpeg.Options{Quality: jpegQuality})
|
||||||
if aerr != nil {
|
if err != nil {
|
||||||
mlog.Error("Unable to upload", mlog.String("path", path), mlog.Err(aerr))
|
mlog.Error("Unable to encode image as jpeg", mlog.String("path", path), mlog.Err(err))
|
||||||
return
|
w.CloseWithError(err)
|
||||||
|
} else {
|
||||||
|
w.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
_, aerr := t.writeFile(r, path)
|
||||||
err := jpeg.Encode(w, img, &jpeg.Options{Quality: 90})
|
if aerr != nil {
|
||||||
if err != nil {
|
mlog.Error("Unable to upload", mlog.String("path", path), mlog.Err(aerr))
|
||||||
mlog.Error("Unable to encode image as jpeg", mlog.String("path", path), mlog.Err(err))
|
return
|
||||||
w.CloseWithError(err)
|
|
||||||
} else {
|
|
||||||
w.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w := decoded.Bounds().Dx()
|
w := decoded.Bounds().Dx()
|
||||||
h := decoded.Bounds().Dy()
|
h := decoded.Bounds().Dy()
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
var wg sync.WaitGroup
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|||||||
@@ -2181,7 +2181,7 @@ func TestParseImages(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"tiff": {
|
"tiff": {
|
||||||
FileName: "test_compressed_tiff.tiff",
|
FileName: "test.tiff",
|
||||||
Expected: (*model.PostImage)(nil),
|
Expected: (*model.PostImage)(nil),
|
||||||
},
|
},
|
||||||
"not an image": {
|
"not an image": {
|
||||||
|
|||||||
Двоичные данные
tests/test_raw_tiff.tiff
Двоичные данные
tests/test_raw_tiff.tiff
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user