Skip to content

Commit

Permalink
[#1032] Convert htdocs/misc/feedping.bml from BML
Browse files Browse the repository at this point in the history
  • Loading branch information
afuna committed Nov 4, 2014
1 parent 06e8abf commit fa2075d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
47 changes: 47 additions & 0 deletions cgi-bin/DW/Controller/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,59 @@ use DW::Controller;
use DW::Routing;
use DW::Template;

DW::Routing->register_string( '/misc/feedping', \&feedping_handler, app => 1 );
DW::Routing->register_string( '/misc/whereami', \&whereami_handler, app => 1 );
DW::Routing->register_string( '/pubkey', \&pubkey_handler, app => 1 );
DW::Routing->register_string( '/guidelines', \&community_guidelines, user => 1 );
DW::Routing->register_string( "/random/index", \&random_personal_handler, app => 1 );
DW::Routing->register_string( "/community/random/index", \&random_community_handler, app => 1 );

sub feedping_handler {
my ( $opts ) = @_;

my ( $ok, $rv ) = controller( anonymous => 1, form_auth => 0 );
return $rv unless $ok;

my $r = $rv->{r};
my $error_out = sub {
my ( $code, $message ) = @_;
$r->status( $code );
$r->print( $message );
return $r->OK;
};

my $out = sub {
my ( $message ) = @_;
$r->print( $message );
return $r->OK;
};

return $out->( "This is a REST-like interface for pinging $LJ::SITENAMESHORT feed crawler to re-fetch a syndication URL. Do a POST to this URL with a 'feed' parameter equal to the URL. Possible HTTP responses are 400 (bad request), 404 (we're not indexing that feed), or 204 (we'll get to it soon). (also permitted are multiple feed parameters, if you're not sure we're indexing your Atom vs RSS, etc. At most 3 are currently accepted.)" )
unless $r->did_post;


my $post = $r->post_args;
my $test_url = $post->{feed};
return $error_out->( $r->HTTP_BAD_REQUEST, "No 'feed' parameter with URL." )
unless $test_url;

my @feeds = $post->get_all( "feed" );
return $error_out->( $r->HTTP_BAD_REQUEST, "Too many 'feed' parameters." )
if @feeds > 3;

my $updated = 0;
my $dbh = LJ::get_db_writer();
foreach my $url ( @feeds ) {
$updated = 1 if
$dbh->do( "UPDATE syndicated SET checknext=NOW() WHERE synurl=?", undef, $url ) > 0;
}

return $out->( "Thanks! We'll get to it soon." )
if $updated;

return $error_out->( $r->NOT_FOUND, "Unknown feed(s)." );
}

# handles the /misc/whereami page
sub whereami_handler {
my ( $ok, $rv ) = controller( authas => 1 );
Expand Down
48 changes: 0 additions & 48 deletions htdocs/misc/feedping.bml

This file was deleted.

0 comments on commit fa2075d

Please sign in to comment.