From 8419f31aca48d73cdecbcc90992884db5d0ffcfc Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 19 Dec 2022 01:14:01 +0100 Subject: File browser: sort files --- src/io/file.nim | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/io/file.nim b/src/io/file.nim index b35aee09..092810e2 100644 --- a/src/io/file.nim +++ b/src/io/file.nim @@ -1,3 +1,4 @@ +import algorithm import os import streams import tables @@ -20,7 +21,11 @@ proc loadDir(url: URL, path: string, ostream: Stream) =

Directory list of """ & path & """

[DIR]  ../
""") + var fs: seq[(PathComponent, string)] for pc, file in walkDir(path, relative = true): + fs.add((pc, file)) + fs.sort(cmp = proc(a, b: (PathComponent, string)): int = cmp(a[1], b[1])) + for (pc, file) in fs: case pc of pcDir: ostream.write("[DIR]  ") @@ -41,7 +46,21 @@ proc loadDir(url: URL, path: string, ostream: Stream) = ostream.flush() proc loadSymlink(path: string, ostream: Stream) = - discard + ostream.swrite(0) + ostream.swrite(200) # ok + ostream.swrite(newHeaderList({"Content-Type": "text/html"}.toTable())) + let sl = expandSymlink(path) + ostream.write(""" + + +Symlink view<TITLE> +</HEAD> +<BODY> +Symbolic link to <A HREF="""" & sl & """">""" & sl & """</A></br> +</BODY> +</HTML>""") + ostream.flush() + proc loadFile*(url: URL, ostream: Stream) = when defined(windows) or defined(OS2) or defined(DOS): -- cgit