diff --git a/Prototype/server/src/utils/minio.ts b/Prototype/server/src/utils/minio.ts index ed39987..b9c49b4 100644 --- a/Prototype/server/src/utils/minio.ts +++ b/Prototype/server/src/utils/minio.ts @@ -3,11 +3,26 @@ import minioClient from "../storage"; /** * Remove slash at the start and ensure slash at the end of the path + * @param path - path to be check and ensure + * @returns path without / at start and end with trailing slash */ function safePath(path: string) { return path.replace(/^\/|\/$/g, "") + "/"; } +/** + * Replace illegal character eg. ? % < > / \ : | that can't be in path with "-". + * @param path - string to check and replace + * @returns path with illegal character replaced with "-" + */ +export function replaceIllegalChars(path: string, replaceChar = "-") { + return path.replace(/[/\\?%*:|"<>]/g, "-"); +} + +/** + * Utility function to check for .keep file if it is exist or not. + * @returns true if .keep exist, false otherwise + */ export async function pathExist(path: string): Promise { return await minioClient .statObject("ehr", `${safePath(path)}.keep`) @@ -18,6 +33,11 @@ export async function pathExist(path: string): Promise { }); } +/** + * Utility function to list folder by using .keep file with prefix in minio. + * @param path - path to list + * @return list of folder with metadata + */ export function listFolder(path?: string): Promise { if (path) path = safePath(path);