mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
Linked PR https://github.com/chatwoot/chatwoot/pull/12113 ## Linear Link https://linear.app/chatwoot/issue/CW-4515/upload-pdfs-to-captain ## Description This PR adds support for PDF file uploads to the Captain document knowledge base system. The feature enables users to upload PDF files directly to the knowledge base for FAQ generation and document processing, expanding beyond the existing URL-based document ingestion. ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Unit Tests - Manually via UI ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com>
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
/**
|
|
* Document Helper - utilities for document display and formatting
|
|
*/
|
|
|
|
// Constants for document processing
|
|
const PDF_PREFIX = 'PDF:';
|
|
const TIMESTAMP_PATTERN = /_\d{14}(?=\.pdf$)/; // Format: _YYYYMMDDHHMMSS before .pdf extension
|
|
|
|
/**
|
|
* Checks if a document is a PDF based on its external link
|
|
* @param {string} externalLink - The external link string
|
|
* @returns {boolean} True if the document is a PDF
|
|
*/
|
|
export const isPdfDocument = externalLink => {
|
|
if (!externalLink) return false;
|
|
return externalLink.startsWith(PDF_PREFIX);
|
|
};
|
|
|
|
/**
|
|
* Formats the display link for documents
|
|
* For PDF documents: removes 'PDF:' prefix and timestamp suffix
|
|
* For regular URLs: returns as-is
|
|
*
|
|
* @param {string} externalLink - The external link string
|
|
* @returns {string} Formatted display link
|
|
*/
|
|
export const formatDocumentLink = externalLink => {
|
|
if (!externalLink) return '';
|
|
|
|
if (isPdfDocument(externalLink)) {
|
|
// Remove 'PDF:' prefix
|
|
const fullName = externalLink.substring(PDF_PREFIX.length);
|
|
// Remove timestamp suffix if present
|
|
return fullName.replace(TIMESTAMP_PATTERN, '');
|
|
}
|
|
|
|
return externalLink;
|
|
};
|