From fe997abc6d4908140d3ceba78ebc251b83dce6ab Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 8 Jan 2024 01:32:55 -0800 Subject: [PATCH] feat: transform filename to name --- src/lib/utils/index.ts | 13 +++++ src/routes/(app)/documents/+page.svelte | 65 +++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 75cd073ed..129a1d12c 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 747adec8d..f0ad1a541 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 @@