3
0

Fixes file upload for empty txt file and ico file

This commit is contained in:
Vivek Patel
2021-07-01 20:39:57 +05:30
parent 537791389e
commit f5532acf97
6 changed files with 82 additions and 2 deletions
+5 -1
View File
@@ -384,6 +384,10 @@ func (svc attachment) create(name string, size int64, fh io.ReadSeeker, att *typ
return errors.New("cannot create attachment: store handler not set")
}
if size == 0 {
return AttachmentErrNotAllowedToCreateEmptyAttachment()
}
aProps.setName(name)
aProps.setSize(size)
@@ -433,7 +437,7 @@ func (svc attachment) extractMimetype(file io.ReadSeeker) (mimetype string, err
}
func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment) (err error) {
if !strings.HasPrefix(att.Meta.Original.Mimetype, "image/") {
if !strings.HasPrefix(att.Meta.Original.Mimetype, "image/") || att.Meta.Original.Mimetype == "image/x-icon" {
// Only supporting previews from images (for now)
return
}
+32
View File
@@ -868,6 +868,38 @@ func AttachmentErrNotAllowedToCreate(mm ...*attachmentActionProps) *errors.Error
return e
}
// AttachmentErrNotAllowedToCreateEmptyAttachment returns "compose:attachment.notAllowedToCreateEmptyAttachment" as *errors.Error
//
//
// This function is auto-generated.
//
func AttachmentErrNotAllowedToCreateEmptyAttachment(mm ...*attachmentActionProps) *errors.Error {
var p = &attachmentActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to create empty attachments", nil),
errors.Meta("type", "notAllowedToCreateEmptyAttachment"),
errors.Meta("resource", "compose:attachment"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(attachmentLogMetaKey{}, "failed to create attachment; empty file"),
errors.Meta(attachmentPropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// AttachmentErrFailedToExtractMimeType returns "compose:attachment.failedToExtractMimeType" as *errors.Error
//
//
+4
View File
@@ -101,6 +101,10 @@ errors:
message: "not allowed to create attachments"
log: "could not create attachments; insufficient permissions"
- error: notAllowedToCreateEmptyAttachment
message: "not allowed to create empty attachments"
log: "failed to create attachment; empty file"
- error: failedToExtractMimeType
message: "could not extract mime type"
+5 -1
View File
@@ -210,6 +210,10 @@ func (svc attachment) create(ctx context.Context, name string, size int64, fh io
return errors.New("cannot create attachment: store handler not set")
}
if size == 0 {
return AttachmentErrNotAllowedToCreateEmptyAttachment(aaProps)
}
aaProps.setName(name)
aaProps.setSize(size)
@@ -259,7 +263,7 @@ func (svc attachment) extractMimetype(file io.ReadSeeker) (mimetype string, err
}
func (svc attachment) processImage(original io.ReadSeeker, att *types.Attachment) (err error) {
if !strings.HasPrefix(att.Meta.Original.Mimetype, "image/") {
if !strings.HasPrefix(att.Meta.Original.Mimetype, "image/") || att.Meta.Original.Mimetype == "image/x-icon" {
// Only supporting previews from images (for now)
return
}
+32
View File
@@ -493,6 +493,38 @@ func AttachmentErrNotAllowedToCreate(mm ...*attachmentActionProps) *errors.Error
return e
}
// AttachmentErrNotAllowedToCreateEmptyAttachment returns "system:attachment.notAllowedToCreateEmptyAttachment" as *errors.Error
//
//
// This function is auto-generated.
//
func AttachmentErrNotAllowedToCreateEmptyAttachment(mm ...*attachmentActionProps) *errors.Error {
var p = &attachmentActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to create empty attachments", nil),
errors.Meta("type", "notAllowedToCreateEmptyAttachment"),
errors.Meta("resource", "system:attachment"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(attachmentLogMetaKey{}, "failed to create attachment; empty file"),
errors.Meta(attachmentPropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// AttachmentErrFailedToExtractMimeType returns "system:attachment.failedToExtractMimeType" as *errors.Error
//
//
+4
View File
@@ -57,6 +57,10 @@ errors:
message: "not allowed to create attachments"
log: "failed to create attachment; insufficient permissions"
- error: notAllowedToCreateEmptyAttachment
message: "not allowed to create empty attachments"
log: "failed to create attachment; empty file"
- error: failedToExtractMimeType
message: "could not extract mime type"