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:-}
|
STRIPE_PRICE_ID_YEARLY: ${STRIPE_PRICE_ID_YEARLY:-}
|
||||||
volumes:
|
volumes:
|
||||||
- kaboot-data:/data
|
- kaboot-data:/data
|
||||||
|
tmpfs:
|
||||||
|
- /tmp:size=100M
|
||||||
networks:
|
networks:
|
||||||
- kaboot-network
|
- kaboot-network
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,8 @@ services:
|
||||||
GEMINI_API_KEY: ${GEMINI_API_KEY:-}
|
GEMINI_API_KEY: ${GEMINI_API_KEY:-}
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
|
tmpfs:
|
||||||
|
- /tmp:size=100M
|
||||||
ports:
|
ports:
|
||||||
- "${KABOOT_BACKEND_PORT:-3001}:3001"
|
- "${KABOOT_BACKEND_PORT:-3001}:3001"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ import officeParser from 'officeparser';
|
||||||
import WordExtractor from 'word-extractor';
|
import WordExtractor from 'word-extractor';
|
||||||
import * as XLSX from 'xlsx';
|
import * as XLSX from 'xlsx';
|
||||||
import PPT from 'ppt';
|
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 = [
|
export const GEMINI_NATIVE_TYPES = [
|
||||||
'application/pdf',
|
'application/pdf',
|
||||||
|
|
@ -197,10 +200,20 @@ function extractWithSheetJS(buffer: Buffer): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractWithSheetJSPPT(buffer: Buffer): string {
|
function extractWithSheetJSPPT(buffer: Buffer): string {
|
||||||
const cfb = CFB.read(buffer, { type: 'buffer' });
|
// PPT library requires file path due to CFB API compatibility issues
|
||||||
const pres = PPT.parse_pptcfb(cfb);
|
const tempPath = join(tmpdir(), `ppt-${randomUUID()}.ppt`);
|
||||||
const textArray = PPT.utils.to_text(pres);
|
try {
|
||||||
return textArray.join('\n\n');
|
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(
|
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 {
|
interface PPTModule {
|
||||||
version: string;
|
version: string;
|
||||||
readFile(filename: string, opts?: { WTF?: number; dump?: number }): PPTPresentation;
|
readFile(filename: string, opts?: { WTF?: number; dump?: number }): PPTPresentation;
|
||||||
parse_pptcfb(cfb: CFBContainer, opts?: object): PPTPresentation;
|
|
||||||
utils: PPTUtils;
|
utils: PPTUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PPT: PPTModule;
|
const PPT: PPTModule;
|
||||||
export default PPT;
|
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