From 789e9a8c3c52bcfa9958f46f234263b14e4c030e Mon Sep 17 00:00:00 2001 From: Isak Van Der Walt Date: Sun, 13 Oct 2024 15:12:20 +0200 Subject: [PATCH] (fix) show correct path dirListing. --- agent/src/generic/http.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/agent/src/generic/http.ts b/agent/src/generic/http.ts index 9ffd595..ad56d4f 100644 --- a/agent/src/generic/http.ts +++ b/agent/src/generic/http.ts @@ -15,20 +15,22 @@ const dirListingHTML = (pwd: string, path: string): string => { let h = ` -

Index Of /

+

Index Of ${path}

{file_listing} `; h = h.replace(`{file_listing}`, () => { - return fs.list(pwd + path).map((f) => { + return fs.list(pwd + decodeURIComponent(path)).map((f) => { + if (f.name === '.') return; + // Add a slash at the end if it is a directory. var fname = f.name + (f.type == 4 ? '/' : ''); if (path !== '/') { return `${fname}`; - } else { + } else if (fname !== '../') { return `${fname}`; } }).join("
"); @@ -62,7 +64,7 @@ export const start = (pwd: string, port: number = 9000): void => { const fileLocation = pwd + decodeURIComponent(parsedUrl.path); if (fs.statSync(fileLocation).isDirectory()) { - res.end(dirListingHTML(pwd, decodeURIComponent(parsedUrl.path))); + res.end(dirListingHTML(pwd, parsedUrl.path)); return; }