Przeglądaj źródła

refactor: update isVectorStoreCompatible function to accept separate parameters for original name and mime type

Shun Miyazawa 10 miesięcy temu
rodzic
commit
cdf58d2f00

+ 1 - 2
apps/app/src/features/openai/server/services/openai.ts

@@ -2,7 +2,6 @@ import assert from 'node:assert';
 import { Readable, Transform } from 'stream';
 import { pipeline } from 'stream/promises';
 
-
 import type {
   IUser, Ref, Lang, IPage,
 } from '@growi/core';
@@ -664,7 +663,7 @@ class OpenaiService implements IOpenaiService {
   private async createVectorStoreFileOnUploadAttachment(
       pageId: string, attachment: HydratedDocument<IAttachmentDocument>, file: Express.Multer.File, buffer: Buffer,
   ): Promise<void> {
-    if (!isVectorStoreCompatible(file)) {
+    if (!isVectorStoreCompatible(file.originalname, file.mimetype)) {
       return;
     }
 

+ 2 - 3
apps/app/src/features/openai/server/utils/is-vector-store-compatible.ts

@@ -27,9 +27,9 @@ const supportedFormats = {
 
 type SupportedExtension = keyof typeof supportedFormats;
 
-export const isVectorStoreCompatible = (file: Express.Multer.File): boolean => {
+export const isVectorStoreCompatible = (originalName: string, mimeType: string): boolean => {
   // Get extension
-  const extension = path.extname(file.originalname).toLowerCase();
+  const extension = path.extname(originalName).toLowerCase();
 
   // Check if the file extension is supported
   if (!(extension in supportedFormats)) {
@@ -40,7 +40,6 @@ export const isVectorStoreCompatible = (file: Express.Multer.File): boolean => {
   const supportedMimeType = supportedFormats[extension as SupportedExtension];
 
   // Check if the mimeType is supported
-  const mimeType = file.mimetype;
   return Array.isArray(supportedMimeType)
     ? supportedMimeType.includes(mimeType)
     : supportedMimeType === mimeType;