Fix stuff
This commit is contained in:
parent
e301d9d1eb
commit
255497837b
4 changed files with 22 additions and 36 deletions
|
|
@ -107,6 +107,8 @@ services:
|
|||
STRIPE_PRICE_ID_YEARLY: ${STRIPE_PRICE_ID_YEARLY:-}
|
||||
volumes:
|
||||
- kaboot-data:/data
|
||||
tmpfs:
|
||||
- /tmp:size=100M
|
||||
networks:
|
||||
- kaboot-network
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
// 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(
|
||||
|
|
|
|||
31
server/src/types/legacy-office.d.ts
vendored
31
server/src/types/legacy-office.d.ts
vendored
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue