#!/usr/bin/env perl use Mojolicious::Lite; use Mojo::Cache; use Archive::Tar; use File::Basename; use Encode qw(decode_utf8); my $dir = "/home/alex/oddmuse.org/releases"; my $cache = Mojo::Cache->new(max_keys => 50); get '/' => sub { my $c = shift; my @tarballs = sort map { my ($name, $path, $suffix) = fileparse($_, '.tar.gz'); $name; } <$dir/*.tar.gz>; $c->render(template => 'index', tarballs => \@tarballs); } => 'main'; get '/#tarball' => sub { my $c = shift; my $tarball = $c->param('tarball'); my $files = $cache->get($tarball); if (not $files) { $c->app->log->info("Reading $tarball.tar.gz"); my $tar = Archive::Tar->new; $tar->read("$dir/$tarball.tar.gz"); my @files = sort grep /./, map { my @e = split('/', $_->name); $e[1]; } $tar->get_files(); $files = \@files; $cache->set($tarball => $files); } $c->render(template => 'release', tarball=> $tarball, files => $files); } => 'release'; get '/#tarball/#file' => sub { my $c = shift; my $tarball = $c->param('tarball'); my $file = $c->param('file'); my $text = $cache->get("$tarball/$file"); if (not $text) { $c->app->log->info("Reading $tarball/$file"); my $tar = Archive::Tar->new; $tar->read("$dir/$tarball.tar.gz"); $text = decode_utf8($tar->get_content("$tarball/$file")); $cache->set("$tarball/$file" => $text); } if ($text) { $c->render(template => 'file', format => 'txt', content => $text); } else { $c->render(template => 'missing'); } } => 'file'; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title 'Oddmuse Releases';

Oddmuse Releases

Welcome! This is where you get access to tarballs and files in released versions of Oddmuse.

@@ release.html.ep % layout 'default'; % title 'Release';

Files for <%= $tarball %>

Back to the list of <%= link_to 'releases' => 'main' %>. Remember, %= link_to file => {file => 'wiki.pl'} => begin wiki.pl % end is the main script.

@@ file.txt.ep %layout 'file'; <%== $content %> @@ missing.html.ep % layout 'default'; % title 'Missing File';

<%= $tarball %> is missing <%= $file %>

You can go back to the list of <%= link_to 'releases' => 'main' %>, or you can try to find <%= $file %> in the unstable modules section on GitHub. @@ layouts/default.html.ep <%= title %> %= stylesheet '/tarballs.css' %= stylesheet begin body { padding: 1em; font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif; } % end <%= content %>


Oddmuse  <%= link_to 'Releases' => 'main' %>  Alex Schroeder