From 255497837ba65cf9cb76b40a24a67193f5e2a047 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Fri, 23 Jan 2026 15:04:49 -0700 Subject: [PATCH] Fix stuff --- docker-compose.prod.yml | 2 ++ docker-compose.yml | 2 ++ server/src/services/documentParser.ts | 23 +++++++++++++++----- server/src/types/legacy-office.d.ts | 31 --------------------------- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index a56ad90..6fb48aa 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -107,6 +107,8 @@ services: STRIPE_PRICE_ID_YEARLY: ${STRIPE_PRICE_ID_YEARLY:-} volumes: - kaboot-data:/data + tmpfs: + - /tmp:size=100M networks: - kaboot-network diff --git a/docker-compose.yml b/docker-compose.yml index 0d97add..1a9e809 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -120,6 +120,8 @@ services: GEMINI_API_KEY: ${GEMINI_API_KEY:-} volumes: - ./data:/data + tmpfs: + - /tmp:size=100M ports: - "${KABOOT_BACKEND_PORT:-3001}:3001" depends_on: diff --git a/server/src/services/documentParser.ts b/server/src/services/documentParser.ts index a99f6ab..5cfc628 100644 --- a/server/src/services/documentParser.ts +++ b/server/src/services/documentParser.ts @@ -2,7 +2,10 @@ import officeParser from 'officeparser'; import WordExtractor from 'word-extractor'; import * as XLSX from 'xlsx'; import PPT from 'ppt'; -import CFB from 'cfb'; +import { writeFileSync, unlinkSync } from 'fs'; +import { tmpdir } from 'os'; +import { join } from 'path'; +import { randomUUID } from 'crypto'; export const GEMINI_NATIVE_TYPES = [ 'application/pdf', @@ -197,10 +200,20 @@ function extractWithSheetJS(buffer: Buffer): string { } function extractWithSheetJSPPT(buffer: Buffer): string { - const cfb = CFB.read(buffer, { type: 'buffer' }); - const pres = PPT.parse_pptcfb(cfb); - const textArray = PPT.utils.to_text(pres); - return textArray.join('\n\n'); + // PPT library requires file path due to CFB API compatibility issues + const tempPath = join(tmpdir(), `ppt-${randomUUID()}.ppt`); + try { + writeFileSync(tempPath, buffer); + const pres = PPT.readFile(tempPath); + const textArray = PPT.utils.to_text(pres); + return textArray.join('\n\n'); + } finally { + try { + unlinkSync(tempPath); + } catch { + // Ignore cleanup errors + } + } } export async function processDocument( diff --git a/server/src/types/legacy-office.d.ts b/server/src/types/legacy-office.d.ts index 16d6c00..e00074f 100644 --- a/server/src/types/legacy-office.d.ts +++ b/server/src/types/legacy-office.d.ts @@ -23,40 +23,9 @@ declare module 'ppt' { interface PPTModule { version: string; readFile(filename: string, opts?: { WTF?: number; dump?: number }): PPTPresentation; - parse_pptcfb(cfb: CFBContainer, opts?: object): PPTPresentation; utils: PPTUtils; } const PPT: PPTModule; export default PPT; } - -declare module 'cfb' { - interface CFBEntry { - name: string; - type: number; - content?: Buffer; - } - - interface CFBContainer { - FileIndex: CFBEntry[]; - FullPaths: string[]; - } - - interface ReadOptions { - type?: 'file' | 'buffer' | 'base64' | 'binary' | 'array'; - } - - interface CFBModule { - read(data: Buffer | string | ArrayBuffer, opts?: ReadOptions): CFBContainer; - parse(data: Buffer | number[]): CFBContainer; - } - - const CFB: CFBModule; - export default CFB; -} - -// Re-export for global use -declare global { - type CFBContainer = import('cfb').CFBContainer; -}