enh: temp chat docx file support
This commit is contained in:
@@ -15,6 +15,7 @@ dayjs.extend(localizedFormat);
|
||||
|
||||
import { TTS_RESPONSE_SPLIT } from '$lib/types';
|
||||
|
||||
import mammoth from 'mammoth';
|
||||
import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.mjs?url';
|
||||
|
||||
import { marked } from 'marked';
|
||||
@@ -1519,6 +1520,12 @@ export const extractContentFromFile = async (file: File) => {
|
||||
});
|
||||
}
|
||||
|
||||
async function extractDocxText(file: File) {
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const result = await mammoth.extractRawText({ arrayBuffer });
|
||||
return result.value; // plain text
|
||||
}
|
||||
|
||||
const type = file.type || '';
|
||||
const ext = getExtension(file.name);
|
||||
|
||||
@@ -1527,6 +1534,14 @@ export const extractContentFromFile = async (file: File) => {
|
||||
return await extractPdfText(file);
|
||||
}
|
||||
|
||||
// DOCX check
|
||||
if (
|
||||
type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ||
|
||||
ext === '.docx'
|
||||
) {
|
||||
return await extractDocxText(file);
|
||||
}
|
||||
|
||||
// Text check (plain or common text-based)
|
||||
if (type.startsWith('text/') || textExtensions.includes(ext)) {
|
||||
return await readAsText(file);
|
||||
|
||||
Reference in New Issue
Block a user