]> git.taranathan.com Git - filestuffs.git/commitdiff
file list
authorTaran Nathan <moogoesmeow123@gmail.com>
Thu, 11 Jun 2026 19:26:18 +0000 (15:26 -0400)
committerTaran Nathan <moogoesmeow123@gmail.com>
Thu, 11 Jun 2026 19:26:28 +0000 (15:26 -0400)
src/router.gleam

index 2036bc7cb3111964175031c6d0fe79246fd97172..cd1aad3f0fa4ad6b51586addc5620da01866ce70 100644 (file)
@@ -21,11 +21,32 @@ pub fn handle_request(
       wisp.ok()
     }
     "/new/" <> _path -> upload(req, password)
+    "/list" -> list(req, file_path)
     "/files/" <> path -> files(req, "/" <> path, file_path)
     _ -> wisp.not_found()
   }
 }
 
+fn list(req: wisp.Request, file_path: String) -> wisp.Response {
+  let files = simplifile.get_files(file_path) |> result.unwrap([])
+
+  let formatted =
+    files
+    |> list.fold("", fn(acc, file) {
+      acc
+      <> html_linkify(
+        file |> string.split("/") |> list.last |> result.unwrap(""),
+      )
+    })
+
+  wisp.html_response("<h1>FILE LIST!</h1><ul>" <> formatted <> "</ul>", 200)
+}
+
+fn html_linkify(file: String) -> String {
+  echo file
+  echo "<a href=\"/files/" <> file <> "\">" <> file <> "</a><br>"
+}
+
 fn files(req: wisp.Request, path: String, file_path) -> wisp.Response {
   //TODO case req.headers smth smth
   use <- wisp.serve_static(req, "/files", file_path)