[MM-45862] Set size and extension to fileinfo (#20681)
* Set size and extension to fileinfo * Remove unnecessary check
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3d7859396d
Коммит
9255671222
@@ -207,7 +207,7 @@ func TestUploadData(t *testing.T) {
|
||||
CreateAt: model.GetMillis(),
|
||||
UserId: th.BasicUser2.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Filename: "upload",
|
||||
Filename: "upload.zip",
|
||||
FileSize: 8 * 1024 * 1024,
|
||||
}
|
||||
us, err := th.App.CreateUploadSession(th.Context, us)
|
||||
@@ -281,6 +281,9 @@ func TestUploadData(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, u.Filename, info.Name)
|
||||
require.Equal(t, u.FileSize, info.Size)
|
||||
require.Equal(t, "zip", info.Extension)
|
||||
require.Equal(t, "application/zip", info.MimeType)
|
||||
|
||||
file, _, err := th.Client.GetFile(info.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -24,10 +24,19 @@ const minFirstPartSize = 5 * 1024 * 1024 // 5MB
|
||||
|
||||
func (a *App) genFileInfoFromReader(name string, file io.ReadSeeker, size int64) (*model.FileInfo, error) {
|
||||
ext := strings.ToLower(filepath.Ext(name))
|
||||
|
||||
info := &model.FileInfo{
|
||||
Name: name,
|
||||
MimeType: mime.TypeByExtension(ext),
|
||||
Name: name,
|
||||
MimeType: mime.TypeByExtension(ext),
|
||||
Size: size,
|
||||
Extension: ext,
|
||||
}
|
||||
|
||||
if ext != "" {
|
||||
// The client expects a file extension without the leading period
|
||||
info.Extension = ext[1:]
|
||||
}
|
||||
|
||||
if info.IsImage() {
|
||||
config, _, err := a.ch.imgDecoder.DecodeConfig(file)
|
||||
if err != nil {
|
||||
|
||||
@@ -141,7 +141,7 @@ func GetInfoForBytes(name string, data io.ReadSeeker, size int) (*FileInfo, *App
|
||||
extension := strings.ToLower(filepath.Ext(name))
|
||||
info.MimeType = mime.TypeByExtension(extension)
|
||||
|
||||
if extension != "" && extension[0] == '.' {
|
||||
if extension != "" {
|
||||
// The client expects a file extension without the leading period
|
||||
info.Extension = extension[1:]
|
||||
} else {
|
||||
|
||||
Ссылка в новой задаче
Block a user