123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #!/usr/bin/env perl
- use Modern::Perl;
- use Mojolicious::Lite;
- use Mojo::Cache;
- use Archive::Tar;
- use File::Basename;
- use Sort::Versions;
- use Encode qw(decode_utf8);
- my $dir = "/home/alex/oddmuse.org/releases";
- my $cache = Mojo::Cache->new(max_keys => 50);
- sub tarballs {
- my @tarballs = reverse sort versioncmp map {
- my ($name, $path, $suffix) = fileparse($_, '.tar.gz');
- $name;
- } <$dir/*.tar.gz>;
- return \@tarballs;
- }
- sub tarball {
- my $tarball = shift;
- if ($tarball eq 'latest') {
- my $tarballs = tarballs();
- $tarball = shift @$tarballs;
- }
- return $tarball;
- }
- get '/' => sub {
- my $c = shift;
- my $tarballs = tarballs();
- unshift @$tarballs, 'latest';
- $c->render(template => 'index', tarballs => $tarballs);
- } => 'main';
- get '/#tarball' => sub {
- my $c = shift;
- my $tarball = 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 = 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';
- <h1>Oddmuse Releases</h1>
- <p>Welcome! This is where you get access to tarballs and files in released
- versions of Oddmuse.</p>
- <ul>
- % for my $tarball (@$tarballs) {
- <li>
- % if ($tarball ne 'latest') {
- <a href="https://oddmuse.org/releases/<%= $tarball %>.tar.gz"><%= $tarball %>.tar.gz</a>
- % }
- (files for <%= link_to release => {tarball => $tarball} => begin %>\
- <%= $tarball =%><%= end %>)
- </li>
- % }
- </ul>
- @@ release.html.ep
- % layout 'default';
- % title 'Release';
- <h1>Files for <%= $tarball %></h1>
- <p>
- Back to the list of <%= link_to 'releases' => 'main' %>.
- Remember,
- %= link_to file => {file => 'wiki.pl'} => begin
- wiki.pl
- % end
- is the main script.
- <ul>
- % for my $file (@$files) {
- <li>
- %= link_to file => {file => $file} => begin
- %= $file
- % end
- % }
- </ul>
- @@ file.txt.ep
- %layout 'file';
- <%== $content %>
- @@ missing.html.ep
- % layout 'default';
- % title 'Missing File';
- <h1><%= $tarball %> is missing <%= $file %></h1>
- <p>
- You can go back to the list of <%= link_to 'releases' => 'main' %>,
- or you can try to find <%= $file %> in the
- <a href="https://raw.githubusercontent.com/kensanata/oddmuse/master/modules/<%= $file %>">unstable modules</a> section on GitHub.
- @@ layouts/default.html.ep
- <!DOCTYPE html>
- <html>
- <head>
- <title><%= title %></title>
- %= stylesheet '/tarballs.css'
- %= stylesheet begin
- body {
- padding: 1em;
- font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
- }
- % end
- <meta name="viewport" content="width=device-width">
- </head>
- <body>
- <%= content %>
- <hr>
- <p>
- <a href="https://oddmuse.org/">Oddmuse</a> 
- <%= link_to 'Releases' => 'main' %> 
- <a href="https://alexschroeder.ch/wiki/Contact">Alex Schroeder</a>
- </body>
- </html>
|