MCPcopy Create free account
hub / github.com/MathMan05/Fermi / combinePath

Function combinePath

src/index.ts:28–64  ·  view source on GitHub ↗
(path: string, tryAgain = true, reqpath: string)

Source from the content-addressed store, hash-verified

26
27let dirs: dirtype | undefined = undefined;
28async function combinePath(path: string, tryAgain = true, reqpath: string): Promise<string> {
29 if (!dirs) {
30 dirs = await getDirectories(__dirname);
31 }
32 const pathDir = path
33 .split("/")
34 .reverse()
35 .filter((_) => _ !== "");
36 function find(arr: string[], search: dirtype | string | undefined): boolean {
37 if (search == undefined) return false;
38 if (arr.length === 0) {
39 return typeof search == "string";
40 }
41 if (typeof search == "string") {
42 return false;
43 }
44 const thing = arr.pop() as string;
45 return find(arr, search.get(thing));
46 }
47 if (find(pathDir, dirs)) {
48 return __dirname + path;
49 } else if (reqpath.startsWith("/channels")) {
50 return __dirname + "/webpage/app.html";
51 } else {
52 if (!path.includes(".")) {
53 const str = await combinePath(path + ".html", false, reqpath);
54 if (str !== __dirname + "/webpage/404.html") {
55 return str;
56 }
57 }
58 if (devmode && tryAgain) {
59 dirs = await getDirectories(__dirname);
60 return combinePath(path, false, reqpath);
61 }
62 return __dirname + "/webpage/404.html";
63 }
64}
65interface Instance {
66 name: string;
67 [key: string]: any;

Callers 1

index.tsFile · 0.85

Calls 2

getDirectoriesFunction · 0.85
findFunction · 0.85

Tested by

no test coverage detected