( ctx context.Context, tx database.Store, chatID uuid.UUID, ownerID uuid.UUID, organizationID uuid.UUID, name string, mediaType string, data []byte, )
| 71 | } |
| 72 | |
| 73 | func storeLinkedChatFileTx( |
| 74 | ctx context.Context, |
| 75 | tx database.Store, |
| 76 | chatID uuid.UUID, |
| 77 | ownerID uuid.UUID, |
| 78 | organizationID uuid.UUID, |
| 79 | name string, |
| 80 | mediaType string, |
| 81 | data []byte, |
| 82 | ) (chattool.AttachmentMetadata, error) { |
| 83 | row, err := tx.InsertChatFile(ctx, database.InsertChatFileParams{ |
| 84 | OwnerID: ownerID, |
| 85 | OrganizationID: organizationID, |
| 86 | Name: name, |
| 87 | Mimetype: mediaType, |
| 88 | Data: data, |
| 89 | }) |
| 90 | if err != nil { |
| 91 | return chattool.AttachmentMetadata{}, xerrors.Errorf("insert chat file: %w", err) |
| 92 | } |
| 93 | |
| 94 | rejected, err := tx.LinkChatFiles(ctx, database.LinkChatFilesParams{ |
| 95 | ChatID: chatID, |
| 96 | MaxFileLinks: int32(codersdk.MaxChatFileIDs), |
| 97 | FileIds: []uuid.UUID{row.ID}, |
| 98 | }) |
| 99 | if err != nil { |
| 100 | return chattool.AttachmentMetadata{}, xerrors.Errorf("link chat file: %w", err) |
| 101 | } |
| 102 | if rejected > 0 { |
| 103 | return chattool.AttachmentMetadata{}, xerrors.Errorf("chat already has the maximum of %d linked files", codersdk.MaxChatFileIDs) |
| 104 | } |
| 105 | |
| 106 | return chattool.AttachmentMetadata{ |
| 107 | FileID: row.ID, |
| 108 | MediaType: mediaType, |
| 109 | Name: name, |
| 110 | }, nil |
| 111 | } |
no test coverage detected