docs: added description

This commit is contained in:
Methapon2001 2023-11-21 09:57:48 +07:00
parent 6bf28d11a8
commit 6718b4a10b
No known key found for this signature in database
GPG key ID: 849924FEF46BD132

View file

@ -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<boolean> {
return await minioClient
.statObject("ehr", `${safePath(path)}.keep`)
@ -18,6 +33,11 @@ export async function pathExist(path: string): Promise<boolean> {
});
}
/**
* 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<EhrFolder[]> {
if (path) path = safePath(path);