]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwAltId.pm
wwwaltid: inform users to use POST instead of GET
[public-inbox.git] / lib / PublicInbox / WwwAltId.pm
index 34641a926c0c4393ac08562f437c07b89d04cff6..263e884aa445c92b588c1637546166b343205399 100644 (file)
@@ -10,18 +10,6 @@ use PublicInbox::AltId;
 use PublicInbox::Spawn qw(which);
 our $sqlite3 = $ENV{SQLITE3};
 
-# returns prefix => pathname mapping
-# (pathname is NOT public, but prefix is used for Xapian queries)
-sub altid_map ($) {
-       my ($ibx) = @_;
-       my $altid = $ibx->{altid} or return {};
-       my %h = map {;
-               my $x = PublicInbox::AltId->new($ibx, $_);
-               "$x->{prefix}" => $x->{filename}
-       } @$altid;
-       \%h;
-}
-
 sub sqlite3_missing ($) {
        PublicInbox::WwwResponse::oneshot($_[0], 501, \<<EOF);
 <pre>sqlite3 not available
@@ -50,8 +38,9 @@ sub check_output {
 # and thus not usable from DBD::SQLite.
 sub sqldump ($$) {
        my ($ctx, $altid_pfx) = @_;
+       my $env = $ctx->{env};
        my $ibx = $ctx->{-inbox};
-       my $altid_map = $ibx->{-altid_map} //= altid_map($ibx);
+       my $altid_map = $ibx->altid_map;
        my $fn = $altid_map->{$altid_pfx};
        unless (defined $fn) {
                return PublicInbox::WwwStream::oneshot($ctx, 404, \<<EOF);
@@ -59,6 +48,22 @@ sub sqldump ($$) {
 EOF
        }
 
+       if ($env->{REQUEST_METHOD} ne 'POST') {
+               my $url = $ibx->base_url($ctx->{env}) . "$altid_pfx.sql.gz";
+               return PublicInbox::WwwStream::oneshot($ctx, 405, \<<EOF);
+<pre>A POST request required to retrieve $altid_pfx.sql.gz
+
+       curl -XPOST -O $url
+
+or
+
+       curl -XPOST $url | \\
+               gzip -dc | \\
+               sqlite3 /path/to/$altid_pfx.sqlite3
+</pre>
+EOF
+       }
+
        eval { require PublicInbox::GzipFilter } or
                return PublicInbox::WwwStream::oneshot($ctx, 501, \<<EOF);
 <pre>gzip output not available
@@ -85,7 +90,6 @@ EOF
 
        # TODO: use -readonly if available with newer sqlite3(1)
        my $qsp = PublicInbox::Qspawn->new([$sqlite3, $fn], undef, { 0 => $r });
-       my $env = $ctx->{env};
        $ctx->{altid_pfx} = $altid_pfx;
        $env->{'qspawn.filter'} = PublicInbox::GzipFilter->new;
        $qsp->psgi_return($env, undef, \&check_output, $ctx);