diff options
author | Olivier Thauvin <nanardon@mageia.org> | 2010-11-05 20:33:33 +0000 |
---|---|---|
committer | Olivier Thauvin <nanardon@mageia.org> | 2010-11-05 20:33:33 +0000 |
commit | f81b033210bf91cd464e88417a759dc7a06275fb (patch) | |
tree | 45d758327c327e832d02e14b6768cd28536b5fb1 /lib/MGA | |
parent | b6a1e038f23f29127bfc97589b5663cebf4dcd76 (diff) | |
download | mgamirrors-f81b033210bf91cd464e88417a759dc7a06275fb.tar mgamirrors-f81b033210bf91cd464e88417a759dc7a06275fb.tar.gz mgamirrors-f81b033210bf91cd464e88417a759dc7a06275fb.tar.bz2 mgamirrors-f81b033210bf91cd464e88417a759dc7a06275fb.tar.xz mgamirrors-f81b033210bf91cd464e88417a759dc7a06275fb.zip |
- add support for mirror list
Diffstat (limited to 'lib/MGA')
-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)); |