From 234c399f59a23ef5af86148a67526319b8a79b8d Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 11 Jun 2022 21:26:49 +0530 Subject: Code cleanup, document blocks --- lib/Crater/Routes.rakumod | 3 ++- lib/Crater/Routes/Auth.rakumod | 1 + lib/Crater/Routes/Gallery.rakumod | 15 +++++++-------- lib/Crater/Service.rakumod | 7 ++----- 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] ~ $p ~ "/") - ); + next if $p eq ''; + @nav.push: %(name => $p, url => (@nav[*-1] ~ $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 //= %*ENV; - %conf //= %*ENV; - 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 => , -- cgit 1.4.1-2-gfad0