1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # generates manifest.js.gz for grokmirror(1)
5 package PublicInbox::ManifestJsGz;
8 use parent qw(PublicInbox::WwwListing);
10 use PublicInbox::Config;
11 use IO::Compress::Gzip qw(gzip);
12 use HTTP::Date qw(time2str);
14 our $json = PublicInbox::Config::json();
16 # called by WwwListing
19 # grokmirror uses relative paths, so it's domain-dependent
20 # SUPER calls PublicInbox::WwwListing::url_regexp
21 $ctx->SUPER::url_regexp('publicInbox.grokManifest', 'match=domain');
24 sub manifest_add ($$;$$) {
25 my ($ctx, $ibx, $epoch, $default_desc) = @_;
26 my $url_path = "/$ibx->{name}";
29 $url_path .= "/git/$epoch.git";
30 $git = $ibx->git_epoch($epoch) or return;
34 my $ent = $git->manifest_entry($epoch, $default_desc) or return;
35 $ctx->{-abs2urlpath}->{$git->{git_dir}} = $url_path;
36 my $modified = $ent->{modified};
37 if ($modified > ($ctx->{-mtime} // 0)) {
38 $ctx->{-mtime} = $modified;
40 $ctx->{manifest}->{$url_path} = $ent;
46 if (defined(my $max = $ibx->max_git_epoch)) {
47 my $desc = $ibx->description;
48 for my $epoch (0..$max) {
49 manifest_add($ctx, $ibx, $epoch, $desc);
52 manifest_add($ctx, $ibx);
58 sub hide_key { 'manifest' }
60 # overrides WwwListing->psgi_triple
63 my $abs2urlpath = delete($ctx->{-abs2urlpath}) // {};
64 my $manifest = delete($ctx->{manifest}) // {};
65 while (my ($url_path, $repo) = each %$manifest) {
66 defined(my $abs = $repo->{reference}) or next;
67 $repo->{reference} = $abs2urlpath->{$abs};
69 $manifest = $json->encode($manifest);
70 gzip(\$manifest => \(my $out));
71 [ 200, [ qw(Content-Type application/gzip),
72 'Last-Modified', time2str($ctx->{-mtime}),
73 'Content-Length', bytes::length($out) ], [ $out ] ]