aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-26 21:53:41 +0000
committerFuwn <[email protected]>2024-07-26 21:53:41 +0000
commit865b0769fda344cb4b6f6a75d9698f5acdc79107 (patch)
tree6e0ec372b62ae895f42c5a5ba0bfb57c9b25c27f
parentchore: bump version (diff)
downloadmomoka-865b0769fda344cb4b6f6a75d9698f5acdc79107.tar.xz
momoka-865b0769fda344cb4b6f6a75d9698f5acdc79107.zip
fix(gemini): remove assertions
-rw-r--r--src/gemini.gleam60
-rw-r--r--src/gopher.gleam2
2 files changed, 41 insertions, 21 deletions
diff --git a/src/gemini.gleam b/src/gemini.gleam
index 52d5e08..c835d37 100644
--- a/src/gemini.gleam
+++ b/src/gemini.gleam
@@ -23,31 +23,51 @@ pub fn get_gemtext_from_capsule(message) {
Ok(proxy) -> proxy
_ -> "https://fuwn.me/raw/"
}
- let assert Ok(request) = case bit_array.to_string(message) {
- Ok(path) -> {
- case string.split(path, "/") {
- ["/\r\n"] | ["\r\n"] | ["\n"] ->
- request.to(gemini_proxy <> root_capsule)
- ["", "proxy", ..route] ->
- request.to(
- gemini_proxy
- <> gopher.trim_gopher_line_ending(string.join(route, "/")),
- )
- ["", ..path] ->
- request.to(
- gemini_proxy
- <> root_capsule
- <> "/"
- <> gopher.trim_gopher_line_ending(string.join(path, "/")),
+
+ case
+ case bit_array.to_string(message) {
+ Ok(path) -> {
+ case string.split(path, "/") {
+ ["/\r\n"] | ["\r\n"] | ["\n"] ->
+ request.to(gemini_proxy <> root_capsule)
+ ["", "proxy", ..route] ->
+ request.to(
+ gemini_proxy
+ <> gopher.trim_gopher_line_ending(string.join(route, "/")),
+ )
+ ["", ..path] ->
+ request.to(
+ gemini_proxy
+ <> root_capsule
+ <> "/"
+ <> gopher.trim_gopher_line_ending(string.join(path, "/")),
+ )
+ _ -> request.to(root_capsule <> gopher.trim_gopher_line_ending(path))
+ }
+ }
+ _ -> request.to(root_capsule)
+ }
+ {
+ Ok(request) -> {
+ case httpc.send(request) {
+ Ok(response) ->
+ bytes_builder.from_string(
+ gopher.gemtext_to_gopher(parse.parse_gemtext_raw(response.body))
+ <> "\r\n",
)
- _ -> request.to(root_capsule <> gopher.trim_gopher_line_ending(path))
+ Error(error) -> error_response(error)
}
}
- _ -> request.to(root_capsule)
+ Error(error) -> error_response(error)
}
- let assert Ok(response) = httpc.send(request)
+}
+fn error_response(error) {
bytes_builder.from_string(
- gopher.gemtext_to_gopher(parse.parse_gemtext_raw(response.body)) <> "\r\n",
+ {
+ { "iAn error has occurred: " <> string.inspect(error) }
+ |> gopher.terminate_text_line
+ }
+ <> "\r\n",
)
}
diff --git a/src/gopher.gleam b/src/gopher.gleam
index 1c8b277..0ef4f1b 100644
--- a/src/gopher.gleam
+++ b/src/gopher.gleam
@@ -9,7 +9,7 @@ pub fn trim_gopher_line_ending(line) {
|> string.replace("\r", "")
}
-fn terminate_text_line(line) {
+pub fn terminate_text_line(line) {
line <> "\tnull.host\t1\t70"
}