summary refs log tree commit diff stats
path: root/lib/Crater
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2022-06-11 21:26:49 +0530
committerAndinus <andinus@nand.sh>2022-06-11 21:26:49 +0530
commit234c399f59a23ef5af86148a67526319b8a79b8d (patch)
tree90a6fbda1d32fb7e5cb78d7d54d000cafcb7fa66 /lib/Crater
parentdcceb30788af8433e8184ab15fe8833f5539145b (diff)
downloadcrater-234c399f59a23ef5af86148a67526319b8a79b8d.tar.gz
Code cleanup, document blocks
Diffstat (limited to 'lib/Crater')
-rw-r--r--lib/Crater/Routes.rakumod3
-rw-r--r--lib/Crater/Routes/Auth.rakumod1
-rw-r--r--lib/Crater/Routes/Gallery.rakumod15
-rw-r--r--lib/Crater/Service.rakumod7
4 files changed, 12 insertions, 14 deletions
diff --git a/lib/Crater/Routes.rakumod b/lib/Crater/Routes.rakumod
index cf4c5eb..1400acf 100644
--- a/lib/Crater/Routes.rakumod
+++ b/lib/Crater/Routes.rakumod
@@ -5,12 +5,13 @@ use Crater::Gallery;
 use Crater::Routes::Auth;
 use Crater::Routes::Gallery;
 
+#| routes contains all routes. This block may contain unauthenticated
+#| paths.
 sub routes(
     Crater::Gallery :$gallery!, #= gallery object
     Str :$password!, #= password for authentication
 ) is export {
     template-location 'templates/';
-
     route {
         after { redirect '/login', :see-other if .status == 401 };
 
diff --git a/lib/Crater/Routes/Auth.rakumod b/lib/Crater/Routes/Auth.rakumod
index aef2c48..46100f5 100644
--- a/lib/Crater/Routes/Auth.rakumod
+++ b/lib/Crater/Routes/Auth.rakumod
@@ -3,6 +3,7 @@ use Cro::WebApp::Template;
 
 use Crater::Session;
 
+#| auth-routes contains routes related to authentication.
 sub auth-routes(
     Str :$password!, #= password for authentication
 ) is export {
diff --git a/lib/Crater/Routes/Gallery.rakumod b/lib/Crater/Routes/Gallery.rakumod
index ebf40b4..9c7fc0a 100644
--- a/lib/Crater/Routes/Gallery.rakumod
+++ b/lib/Crater/Routes/Gallery.rakumod
@@ -4,6 +4,8 @@ use Cro::WebApp::Template;
 use Crater::Gallery;
 use Crater::Session;
 
+#| gallery-routes contains routes for gallery view, images. Routes in
+#| this block must be authenticated.
 sub gallery-routes(
     Crater::Gallery :$gallery!, #= gallery object
 ) is export {
@@ -21,24 +23,21 @@ sub gallery-routes(
             # Generates a navigation bar for nested directories.
             my @nav = %(name => "home", url => "/"), ;
             for @path.kv -> $idx, $p {
-                next if $p eq "";
-                push @nav, %(
-                    name => $p,
-                    url => (@nav[*-1]<url> ~ $p ~ "/")
-                );
+                next if $p eq '';
+                @nav.push: %(name => $p, url => (@nav[*-1]<url> ~ $p ~ "/"));
             }
 
             template 'gallery.crotmp', {
+                :@nav,
+                show-nav => @path.elems ?? True !! False,
                 gallery => $gallery.list(sub-dir => @path),
                 title => $gallery.title() // "Gallery",
-                nav => @nav,
-                show-nav => @path.elems ?? True !! False
             };
         }
 
         # Redirect to login page if not logged in.
         get -> *@path {
-            redirect '/login', :see-other;
+            response.status = 401;
         }
     }
 }
diff --git a/lib/Crater/Service.rakumod b/lib/Crater/Service.rakumod
index 1119e5b..35fb3af 100644
--- a/lib/Crater/Service.rakumod
+++ b/lib/Crater/Service.rakumod
@@ -8,7 +8,7 @@ use Crater::Routes;
 use Crater::Gallery;
 use Crater::Session;
 
-#| Crater is a photo gallery
+#| Crater is a photo gallery.
 sub MAIN(
     IO() :$config where *.IO.f = 'resources/config.toml', #= configuration file
     IO() :$directory! where *.IO.d, #= gallery directory (takes absolute path)
@@ -19,12 +19,9 @@ sub MAIN(
     put "Gallery: {$directory.absolute}";
     put "Password: $password";
 
-    my %conf = from-toml($config.slurp);
-    %conf<server><host> //= %*ENV<CRATER_HOST>;
-    %conf<server><port> //= %*ENV<CRATER_PORT>;
-
     my Crater::Gallery $gallery = Crater::Gallery.new(:$directory);
 
+    my %conf = from-toml($config.slurp);
     my Cro::Service $http = Cro::HTTP::Server.new(
         http => <1.1>,
         allowed-methods => <GET POST>,