diff options
| author | Axetroy <troy450409405@gmail.com> | 2019-06-22 22:52:56 +0800 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-22 07:52:56 -0700 |
| commit | cd7ed28c36192cab035557677a3e1748bbdb0334 (patch) | |
| tree | 2a091ed0d19cebb1071b407035158d4aa773e4b1 /http/file_server.ts | |
| parent | a7dbd39270a3070d2c253111bedd47e7b55b180f (diff) | |
file server should order filenames (denoland/deno_std#511)
Original: https://github.com/denoland/deno_std/commit/1365d287bc97815b07f7ad298704756cb6877784
Diffstat (limited to 'http/file_server.ts')
| -rwxr-xr-x | http/file_server.ts | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/http/file_server.ts b/http/file_server.ts index 54979bf3e..7d1d132c9 100755 --- a/http/file_server.ts +++ b/http/file_server.ts @@ -145,8 +145,12 @@ async function serveDir( dirPath: string, dirName: string ): Promise<Response> { + interface ListItem { + name: string; + template: string; + } // dirname has no prefix - const listEntry: string[] = []; + const listEntry: ListItem[] = []; const fileInfos = await readDir(dirPath); for (const info of fileInfos) { let fn = dirPath + "/" + info.name; @@ -159,21 +163,29 @@ async function serveDir( try { mode = (await stat(fn)).mode; } catch (e) {} - listEntry.push( - createDirEntryDisplay( + listEntry.push({ + name: info.name, + template: createDirEntryDisplay( info.name, fn.replace(currentDir, ""), info.isFile() ? info.len : null, mode, info.isDirectory() ) - ); + }); } const page = new TextEncoder().encode( - dirViewerTemplate - .replace("<%DIRNAME%>", dirName + "/") - .replace("<%CONTENTS%>", listEntry.join("")) + dirViewerTemplate.replace("<%DIRNAME%>", dirName + "/").replace( + "<%CONTENTS%>", + listEntry + .sort( + (a, b): number => + a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1 + ) + .map((v): string => v.template) + .join("") + ) ); const headers = new Headers(); |
