use strict;
use warnings;
use Plack::Request;
-use PublicInbox::Config qw(try_cat);
+use PublicInbox::Config;
use URI::Escape qw(uri_escape_utf8 uri_unescape);
use constant SSOMA_URL => '//ssoma.public-inbox.org/';
use constant PI_URL => '//public-inbox.org/';
our $INBOX_RE = qr!\A/([\w\.\-]+)!;
our $MID_RE = qr!([^/]+)!;
our $END_RE = qr!(T/|t/|R/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
+our $ATTACH_RE = qr!(\d[\.\d]*)-([[:alnum:]][\w\.-]+[[:alnum:]])!i;
sub new {
my ($class, $pi_config) = @_;
sub call {
my ($self, $env) = @_;
my $cgi = Plack::Request->new($env);
- my $ctx = { cgi => $cgi, pi_config => $self->{pi_config} };
+ my $ctx = {cgi => $cgi, pi_config => $self->{pi_config}, www => $self};
my $path_info = $cgi->path_info;
my $method = $cgi->method;
} elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$END_RE\z!o) {
msg_page($self, $ctx, $1, $2, $3);
+ } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$ATTACH_RE\z!o) {
+ my ($idx, $fn) = ($3, $4);
+ invalid_inbox_mid($self, $ctx, $1, $2) ||
+ get_attach($ctx, $idx, $fn);
# in case people leave off the trailing slash:
} elsif ($path_info =~ m!$INBOX_RE/$MID_RE/(T|t|R)\z!o) {
my ($inbox, $mid, $suffix) = ($1, $2, $3);
foreach (qw(PublicInbox::Search PublicInbox::SearchView
PublicInbox::Mbox IO::Compress::Gzip
- PublicInbox::NewsWWW PublicInbox::NewsGroup)) {
+ PublicInbox::NewsWWW)) {
eval "require $_;";
}
}
# returns undef if valid, array ref response if invalid
sub invalid_inbox {
- my ($self, $ctx, $inbox, $mid) = @_;
+ my ($self, $ctx, $inbox) = @_;
my $obj = $ctx->{pi_config}->lookup_name($inbox);
if (defined $obj) {
$ctx->{git_dir} = $obj->{mainrepo};
$ctx->{git} = $obj->git;
+ # for PublicInbox::HTTP::weaken_task:
+ $ctx->{cgi}->{env}->{'pi-httpd.inbox'} = $obj;
$ctx->{-inbox} = $obj;
$ctx->{inbox} = $inbox;
return;
# returns undef if valid, array ref response if invalid
sub invalid_inbox_mid {
my ($self, $ctx, $inbox, $mid) = @_;
- my $ret = invalid_inbox($self, $ctx, $inbox, $mid);
+ my $ret = invalid_inbox($self, $ctx, $inbox);
return $ret if $ret;
$ctx->{mid} = $mid = uri_unescape($mid);
my ($ctx) = @_;
return '' unless $ctx;
my $obj = $ctx->{-inbox} or return '';
- my $footer = $obj->footer_html;
- return $ctx->{footer} = $footer if $footer;
# auto-generate a footer
chomp(my $desc = $obj->description);
sub r301 {
my ($ctx, $inbox, $mid, $suffix) = @_;
my $cgi = $ctx->{cgi};
- my $url;
+ my $obj = $ctx->{-inbox};
+ unless ($obj) {
+ my $r404 = invalid_inbox($ctx->{www}, $ctx, $inbox);
+ return $r404 if $r404;
+ $obj = $ctx->{-inbox};
+ }
+ my $url = $obj->base_url($cgi);
my $qs = $cgi->env->{QUERY_STRING};
- $url = $cgi->base->as_string . $inbox . '/';
$url .= (uri_escape_utf8($mid) . '/') if (defined $mid);
$url .= $suffix if (defined $suffix);
$url .= "?$qs" if $qs ne '';
$self->{news_www} = PublicInbox::NewsWWW->new($self->{pi_config});
}
+sub get_attach {
+ my ($ctx, $idx, $fn) = @_;
+ require PublicInbox::WwwAttach;
+ PublicInbox::WwwAttach::get_attach($ctx, $idx, $fn);
+}
+
1;