Merge pull request #1977 from hmhealey/plt1685
PLT-1685 Fixed handling of files with no extension
Этот коммит содержится в:
@@ -32,6 +32,11 @@ func GetInfoForBytes(filename string, data []byte) (*FileInfo, *AppError) {
|
||||
mimeType = mime.TypeByExtension(extension)
|
||||
}
|
||||
|
||||
if extension != "" && extension[0] == '.' {
|
||||
// the client expects a file extension without the leading period
|
||||
extension = extension[1:]
|
||||
}
|
||||
|
||||
hasPreviewImage := isImage
|
||||
if mimeType == "image/gif" {
|
||||
// just show the gif itself instead of a preview image for animated gifs
|
||||
@@ -45,7 +50,7 @@ func GetInfoForBytes(filename string, data []byte) (*FileInfo, *AppError) {
|
||||
return &FileInfo{
|
||||
Filename: filename,
|
||||
Size: size,
|
||||
Extension: extension[1:],
|
||||
Extension: extension,
|
||||
MimeType: mimeType,
|
||||
HasPreviewImage: hasPreviewImage,
|
||||
}, nil
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestGetInfoForBytes(t *testing.T) {
|
||||
} else if info.Size != 1000 {
|
||||
t.Fatalf("Got incorrect size: %v", info.Size)
|
||||
} else if info.Extension != "txt" {
|
||||
t.Fatalf("Git incorrect file extension: %v", info.Extension)
|
||||
t.Fatalf("Got incorrect file extension: %v", info.Extension)
|
||||
} else if info.MimeType != "text/plain; charset=utf-8" {
|
||||
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
|
||||
} else if info.HasPreviewImage {
|
||||
@@ -33,7 +33,7 @@ func TestGetInfoForBytes(t *testing.T) {
|
||||
} else if info.Size != 1000 {
|
||||
t.Fatalf("Got incorrect size: %v", info.Size)
|
||||
} else if info.Extension != "png" {
|
||||
t.Fatalf("Git incorrect file extension: %v", info.Extension)
|
||||
t.Fatalf("Got incorrect file extension: %v", info.Extension)
|
||||
} else if info.MimeType != "image/png" {
|
||||
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
|
||||
} else if !info.HasPreviewImage {
|
||||
@@ -49,7 +49,7 @@ func TestGetInfoForBytes(t *testing.T) {
|
||||
} else if info.Size != 35 {
|
||||
t.Fatalf("Got incorrect size: %v", info.Size)
|
||||
} else if info.Extension != "gif" {
|
||||
t.Fatalf("Git incorrect file extension: %v", info.Extension)
|
||||
t.Fatalf("Got incorrect file extension: %v", info.Extension)
|
||||
} else if info.MimeType != "image/gif" {
|
||||
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
|
||||
} else if !info.HasPreviewImage {
|
||||
@@ -67,10 +67,24 @@ func TestGetInfoForBytes(t *testing.T) {
|
||||
} else if info.Size != 38689 {
|
||||
t.Fatalf("Got incorrect size: %v", info.Size)
|
||||
} else if info.Extension != "gif" {
|
||||
t.Fatalf("Git incorrect file extension: %v", info.Extension)
|
||||
t.Fatalf("Got incorrect file extension: %v", info.Extension)
|
||||
} else if info.MimeType != "image/gif" {
|
||||
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
|
||||
} else if info.HasPreviewImage {
|
||||
t.Fatalf("Got HasPreviewImage = true for animated gif")
|
||||
}
|
||||
|
||||
if info, err := GetInfoForBytes("filewithoutextension", fakeFile); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if info.Filename != "filewithoutextension" {
|
||||
t.Fatalf("Got incorrect filename: %v", info.Filename)
|
||||
} else if info.Size != 1000 {
|
||||
t.Fatalf("Got incorrect size: %v", info.Size)
|
||||
} else if info.Extension != "" {
|
||||
t.Fatalf("Got incorrect file extension: %v", info.Extension)
|
||||
} else if info.MimeType != "" {
|
||||
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
|
||||
} else if info.HasPreviewImage {
|
||||
t.Fatalf("Got HasPreviewImage = true for non-image file")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,16 @@ import * as Utils from '../utils/utils.jsx';
|
||||
|
||||
export default function FileInfoPreview({filename, fileUrl, fileInfo}) {
|
||||
// non-image files include a section providing details about the file
|
||||
let infoString = 'File type ' + fileInfo.extension.toUpperCase();
|
||||
if (fileInfo.size > 0) {
|
||||
infoString += ', Size ' + Utils.fileSizeToString(fileInfo.size);
|
||||
const infoParts = [];
|
||||
|
||||
if (fileInfo.extension !== '') {
|
||||
infoParts.push('File type ' + fileInfo.extension.toUpperCase());
|
||||
}
|
||||
|
||||
infoParts.push('Size ' + Utils.fileSizeToString(fileInfo.size));
|
||||
|
||||
const infoString = infoParts.join(', ');
|
||||
|
||||
const name = decodeURIComponent(Utils.getFileName(filename));
|
||||
|
||||
return (
|
||||
|
||||
Ссылка в новой задаче
Block a user