(path: string, tryAgain = true, reqpath: string)
| 26 | |
| 27 | let dirs: dirtype | undefined = undefined; |
| 28 | async 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 | } |
| 65 | interface Instance { |
| 66 | name: string; |
| 67 | [key: string]: any; |
no test coverage detected