Files
oddmuse/scripts/tarballs.pl

136 lines
3.2 KiB
Perl
Raw Normal View History

2016-06-23 18:33:42 +02:00
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::Cache;
2016-06-23 18:33:42 +02:00
use Archive::Tar;
use File::Basename;
2016-06-24 12:29:19 +02:00
use Encode qw(decode_utf8);
2016-06-23 18:33:42 +02:00
my $dir = "/home/alex/oddmuse.org/releases";
my $cache = Mojo::Cache->new(max_keys => 50);
2016-06-23 18:33:42 +02:00
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 {
2016-06-23 18:33:42 +02:00
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);
2016-06-23 18:33:42 +02:00
} => 'release';
get '/#tarball/#file' => sub {
2016-06-23 18:33:42 +02:00
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");
2016-06-24 12:29:19 +02:00
$text = decode_utf8($tar->get_content("$tarball/$file"));
$cache->set("$tarball/$file" => $text);
}
2016-08-03 12:52:29 +02:00
if ($text) {
$c->render(template => 'file', format => 'txt', content => $text);
} else {
$c->render(template => 'missing');
}
2016-06-23 18:33:42 +02:00
} => 'file';
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Oddmuse Releases';
<h1>Oddmuse Releases</h1>
2016-06-23 18:33:42 +02:00
<p>Welcome! This is where you get access to tarballs and files in released
versions of Oddmuse.</p>
<ul>
% for my $tarball (@$tarballs) {
<li>
<a href="https://oddmuse.org/releases/<%= $tarball %>.tar.gz"><%= $tarball %>.tar.gz</a>
(files for <%= link_to release => {tarball => $tarball} => begin %>\
<%= $tarball =%><%= end %>)
</li>
2016-06-23 18:33:42 +02:00
% }
</ul>
@@ release.html.ep
% layout 'default';
% title 'Release';
<h1>Files for <%= $tarball %></h1>
2016-06-23 18:33:42 +02:00
<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.
2016-06-23 18:33:42 +02:00
<ul>
% for my $file (@$files) {
<li>
%= link_to file => {file => $file} => begin
%= $file
% end
% }
</ul>
@@ file.txt.ep
%layout 'file';
<%== $content %>
2016-06-23 18:33:42 +02:00
2016-08-03 12:52:29 +02:00
@@ 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.
2016-06-23 18:33:42 +02:00
@@ 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>&#x2003;
<%= link_to 'Releases' => 'main' %>&#x2003;
<a href="https://alexschroeder.ch/wiki/Contact">Alex Schroeder</a>
2016-06-23 18:33:42 +02:00
</body>
</html>