]> git.taranathan.com Git - filestuffs.git/commitdiff
rename and add password to args
authorTaran Nathan <moogoesmeow123@gmail.com>
Thu, 11 Jun 2026 03:53:31 +0000 (23:53 -0400)
committerTaran Nathan <moogoesmeow123@gmail.com>
Thu, 11 Jun 2026 03:53:56 +0000 (23:53 -0400)
README.md
gleam.toml
src/filestuffs.gleam [new file with mode: 0644]
src/preview.gleam [deleted file]
src/router.gleam
test/filestuffs_test.gleam [new file with mode: 0644]
test/preview_test.gleam [deleted file]

index 6be9ddc5c259d599b6833b36dd4a39236aafaefd..7baa37095c9c7423ebe222e3e4bd4b2f8a4cfc84 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,20 +1,4 @@
-# preview
-
-[![Package Version](https://img.shields.io/hexpm/v/preview)](https://hex.pm/packages/preview)
-[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/preview/)
-
-```sh
-gleam add preview@1
-```
-```gleam
-import preview
-
-pub fn main() -> Nil {
-  // TODO: An example of the project in use
-}
-```
-
-Further documentation can be found at <https://hexdocs.pm/preview>.
+# file server!
 
 ## Development
 
index acf4aa93de5c98d25b8b6e626ae3aae71cb023a8..fc5046694cc1af70a9323d45cc21ccb253ee3e03 100644 (file)
@@ -1,4 +1,4 @@
-name = "preview"
+name = "filestuffs"
 version = "1.0.0"
 
 # Fill out these fields if you intend to generate HTML documentation or publish
diff --git a/src/filestuffs.gleam b/src/filestuffs.gleam
new file mode 100644 (file)
index 0000000..7121b60
--- /dev/null
@@ -0,0 +1,37 @@
+import argv
+import gleam/erlang/process
+import gleam/io
+import mist
+import router
+import wisp
+import wisp/wisp_mist
+
+pub fn main() -> Nil {
+  let args: List(String) = argv.load().arguments
+  case args {
+    ["greet", name] -> io.println("hello " <> name <> "!")
+    ["web", file_path, "-p", password] -> web(file_path, password)
+    _ -> io.println("bad args")
+  }
+
+  Nil
+}
+
+pub fn wassup() -> Int {
+  42
+}
+
+fn web(file_path: String, password: String) -> Nil {
+  wisp.configure_logger()
+
+  let secret_key_base = wisp.random_string(64)
+
+  let assert Ok(_) =
+    router.handle_request(_, file_path, password)
+    |> wisp_mist.handler(secret_key_base)
+    |> mist.new
+    |> mist.port(8000)
+    |> mist.start
+
+  process.sleep_forever()
+}
diff --git a/src/preview.gleam b/src/preview.gleam
deleted file mode 100644 (file)
index 947a17c..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-import argv
-import gleam/erlang/process
-import gleam/io
-import mist
-import router
-import wisp
-import wisp/wisp_mist
-
-pub fn main() -> Nil {
-  let args: List(String) = argv.load().arguments
-  case args {
-    ["greet", name] -> io.println("hello " <> name <> "!")
-    ["web", file_path] -> web(file_path)
-    _ -> io.println("bad args")
-  }
-
-  // wisp.configure_logger()
-
-  Nil
-}
-
-pub fn wassup() -> Int {
-  42
-}
-
-fn web(file_path: String) -> Nil {
-  wisp.configure_logger()
-
-  let secret_key_base = wisp.random_string(64)
-
-  let assert Ok(_) =
-    router.handle_request(_, file_path)
-    |> wisp_mist.handler(secret_key_base)
-    |> mist.new
-    |> mist.port(8000)
-    |> mist.start
-
-  process.sleep_forever()
-}
index c32d12b5e40d4721eebe8fa64763324d86b9da75..a30d11b7ae5f7d8ea0a035c20919a727edd6f78b 100644 (file)
@@ -4,7 +4,11 @@ import gleam/result
 import simplifile
 import wisp
 
-pub fn handle_request(req: wisp.Request, file_path: String) -> wisp.Response {
+pub fn handle_request(
+  req: wisp.Request,
+  file_path: String,
+  password: String,
+) -> wisp.Response {
   use req <- middleware(req)
   // use <- wisp.serve_static(req, "/files", file_path)
 
@@ -15,7 +19,7 @@ pub fn handle_request(req: wisp.Request, file_path: String) -> wisp.Response {
       use <- wisp.serve_static(req, "/styles.css", "./static/styles.css")
       wisp.ok()
     }
-    "/new/" <> _path -> upload(req)
+    "/new/" <> _path -> upload(req, password)
     "/files/" <> path -> files(req, "/" <> path, file_path)
     _ -> wisp.not_found()
   }
@@ -27,9 +31,7 @@ fn files(req: wisp.Request, path: String, file_path) -> wisp.Response {
   wisp.ok()
 }
 
-const password = "greg"
-
-pub fn upload(req: wisp.Request) -> wisp.Response {
+pub fn upload(req: wisp.Request, password: String) -> wisp.Response {
   use form <- wisp.require_form(req)
 
   //early return if incorrect password
diff --git a/test/filestuffs_test.gleam b/test/filestuffs_test.gleam
new file mode 100644 (file)
index 0000000..8abeb09
--- /dev/null
@@ -0,0 +1,18 @@
+import filestuffs
+import gleeunit
+
+pub fn main() -> Nil {
+  gleeunit.main()
+}
+
+// gleeunit test functions end in `_test`
+pub fn hello_world_test() {
+  let name = "Joe"
+  let greeting = "Hello, " <> name <> "!"
+
+  assert greeting == "Hello, Joe!"
+}
+
+pub fn wassup_test() {
+  assert filestuffs.wassup() == 42
+}
diff --git a/test/preview_test.gleam b/test/preview_test.gleam
deleted file mode 100644 (file)
index 456d957..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-import gleeunit
-import preview
-
-pub fn main() -> Nil {
-  gleeunit.main()
-}
-
-// gleeunit test functions end in `_test`
-pub fn hello_world_test() {
-  let name = "Joe"
-  let greeting = "Hello, " <> name <> "!"
-
-  assert greeting == "Hello, Joe!"
-}
-
-pub fn wassup_test() {
-  assert preview.wassup() == 42
-}