mirror of
https://github.com/khairul169/home-lab.git
synced 2025-04-28 16:49:36 +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,
|
|
};
|
|
}
|