| 8 | const logger = createLogger('PptxParser') |
| 9 | |
| 10 | export class PptxParser implements FileParser { |
| 11 | async parseFile(filePath: string): Promise<FileParseResult> { |
| 12 | try { |
| 13 | if (!filePath) { |
| 14 | throw new Error('No file path provided') |
| 15 | } |
| 16 | |
| 17 | if (!existsSync(filePath)) { |
| 18 | throw new Error(`File not found: ${filePath}`) |
| 19 | } |
| 20 | |
| 21 | logger.info(`Parsing PowerPoint file: ${filePath}`) |
| 22 | |
| 23 | const buffer = await readFile(filePath) |
| 24 | return this.parseBuffer(buffer) |
| 25 | } catch (error) { |
| 26 | logger.error('PowerPoint file parsing error:', error) |
| 27 | throw new Error(`Failed to parse PowerPoint file: ${(error as Error).message}`) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | async parseBuffer(buffer: Buffer): Promise<FileParseResult> { |
| 32 | try { |
| 33 | logger.info('Parsing PowerPoint buffer, size:', buffer.length) |
| 34 | |
| 35 | if (!buffer || buffer.length === 0) { |
| 36 | throw new Error('Empty buffer provided') |
| 37 | } |
| 38 | |
| 39 | assertOoxmlArchiveWithinLimits(buffer) |
| 40 | |
| 41 | let parseOfficeAsync |
| 42 | try { |
| 43 | const officeParser = await import('officeparser') |
| 44 | parseOfficeAsync = officeParser.parseOfficeAsync |
| 45 | } catch (importError) { |
| 46 | logger.warn('officeparser not available, using fallback extraction') |
| 47 | return this.fallbackExtraction(buffer) |
| 48 | } |
| 49 | |
| 50 | try { |
| 51 | const result = await parseOfficeAsync(buffer) |
| 52 | |
| 53 | if (!result || typeof result !== 'string') { |
| 54 | throw new Error('officeparser returned invalid result') |
| 55 | } |
| 56 | |
| 57 | const content = sanitizeTextForUTF8(result.trim()) |
| 58 | |
| 59 | logger.info('PowerPoint parsing completed successfully with officeparser') |
| 60 | |
| 61 | return { |
| 62 | content: content, |
| 63 | metadata: { |
| 64 | characterCount: content.length, |
| 65 | extractionMethod: 'officeparser', |
| 66 | }, |
| 67 | } |
nothing calls this directly
no outgoing calls
no test coverage detected