attachmentContext.js 602 B

12345678910111213141516171819
  1. export function buildUploadedDocumentPayload(file) {
  2. if (!file || typeof file.content !== 'string' || !file.content.trim()) {
  3. return null
  4. }
  5. const normalizedType = String(file.type || file.fileType || '')
  6. .replace(/^\./, '')
  7. .toLowerCase()
  8. return {
  9. file_name: file.name || file.fileName || '',
  10. file_type: normalizedType,
  11. content: file.content,
  12. attachment_id: file.attachmentId || file.attachment_id || '',
  13. char_count: Number.isFinite(Number(file.charCount ?? file.char_count))
  14. ? Number(file.charCount ?? file.char_count)
  15. : file.content.length
  16. }
  17. }