[38] | 1 | package Sophie::Controller::0Explorer; |
---|
| 2 | use Moose; |
---|
| 3 | use namespace::autoclean; |
---|
| 4 | |
---|
| 5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
| 6 | |
---|
| 7 | =head1 NAME |
---|
| 8 | |
---|
| 9 | Sophie::Controller::0Explorer - Catalyst Controller |
---|
| 10 | |
---|
| 11 | =head1 DESCRIPTION |
---|
| 12 | |
---|
| 13 | Catalyst Controller. |
---|
| 14 | |
---|
| 15 | =head1 METHODS |
---|
| 16 | |
---|
| 17 | =cut |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | =head2 index |
---|
| 21 | |
---|
| 22 | =cut |
---|
| 23 | |
---|
| 24 | sub dir :Local { |
---|
| 25 | my ( $self, $c, @args ) = @_; |
---|
| 26 | my $dir = join('/', map { "$_" } grep { $_ } @args); |
---|
| 27 | $c->stash->{path} = $dir; |
---|
| 28 | $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : ''); |
---|
[43] | 29 | |
---|
[105] | 30 | my $rsdist = $c->forward('/search/distrib_search', [ |
---|
| 31 | $c->session->{__explorer}, 1 ]); |
---|
[107] | 32 | my %uniq; |
---|
| 33 | foreach ( |
---|
| 34 | $c->model('Base') |
---|
| 35 | ->resultset('Files') |
---|
| 36 | ->search( |
---|
| 37 | { |
---|
| 38 | dirname => '/' . ($dir ? "$dir/" : ''), |
---|
| 39 | ($rsdist |
---|
| 40 | ? (pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },) |
---|
| 41 | : ()), |
---|
| 42 | ($c->req->param('filename') |
---|
| 43 | ? ( basename => { LIKE => $c->req->param('filename') . '%' } ) |
---|
| 44 | : ()), |
---|
| 45 | }, |
---|
| 46 | { |
---|
| 47 | #order_by => [ 'basename' ], |
---|
| 48 | #group_by => [ 'basename' ], |
---|
| 49 | select => [ 'basename' ], |
---|
| 50 | } |
---|
| 51 | )->get_column('basename')->all) { |
---|
| 52 | $uniq{$_} = 1; |
---|
| 53 | } |
---|
| 54 | $c->stash->{xmlrpc} = [ sort keys %uniq ]; |
---|
[38] | 55 | } |
---|
| 56 | |
---|
| 57 | sub file :Local { |
---|
| 58 | my ( $self, $c, @args ) = @_; |
---|
| 59 | my $basename = pop(@args); |
---|
| 60 | my $dir = join('/', map { "$_" } grep { $_ } @args); |
---|
| 61 | $c->stash->{path} = $dir; |
---|
| 62 | $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : ''); |
---|
[43] | 63 | |
---|
[105] | 64 | my $rsdist = $c->forward('/search/distrib_search', [ |
---|
| 65 | $c->session->{__explorer}, 1 ]); |
---|
[43] | 66 | |
---|
[76] | 67 | my @col = qw(dirname basename md5 size pkgid count); |
---|
[38] | 68 | $c->stash->{xmlrpc} = [ |
---|
[76] | 69 | map { { |
---|
[95] | 70 | $_->get_columns |
---|
[76] | 71 | } } |
---|
[38] | 72 | $c->model('Base') |
---|
| 73 | ->resultset('Files') |
---|
| 74 | ->search({ |
---|
[43] | 75 | dirname => '/' . ($dir ? "$dir/" : ''), basename => $basename, |
---|
[105] | 76 | ($rsdist |
---|
| 77 | ? (pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },) |
---|
| 78 | : ()) |
---|
[38] | 79 | }, |
---|
| 80 | { |
---|
[76] | 81 | 'select' => [ 'contents is NOT NULL as has_content', 'rpmfilesmode(mode) as perm', @col, '"group"', |
---|
| 82 | '"user"' ], |
---|
| 83 | as => [ qw(has_content perm), @col, 'group', 'user' ], |
---|
| 84 | order_by => [ 'pkgid' ], |
---|
| 85 | |
---|
| 86 | }, |
---|
[38] | 87 | )->all ]; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | =head1 AUTHOR |
---|
| 91 | |
---|
| 92 | Olivier Thauvin |
---|
| 93 | |
---|
| 94 | =head1 LICENSE |
---|
| 95 | |
---|
| 96 | This library is free software. You can redistribute it and/or modify |
---|
| 97 | it under the same terms as Perl itself. |
---|
| 98 | |
---|
| 99 | =cut |
---|
| 100 | |
---|
| 101 | __PACKAGE__->meta->make_immutable; |
---|
| 102 | |
---|
| 103 | 1; |
---|