Skip to content
Snippets Groups Projects
Unverified Commit 12ed570a authored by Marcus Schiesser's avatar Marcus Schiesser Committed by GitHub
Browse files

refactor: make saveDocument reusable (#332)

parent bde3daae
No related branches found
No related tags found
No related merge requests found
...@@ -15,8 +15,11 @@ export async function storeAndParseFile( ...@@ -15,8 +15,11 @@ export async function storeAndParseFile(
fileBuffer: Buffer, fileBuffer: Buffer,
mimeType: string, mimeType: string,
) { ) {
const fileExt = MIME_TYPE_TO_EXT[mimeType];
if (!fileExt) throw new Error(`Unsupported document type: ${mimeType}`);
const documents = await loadDocuments(fileBuffer, mimeType); const documents = await loadDocuments(fileBuffer, mimeType);
await saveDocument(filename, fileBuffer, mimeType); await saveDocument(filename, fileBuffer);
for (const document of documents) { for (const document of documents) {
document.metadata = { document.metadata = {
...document.metadata, ...document.metadata,
...@@ -38,14 +41,7 @@ async function loadDocuments(fileBuffer: Buffer, mimeType: string) { ...@@ -38,14 +41,7 @@ async function loadDocuments(fileBuffer: Buffer, mimeType: string) {
return await reader.loadDataAsContent(fileBuffer); return await reader.loadDataAsContent(fileBuffer);
} }
async function saveDocument( export async function saveDocument(filename: string, fileBuffer: Buffer) {
filename: string,
fileBuffer: Buffer,
mimeType: string,
) {
const fileExt = MIME_TYPE_TO_EXT[mimeType];
if (!fileExt) throw new Error(`Unsupported document type: ${mimeType}`);
const filepath = `${UPLOADED_FOLDER}/${filename}`; const filepath = `${UPLOADED_FOLDER}/${filename}`;
const fileurl = `${process.env.FILESERVER_URL_PREFIX}/${filepath}`; const fileurl = `${process.env.FILESERVER_URL_PREFIX}/${filepath}`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment