Skip to content

Commit

Permalink
GH#927 Add plain mode + version filter to release/versions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Oct 21, 2020
1 parent 6e3a37b commit 8fc0ac0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/MetaCPAN/Query/Release.pm
Expand Up @@ -560,11 +560,28 @@ sub all_by_author {
}

sub versions {
my ( $self, $dist ) = @_;
my ( $self, $dist, $versions ) = @_;

my $size = $dist eq 'perl' ? 1000 : 250;

my $query;

if ( @{$versions} ) {
$query = {
bool => {
must => [
{ term => { distribution => $dist } },
{ terms => { version => $versions } },
]
}
};
}
else {
$query = { term => { distribution => $dist } };
}

my $body = {
query => { term => { distribution => $dist } },
query => $query,
size => $size,
sort => [ { date => 'desc' } ],
fields => [
Expand Down
14 changes: 13 additions & 1 deletion lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -86,9 +86,21 @@ sub all_by_author : Path('all_by_author') : Args(1) {

sub versions : Path('versions') : Args(1) {
my ( $self, $c, $dist ) = @_;
my %params = %{ $c->req->params }{qw( plain versions )};
$c->add_dist_key($dist);
$c->cdn_max_age('1y');
$c->stash_or_detach( $self->model($c)->versions($dist) );
my $data = $self->model($c)
->versions( $dist, [ split /,/, $params{versions} || '' ] );

if ( $params{plain} ) {
my $data = join "\n",
map { join "\t", @{$_}{qw/ version download_url /} }
@{ $data->{releases} };
$c->res->body($data);
}
else {
$c->stash_or_detach($data);
}
}

sub top_uploaders : Path('top_uploaders') : Args() {
Expand Down

0 comments on commit 8fc0ac0

Please sign in to comment.