( ctx context.Context, storeFile StoreFileFunc, name string, detectName string, data []byte, )
| 33 | } |
| 34 | |
| 35 | func storeAttachmentData( |
| 36 | ctx context.Context, |
| 37 | storeFile StoreFileFunc, |
| 38 | name string, |
| 39 | detectName string, |
| 40 | data []byte, |
| 41 | ) (AttachmentMetadata, error) { |
| 42 | if storeFile == nil { |
| 43 | return AttachmentMetadata{}, xerrors.New("file storage is not configured") |
| 44 | } |
| 45 | if len(data) == 0 { |
| 46 | return AttachmentMetadata{}, xerrors.New("attachment is empty") |
| 47 | } |
| 48 | if len(data) > maxAttachmentSize { |
| 49 | return AttachmentMetadata{}, xerrors.Errorf("attachment exceeds %d MiB size limit", maxAttachmentSize>>20) |
| 50 | } |
| 51 | |
| 52 | name = strings.TrimSpace(name) |
| 53 | if name == "" { |
| 54 | return AttachmentMetadata{}, xerrors.New("attachment name is required") |
| 55 | } |
| 56 | if strings.TrimSpace(detectName) == "" { |
| 57 | detectName = name |
| 58 | } |
| 59 | |
| 60 | attachment, err := storeFile(ctx, name, detectName, data) |
| 61 | if err != nil { |
| 62 | return AttachmentMetadata{}, err |
| 63 | } |
| 64 | if attachment.FileID == uuid.Nil { |
| 65 | return AttachmentMetadata{}, xerrors.New("stored attachment is missing file ID") |
| 66 | } |
| 67 | if attachment.MediaType == "" { |
| 68 | return AttachmentMetadata{}, xerrors.New("stored attachment is missing media type") |
| 69 | } |
| 70 | if attachment.Name == "" { |
| 71 | attachment.Name = name |
| 72 | } |
| 73 | return attachment, nil |
| 74 | } |
| 75 | |
| 76 | func storeWorkspaceAttachment( |
| 77 | ctx context.Context, |
no test coverage detected