diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MGA/Mirrors/Controller/Api.pm | 79 | ||||
-rw-r--r-- | lib/MGA/Mirrors/DB.pm | 10 |
2 files changed, 85 insertions, 4 deletions
diff --git a/lib/MGA/Mirrors/Controller/Api.pm b/lib/MGA/Mirrors/Controller/Api.pm new file mode 100644 index 0000000..91846dc --- /dev/null +++ b/lib/MGA/Mirrors/Controller/Api.pm @@ -0,0 +1,79 @@ +package MGA::Mirrors::Controller::Api; +use Moose; +use namespace::autoclean; + +BEGIN {extends 'Catalyst::Controller'; } + +=head1 NAME + +MGA::Mirrors::Controller::Api - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 index + +=cut + +sub index :Path :Args(0) { + my ( $self, $c ) = @_; + + $c->response->body('Matched MGA::Mirrors::Controller::Api in Api.'); +} + +sub list :Path :Args(1) { + my ( $self, $c, $arg ) = @_; + + my ($product, $version, $arch) = $arg =~ m/^([^\.]+)\.(.+)\.([^\.]+)\.list$/; + + $c->log->debug("$product, $version, $arch"); + + my $list = $c->model('Mirrors')->find_distributions( + { + version => $version, + arch => $arch, + exists => 1, + public => 1, + } + ); + + $c->stash->{current_view} = ''; + $c->response->body(join("\n", + map { + my @tags; + push(@tags, 'continent=' . $_->{ccode}) if ($_->{ccode}); + push(@tags, 'zone=' . $_->{code}) if ($_->{code}); + push(@tags, 'country=' . $_->{country}) if ($_->{country}); + push(@tags, 'city=' . $_->{city}) if ($_->{city}); + push(@tags, 'latitude=' . $_->{latitude}) if ($_->{latitude}); + push(@tags, 'longitude=' . $_->{longitude}) if ($_->{longitude}); + push(@tags, 'version=' . $version); + push(@tags, 'version=' . $arch); + push(@tags, 'type=' . 'distrib'); + push(@tags, 'url=' . $_->{url}) if ($_->{url}); + join(',', @tags); + } @$list + ) . "\n"); +} + + +=head1 AUTHOR + +Olivier Thauvin + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/lib/MGA/Mirrors/DB.pm b/lib/MGA/Mirrors/DB.pm index da0534a..f8d1ac2 100644 --- a/lib/MGA/Mirrors/DB.pm +++ b/lib/MGA/Mirrors/DB.pm @@ -397,10 +397,12 @@ sub _find_distributions { $filters->{$_} or next; my $field = { hostname => 'hosts.hostname', - protocol => 'topelvel_urls.protocol', - version => 'distributions.version', - arch => 'distributions.arch', - country => 'mirrors.country', + protocol => 'toplevel_urls.protocol', + version => 'distributions.version', + arch => 'distributions.arch', + country => 'hosts.country', + exists => 'distributions_validity.exists', + public => 'hosts.public', }->{$_} or next; push(@w, sprintf('%s = any(?)', $field)); |