From: Mark Wooding Date: Sat, 17 Jun 2023 14:35:02 +0000 (+0100) Subject: mason/dhandler, static/tgal.css: Add option to download zipfiles. X-Git-Url: https://git.distorted.org.uk/~mdw/tgal/commitdiff_plain/aa5c3a514d22d4cc6cec6b6e77dc1af4f122b825 mason/dhandler, static/tgal.css: Add option to download zipfiles. This might turn out to be a terrible mistake. --- diff --git a/mason/dhandler b/mason/dhandler index f523432..49e5f84 100755 --- a/mason/dhandler +++ b/mason/dhandler @@ -109,7 +109,11 @@ Failed to find ‘<% $path |h %>’. <&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"), head => $links &> -<& .breadcrumbs, what => "Folder", path => $path &> +<&| .breadcrumbs, what => "Folder", path => $path &> + + % % my $note = contents "$IMGROOT/$path/.tgal-note.html"; % if (defined $note) { @@ -154,6 +158,55 @@ Failed to find ‘<% $path |h %>’. % %###------------------------------------------------------------------------- +<%def .zip>\ +<%perl> + my $st = stat "$IMGROOT/$path"; + if (!$st) { $m->comp(".not-found", path => $path); return; } + my $zip = "$TMP/t$$-download.zip"; + my $err = "$TMP/t$$-download.stderr"; + my $kid = fork; + if (!$kid) { + untie *STDIN; open STDIN, "/dev/null"; + untie *STDERR; open STDERR, ">", $err; + chdir "$IMGROOT/$path"; + exec "zip", "-qr", $zip, "."; + exit 127; + } + waitpid $kid, 0; + +% +% if ($?) { +<&| .html, title => "Zip failed (rc = $?)" &> +
+<%perl>
+	open my $f, "<", $err;
+	my $buf;
+	while (read $f, $buf, 16384) { $m->print($buf); }
+
+
+ +% } else { +<%perl> + $r->content_type("application/zip"); + open my $f, "<", $zip; binmode $f; + my $buf; + while (read $f, $buf, 16384) { $m->print($buf); } + +% } +% +<%perl> + eval { unlink $zip; }; + eval { unlink $err; }; + + +% +<%args> + $path + + +% +%###------------------------------------------------------------------------- <%def .image>\ <%perl> my ($dir, $base, $ext) = split_path $path; @@ -348,7 +401,13 @@ Failed to find ‘<% $path |h %>’. my $path = $m->dhandler_arg; my $st = stat "$IMGROOT/$path"; my $comp; - if (!$st) { $comp = ".not-found"; } + if (!$st) { + $comp = ".not-found"; + if ($path =~ /^ (.*) (\.(?: zip)) $/x) { + $st = stat "$IMGROOT/$1"; + if ($st) { $path = $1; $comp = $2; } + } + } elsif (-d $st) { $comp = ".contact"; } elsif (-f $st) { $comp = ".image"; } else { $comp = ".not-found"; } diff --git a/static/tgal.css b/static/tgal.css index b94038e..aa64878 100644 --- a/static/tgal.css +++ b/static/tgal.css @@ -61,6 +61,18 @@ h1, h2, h3, h4, h5, h6 { font-family: sans-serif; font-weight bold; } hr { width: calc(100% - 4em); } div.fill { flex-grow: 1; } +div.menu { + font-family: sans; + font-weight: normal; + font-size: initial; + float: right; +} +h1 div.menu:before { + visibility: hidden; + font-size: 200%; + content: ""; +} + div.footer { border-top: medium black solid; margin-top: 3.43ex;