let args: List(String) = argv.load().arguments
case args {
["greet", name] -> io.println("hello " <> name <> "!")
- ["web", file_path, "-p", password] -> web(file_path, password)
+ ["web", file_path, "-p", ..passwords] -> web(file_path, passwords)
_ -> io.println("bad args")
}
42
}
-fn web(file_path: String, password: String) -> Nil {
+fn web(file_path: String, passwords: List(String)) -> Nil {
wisp.configure_logger()
let secret_key_base =
})
let assert Ok(_) =
- router.handle_request(_, file_path, password)
+ router.handle_request(_, file_path, passwords)
|> wisp_mist.handler(secret_key_base)
|> mist.new
|> mist.port(
pub fn handle_request(
req: wisp.Request,
file_path: String,
- password: String,
+ passwords: List(String),
) -> wisp.Response {
use req <- middleware(req)
// use <- wisp.serve_static(req, "/files", file_path)
use <- wisp.serve_static(req, "/styles.css", "./static/styles.css")
wisp.ok()
}
- "/new/" <> _path -> upload(req, password)
+ "/new/" <> _path -> upload(req, passwords)
"/list" -> list(req, file_path)
"/files/" <> path -> files(req, "/" <> path, file_path)
_ -> wisp.not_found()
}
fn html_linkify(file: String) -> String {
- echo file
- echo "<a href=\"/files/" <> file <> "\">" <> file <> "</a><br>"
+ "<a href=\"/files/" <> file <> "\">" <> file <> "</a><br>"
}
fn files(req: wisp.Request, path: String, file_path) -> wisp.Response {
wisp.ok()
}
-pub fn upload(req: wisp.Request, password: String) -> wisp.Response {
+pub fn upload(req: wisp.Request, passwords: List(String)) -> wisp.Response {
use form <- wisp.require_form(req)
//early return if incorrect password
+ let input_password = result.unwrap(list.key_find(form.values, "password"), "")
use <- bool.guard(
- when: result.unwrap(list.key_find(form.values, "password"), "") != password,
+ when: !list.any(passwords, fn(password) -> Bool {
+ input_password == password
+ }),
return: wisp.response(401),
)