| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { buildFileConsentCard } from "./file-consent.js"; |
| import { storePendingUpload } from "./pending-uploads.js"; |
|
|
| export type FileConsentMedia = { |
| buffer: Buffer; |
| filename: string; |
| contentType?: string; |
| }; |
|
|
| export type FileConsentActivityResult = { |
| activity: Record<string, unknown>; |
| uploadId: string; |
| }; |
|
|
| |
| |
| |
| |
| export function prepareFileConsentActivity(params: { |
| media: FileConsentMedia; |
| conversationId: string; |
| description?: string; |
| }): FileConsentActivityResult { |
| const { media, conversationId, description } = params; |
|
|
| const uploadId = storePendingUpload({ |
| buffer: media.buffer, |
| filename: media.filename, |
| contentType: media.contentType, |
| conversationId, |
| }); |
|
|
| const consentCard = buildFileConsentCard({ |
| filename: media.filename, |
| description: description || `File: ${media.filename}`, |
| sizeInBytes: media.buffer.length, |
| context: { uploadId }, |
| }); |
|
|
| const activity: Record<string, unknown> = { |
| type: "message", |
| attachments: [consentCard], |
| }; |
|
|
| return { activity, uploadId }; |
| } |
|
|
| |
| |
| |
| |
| export function requiresFileConsent(params: { |
| conversationType: string | undefined; |
| contentType: string | undefined; |
| bufferSize: number; |
| thresholdBytes: number; |
| }): boolean { |
| const isPersonal = params.conversationType?.toLowerCase() === "personal"; |
| const isImage = params.contentType?.startsWith("image/") ?? false; |
| const isLargeFile = params.bufferSize >= params.thresholdBytes; |
| return isPersonal && (isLargeFile || !isImage); |
| } |
|
|