From: Taran Nathan Date: Thu, 11 Jun 2026 19:26:18 +0000 (-0400) Subject: file list X-Git-Url: https://git.taranathan.com/?a=commitdiff_plain;h=1171a1be0dce83819965cf85bf79ba483e1a44cc;p=filestuffs.git file list --- diff --git a/src/router.gleam b/src/router.gleam index 2036bc7..cd1aad3 100644 --- a/src/router.gleam +++ b/src/router.gleam @@ -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("

FILE LIST!

", 200) +} + +fn html_linkify(file: String) -> String { + echo file + echo " file <> "\">" <> file <> "
" +} + 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)