-use PublicInbox::View;
-use PublicInbox::Inbox;
-use bytes ();
-use HTTP::Date qw(time2str);
-require Digest::SHA;
-require File::Spec;
-*try_cat = \&PublicInbox::Inbox::try_cat;
-
-sub list_all_i {
- my ($ibx, $arg) = @_;
- my ($list, $hide_key) = @$arg;
- push @$list, $ibx unless $ibx->{-hide}->{$hide_key};
-}
-
-sub list_all ($$$) {
- my ($self, $env, $hide_key) = @_;
- my $list = [];
- $self->{pi_config}->each_inbox(\&list_all_i, [ $list, $hide_key ]);
- $list;
-}
-
-sub list_match_domain_i {
- my ($ibx, $arg) = @_;
- my ($list, $hide_key, $re) = @$arg;
- if (!$ibx->{-hide}->{$hide_key} && $ibx->{url} =~ $re) {
- push @$list, $ibx;
- }
-}
-
-sub list_match_domain ($$$) {
- my ($self, $env, $hide_key) = @_;
- my $list = [];
- my $host = $env->{HTTP_HOST} // $env->{SERVER_NAME};
- $host =~ s/:[0-9]+\z//;
- my $arg = [ $list, $hide_key,
- qr!\A(?:https?:)?//\Q$host\E(?::[0-9]+)?/!i ];
- $self->{pi_config}->each_inbox(\&list_match_domain_i, $arg);
- $list;
-}
-
-sub list_404 ($$) { [] }
-
-# TODO: +cgit
-my %VALID = (
- all => *list_all,
- 'match=domain' => *list_match_domain,
- 404 => *list_404,
-);
-
-sub set_cb ($$$) {
- my ($pi_config, $k, $default) = @_;
- my $v = $pi_config->{lc $k} // $default;
- $VALID{$v} || do {
- warn <<"";
-`$v' is not a valid value for `$k'
-$k be one of `all', `match=domain', or `404'
-
- $VALID{$default};
- };
-}
-
-sub new {
- my ($class, $www) = @_;
- my $pi_config = $www->{pi_config};
- bless {
- pi_config => $pi_config,
- style => $www->style("\0"),
- www_cb => set_cb($pi_config, 'publicInbox.wwwListing', 404),
- manifest_cb => set_cb($pi_config, 'publicInbox.grokManifest',
- 'match=domain'),
- }, $class;
-}