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