mirror of
				https://github.com/khairul169/home-lab.git
				synced 2025-11-04 05:31:08 +07:00 
			
		
		
		
	
		
			
				
	
	
		
			26 lines
		
	
	
		
			682 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			682 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
export const filesDirList = process.env.FILE_DIRS
 | 
						|
  ? process.env.FILE_DIRS.split(";").map((i) => ({
 | 
						|
      name: i.split("/").at(-1),
 | 
						|
      path: i,
 | 
						|
    }))
 | 
						|
  : [];
 | 
						|
 | 
						|
export function getFilePath(path?: string) {
 | 
						|
  const pathSlices =
 | 
						|
    path
 | 
						|
      ?.replace(/\/{2,}/g, "/")
 | 
						|
      .replace(/\/$/, "")
 | 
						|
      .split("/") || [];
 | 
						|
  const baseName = pathSlices[1] || null;
 | 
						|
  const filePath = pathSlices.slice(2).join("/");
 | 
						|
  const baseDir = filesDirList.find((i) => i.name === baseName)?.path;
 | 
						|
 | 
						|
  return {
 | 
						|
    path: [baseDir || "", filePath].join("/").replace(/\/$/, ""),
 | 
						|
    pathname: ["", baseName, filePath].join("/").replace(/\/$/, ""),
 | 
						|
    baseName,
 | 
						|
    baseDir,
 | 
						|
    filePath,
 | 
						|
  };
 | 
						|
}
 |