MCPcopy Index your code
hub / github.com/coder/coder / storeLinkedChatFileTx

Function storeLinkedChatFileTx

coderd/x/chatd/store_chat_attachment.go:73–111  ·  view source on GitHub ↗
(
	ctx context.Context,
	tx database.Store,
	chatID uuid.UUID,
	ownerID uuid.UUID,
	organizationID uuid.UUID,
	name string,
	mediaType string,
	data []byte,
)

Source from the content-addressed store, hash-verified

71}
72
73func 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}

Callers 2

storeChatAttachmentMethod · 0.85

Calls 3

InsertChatFileMethod · 0.65
LinkChatFilesMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected