File size: 586 Bytes
142ad12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// hf-space/src/lib/knowledge/parser/index.ts

import { parsePDF } from './pdf';
import { parseDOCX } from './docx';
import { parseText } from './text';

export interface ParsedDocument {
  content: string;
  pages?: number;
}

export async function parseDocument(buffer: Buffer, fileType: string): Promise<ParsedDocument> {
  switch (fileType) {
    case 'pdf':
      return parsePDF(buffer);
    case 'docx':
      return parseDOCX(buffer);
    case 'md':
    case 'txt':
      return parseText(buffer);
    default:
      throw new Error(`Unsupported file type: ${fileType}`);
  }
}