aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-19 01:14:01 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-19 01:14:01 +0100
commit8419f31aca48d73cdecbcc90992884db5d0ffcfc (patch)
treeff5b0deca8374d4b7e121a3174649ef6c6d4a129 /src
parenta04485f298d75ccbd8fc0b6fdd7be9ca63817cb0 (diff)
downloadchawan-8419f31aca48d73cdecbcc90992884db5d0ffcfc.tar.gz
File browser: sort files
Diffstat (limited to 'src')
-rw-r--r--src/io/file.nim21
1 files changed, 20 insertions, 1 deletions
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) =
<H1>Directory list of """ & path & """</H1>
[DIR]&nbsp; <A HREF="../">../</A></br>
""")
+ 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]&nbsp; ")
@@ -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("""
+<HTML>
+<HEAD>
+<TITLE>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):