Skip to content

Commit

Permalink
Added an endpoint for looking up files for a release
Browse files Browse the repository at this point in the history
This endpoint /release/files/RELEASE?files=FILE1,FILE2,...
will lookup whether the release has files corresponding to
the given file names and will return the names & paths for
the found files.
  • Loading branch information
mickeyn committed May 12, 2017
1 parent 896370a commit 12f681c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -505,5 +505,34 @@ sub get_contributors {
return { contributors => \@contribs };
}

sub get_files {
my ( $self, $release, $files ) = @_;

my $query = +{
query => {
bool => {
must => [
{ term => { release => $release } },
{ terms => { name => $files } }
],
}
}
};

my $ret = $self->es->search(
index => $self->index->name,
type => 'file',
body => {
query => $query,
size => 999,
_source => [qw< name path >],
}
);

return {} unless @{ $ret->{hits}{hits} };

return { files => [ map { $_->{_source} } @{ $ret->{hits}{hits} } ] };
}

__PACKAGE__->meta->make_immutable;
1;
10 changes: 10 additions & 0 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -58,5 +58,15 @@ sub contributors : Path('contributors') : Args(1) {
$c->stash($data);
}

sub files : Path('files') : Args(1) {
my ( $self, $c, $name ) = @_;
my $files = $c->req->params->{files};
return unless $files;
my @files = split /,/, $files;
my $data = $self->model($c)->raw->get_files($name, \@files);
$c->stash($data);
}


__PACKAGE__->meta->make_immutable;
1;

0 comments on commit 12f681c

Please sign in to comment.