about summary refs log tree commit homepage
path: root/lib/PublicInbox/NewsWWW.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-28 01:57:14 +0000
committerEric Wong <e@80x24.org>2016-05-28 01:57:39 +0000
commit528230a0411897a14cbb79d0dae02ea89827bf1e (patch)
treeae71b388a84c8a8526b1908e77b00cb57d2cd340 /lib/PublicInbox/NewsWWW.pm
parent666b537fb9d3984370d75f16eae43c2ced752963 (diff)
downloadpublic-inbox-528230a0411897a14cbb79d0dae02ea89827bf1e.tar.gz
Most of its functionality is in the PublicInbox::Inbox class.

While we're at it, we no longer auto-create newsgroup names
based on the inbox name, since newsgroup names probably deserve
some thought when it comes to hierarchy.
Diffstat (limited to 'lib/PublicInbox/NewsWWW.pm')
-rw-r--r--lib/PublicInbox/NewsWWW.pm38
1 files changed, 3 insertions, 35 deletions
diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm
index 5357059d..908c4351 100644
--- a/lib/PublicInbox/NewsWWW.pm
+++ b/lib/PublicInbox/NewsWWW.pm
@@ -19,7 +19,6 @@ sub new {
 
 sub call {
         my ($self, $env) = @_;
-        my $ng_map = $self->newsgroup_map;
         my $path = $env->{PATH_INFO};
         $path =~ s!\A/+!!;
         $path =~ s!/+\z!!;
@@ -27,11 +26,11 @@ sub call {
         # some links may have the article number in them:
         # /inbox.foo.bar/123456
         my ($ng, $article) = split(m!/+!, $path, 2);
-        if (my $info = $ng_map->{$ng}) {
-                my $url = PublicInbox::Hval::prurl($env, $info->{url});
+        if (my $inbox = $self->{pi_config}->lookup_newsgroup($ng)) {
+                my $url = PublicInbox::Hval::prurl($env, $inbox->{url});
                 my $code = 301;
                 if (defined $article && $article =~ /\A\d+\z/) {
-                        my $mid = eval { ng_mid_for($ng, $info, $article) };
+                        my $mid = eval { $inbox->mm->mid_for($article) };
                         if (defined $mid) {
                                 # article IDs are not stable across clones,
                                 # do not encourage caching/bookmarking them
@@ -47,35 +46,4 @@ sub call {
         [ 404, [ 'Content-Type' => 'text/plain' ], [] ];
 }
 
-sub ng_mid_for {
-        my ($ng, $info, $article) = @_;
-        # may fail due to lack of Danga::Socket
-        # for defer_weaken:
-        require PublicInbox::NewsGroup;
-        $ng = $info->{ng} ||=
-                PublicInbox::NewsGroup->new($ng, $info->{git_dir}, '');
-        $ng->mm->mid_for($article);
-}
-
-sub newsgroup_map {
-        my ($self) = @_;
-        my $rv;
-        $rv = $self->{ng_map} and return $rv;
-        my $pi_config = $self->{pi_config};
-        my %ng_map;
-        foreach my $k (keys %$pi_config) {
-                $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-                my $inbox = $1;
-                my $git_dir = $pi_config->{"publicinbox.$inbox.mainrepo"};
-                my $url = $pi_config->{"publicinbox.$inbox.url"};
-                defined $url or next;
-                my $ng = $pi_config->{"publicinbox.$inbox.newsgroup"};
-                next if (!defined $ng) || ($ng eq ''); # disabled
-
-                $url =~ m!/\z! or $url .= '/';
-                $ng_map{$ng} = { url => $url, git_dir => $git_dir };
-        }
-        $self->{ng_map} = \%ng_map;
-}
-
 1;