Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
26 lines
958 B
Plaintext
26 lines
958 B
Plaintext
//#region src/utils/filepath.ts
|
|
const getFilePath = (options) => {
|
|
let filename = options.filename;
|
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
if (filename.endsWith("/")) filename = filename.concat(defaultDocument);
|
|
else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) filename = filename.concat("/" + defaultDocument);
|
|
return getFilePathWithoutDefaultDocument({
|
|
root: options.root,
|
|
filename
|
|
});
|
|
};
|
|
const getFilePathWithoutDefaultDocument = (options) => {
|
|
let root = options.root || "";
|
|
let filename = options.filename;
|
|
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return;
|
|
filename = filename.replace(/^\.?[\/\\]/, "");
|
|
filename = filename.replace(/\\/g, "/");
|
|
root = root.replace(/\/$/, "");
|
|
let path = root ? root + "/" + filename : filename;
|
|
path = path.replace(/^\.?\//, "");
|
|
if (root[0] !== "/" && path[0] === "/") return;
|
|
return path;
|
|
};
|
|
//#endregion
|
|
export { getFilePath, getFilePathWithoutDefaultDocument };
|