summaryrefslogtreecommitdiff
path: root/std/http/file_server.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-16 06:40:30 +0100
committerGitHub <noreply@github.com>2020-04-16 01:40:30 -0400
commit5ac728a5f1af575d011c2143f5c9273b0fb4c5bb (patch)
treedfba0fdb3ba17989fd6c3af89ce17a0a71a4df0c /std/http/file_server.ts
parent6441852a1d5eef0d05ed172a00bef58ad5988842 (diff)
refactor(cli/js/ops/fs): Improve readdir() and FileInfo interfaces (#4763)
Diffstat (limited to 'std/http/file_server.ts')
-rwxr-xr-xstd/http/file_server.ts17
1 files changed, 8 insertions, 9 deletions
diff --git a/std/http/file_server.ts b/std/http/file_server.ts
index 468e8a60e..90f8b8792 100755
--- a/std/http/file_server.ts
+++ b/std/http/file_server.ts
@@ -140,11 +140,10 @@ async function serveDir(
): Promise<Response> {
const dirUrl = `/${posix.relative(target, dirPath)}`;
const listEntry: EntryInfo[] = [];
- const fileInfos = await readdir(dirPath);
- for (const fileInfo of fileInfos) {
- const filePath = posix.join(dirPath, fileInfo.name ?? "");
- const fileUrl = posix.join(dirUrl, fileInfo.name ?? "");
- if (fileInfo.name === "index.html" && fileInfo.isFile()) {
+ for await (const dirEntry of readdir(dirPath)) {
+ const filePath = posix.join(dirPath, dirEntry.name);
+ const fileUrl = posix.join(dirUrl, dirEntry.name);
+ if (dirEntry.name === "index.html" && dirEntry.isFile) {
// in case index.html as dir...
return serveFile(req, filePath);
}
@@ -154,9 +153,9 @@ async function serveDir(
mode = (await stat(filePath)).mode;
} catch (e) {}
listEntry.push({
- mode: modeToString(fileInfo.isDirectory(), mode),
- size: fileInfo.isFile() ? fileLenToString(fileInfo.size) : "",
- name: fileInfo.name ?? "",
+ mode: modeToString(dirEntry.isDirectory, mode),
+ size: dirEntry.isFile ? fileLenToString(dirEntry.size) : "",
+ name: dirEntry.name,
url: fileUrl,
});
}
@@ -333,7 +332,7 @@ function main(): void {
let response: Response | undefined;
try {
const info = await stat(fsPath);
- if (info.isDirectory()) {
+ if (info.isDirectory) {
response = await serveDir(req, fsPath);
} else {
response = await serveFile(req, fsPath);