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)