diff options
author | Yorhel <git@yorhel.nl> | 2013-01-03 11:40:01 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2013-01-03 11:40:01 +0100 |
commit | bf9685dd78ff6b8373fca762f738b55f6e9dd560 (patch) | |
tree | b9e7f9efbf0a6e1b7821fa7a9dce87699c173f07 /lib/Multi/API.pm | |
parent | 633ae14c50509237f0b3d3999c890b9abc6747b4 (diff) |
Multi::API: Added 'get vnlist' and 'get wishlist'
Diffstat (limited to 'lib/Multi/API.pm')
-rw-r--r-- | lib/Multi/API.pm | 88 |
1 files changed, 86 insertions, 2 deletions
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm index 84ac6062..dfc1e94f 100644 --- a/lib/Multi/API.pm +++ b/lib/Multi/API.pm @@ -41,7 +41,8 @@ sub spawn { $p => [qw| _start shutdown log server_error client_connect client_error client_input login login_res get_results get_vn get_vn_res get_release get_release_res - get_producer get_producer_res get_votelist get_votelist_res admin + get_producer get_producer_res get_votelist get_votelist_res get_vnlist + get_vnlist_res get_wishlist get_wishlist_res admin |], ], heap => { @@ -365,7 +366,7 @@ sub client_input { filters => $arg->[2], opt => $opt, ); - return cerr $c, 'gettype', "Unknown get type: '$arg->[0]'" if $arg->[0] !~ /^(?:vn|release|producer|votelist)$/; + return cerr $c, 'gettype', "Unknown get type: '$arg->[0]'" if $arg->[0] !~ /^(?:vn|release|producer|votelist|vnlist|wishlist)$/; return cerr $c, needlogin => 'Not logged in as a user' if $arg->[0] =~ /^list$/ && !$c->{uid}; return $_[KERNEL]->yield("get_$arg->[0]", \%obj); } @@ -877,6 +878,89 @@ sub get_votelist_res { } +sub get_vnlist { + my $get = $_[ARG0]; + + return cerr $get->{c}, getinfo => "Unknown info flag '$_'", flag => $_ + for (grep !/^(basic)$/, @{$get->{info}}); + + my $select = "vid AS vn, status, extract('epoch' from added) AS added, notes"; + + my @placeholders; + my $where = encode_filters $get->{filters}, \&filtertosql, $get->{c}, \@placeholders, [ + [ 'uid', + [ 'int' => 'uid :op: :value:', {qw|= =|}, process => sub { $_[0] eq '0' ? $get->{c}{uid} : \'uid filter must be 0' } ], + ] + ]; + my $last = sqllast $get, 'vn', { vn => 'vid %s' }; + return if !$where || !$last; + + $_[KERNEL]->post(pg => query => + qq|SELECT $select FROM vnlists WHERE $where $last|, + \@placeholders, 'get_vnlist_res', $get); +} + + +sub get_vnlist_res { + my($num, $res, $get, $time) = (@_[ARG0..$#_]); + + $get->{time} += $time; + $get->{queries}++; + + for (@$res) { + $_->{vn}*=1; + $_->{status}*=1; + $_->{added} = int $_->{added}; + $_->{notes} ||= undef; + } + $get->{more} = pop(@$res)&&1 if @$res > $get->{opt}{results}; + $get->{list} = $res; + + $_[KERNEL]->yield(get_results => { %$get, type => 'vnlist' }); +} + + +sub get_wishlist { + my $get = $_[ARG0]; + + return cerr $get->{c}, getinfo => "Unknown info flag '$_'", flag => $_ + for (grep !/^(basic)$/, @{$get->{info}}); + + my $select = "vid AS vn, wstat AS priority, extract('epoch' from added) AS added"; + + my @placeholders; + my $where = encode_filters $get->{filters}, \&filtertosql, $get->{c}, \@placeholders, [ + [ 'uid', + [ 'int' => 'uid :op: :value:', {qw|= =|}, process => sub { $_[0] eq '0' ? $get->{c}{uid} : \'uid filter must be 0' } ], + ] + ]; + my $last = sqllast $get, 'vn', { vn => 'vid %s' }; + return if !$where || !$last; + + $_[KERNEL]->post(pg => query => + qq|SELECT $select FROM wlists WHERE $where $last|, + \@placeholders, 'get_wishlist_res', $get); +} + + +sub get_wishlist_res { + my($num, $res, $get, $time) = (@_[ARG0..$#_]); + + $get->{time} += $time; + $get->{queries}++; + + for (@$res) { + $_->{vn}*=1; + $_->{priority}*=1; + $_->{added} = int $_->{added}; + } + $get->{more} = pop(@$res)&&1 if @$res > $get->{opt}{results}; + $get->{list} = $res; + + $_[KERNEL]->yield(get_results => { %$get, type => 'wishlist' }); +} + + # can be call()'ed from other sessions (specifically written for IRC) sub admin { my($func, @arg) = @_[ARG0..$#_]; |