mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
file server should order filenames (denoland/deno_std#511)
Original: 1365d287bc
This commit is contained in:
parent
a7dbd39270
commit
cd7ed28c36
1 changed files with 19 additions and 7 deletions
|
@ -145,8 +145,12 @@ async function serveDir(
|
||||||
dirPath: string,
|
dirPath: string,
|
||||||
dirName: string
|
dirName: string
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
|
interface ListItem {
|
||||||
|
name: string;
|
||||||
|
template: string;
|
||||||
|
}
|
||||||
// dirname has no prefix
|
// dirname has no prefix
|
||||||
const listEntry: string[] = [];
|
const listEntry: ListItem[] = [];
|
||||||
const fileInfos = await readDir(dirPath);
|
const fileInfos = await readDir(dirPath);
|
||||||
for (const info of fileInfos) {
|
for (const info of fileInfos) {
|
||||||
let fn = dirPath + "/" + info.name;
|
let fn = dirPath + "/" + info.name;
|
||||||
|
@ -159,21 +163,29 @@ async function serveDir(
|
||||||
try {
|
try {
|
||||||
mode = (await stat(fn)).mode;
|
mode = (await stat(fn)).mode;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
listEntry.push(
|
listEntry.push({
|
||||||
createDirEntryDisplay(
|
name: info.name,
|
||||||
|
template: createDirEntryDisplay(
|
||||||
info.name,
|
info.name,
|
||||||
fn.replace(currentDir, ""),
|
fn.replace(currentDir, ""),
|
||||||
info.isFile() ? info.len : null,
|
info.isFile() ? info.len : null,
|
||||||
mode,
|
mode,
|
||||||
info.isDirectory()
|
info.isDirectory()
|
||||||
)
|
)
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = new TextEncoder().encode(
|
const page = new TextEncoder().encode(
|
||||||
dirViewerTemplate
|
dirViewerTemplate.replace("<%DIRNAME%>", dirName + "/").replace(
|
||||||
.replace("<%DIRNAME%>", dirName + "/")
|
"<%CONTENTS%>",
|
||||||
.replace("<%CONTENTS%>", listEntry.join(""))
|
listEntry
|
||||||
|
.sort(
|
||||||
|
(a, b): number =>
|
||||||
|
a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1
|
||||||
|
)
|
||||||
|
.map((v): string => v.template)
|
||||||
|
.join("")
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
|
|
Loading…
Reference in a new issue