diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 75cd073e..129a1d12 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -146,6 +146,19 @@ export const removeFirstHashWord = (inputString) => { return resultString; }; +export const transformFileName = (fileName) => { + // Convert to lowercase + const lowerCaseFileName = fileName.toLowerCase(); + + // Remove special characters using regular expression + const sanitizedFileName = lowerCaseFileName.replace(/[^\w\s]/g, ''); + + // Replace spaces with dashes + const finalFileName = sanitizedFileName.replace(/\s+/g, '-'); + + return finalFileName; +}; + export const calculateSHA256 = async (file) => { // Create a FileReader to read the file asynchronously const reader = new FileReader(); diff --git a/src/routes/(app)/documents/+page.svelte b/src/routes/(app)/documents/+page.svelte index 747adec8..f0ad1a54 100644 --- a/src/routes/(app)/documents/+page.svelte +++ b/src/routes/(app)/documents/+page.svelte @@ -9,6 +9,7 @@ import { SUPPORTED_FILE_TYPE } from '$lib/constants'; import { uploadDocToVectorDB } from '$lib/apis/rag'; + import { transformFileName } from '$lib/utils'; let importFiles = ''; @@ -30,7 +31,7 @@ localStorage.token, res.collection_name, res.filename, - res.filename, + transformFileName(res.filename), res.filename ); await documents.set(await getDocs(localStorage.token)); @@ -165,14 +166,70 @@