From 805ac9f2fba34f1a0a6bcd1809945d99173cadf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz> Date: Sun, 1 Nov 2020 18:22:51 +0100 Subject: [PATCH] Optimalizace. Pridana metoda 'info' --- lib/PiTube/Controller/Stream.pm | 64 ++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/lib/PiTube/Controller/Stream.pm b/lib/PiTube/Controller/Stream.pm index 5417171..aabb5b0 100644 --- a/lib/PiTube/Controller/Stream.pm +++ b/lib/PiTube/Controller/Stream.pm @@ -24,22 +24,22 @@ sub list { STREAM: while ( my $stream = $streams->next()) { - my $rights = $c->session->{user}{acl}{ $stream->key }; - next STREAM if ! $rights; - push @streams, { + my $rights = $c->session->{user}{acl}{ $stream->key } || next STREAM; + + my %stream = ( + $stream->get_columns(), is_live => $stream->is_live, - key => $stream->key, - name => $stream->name, - publisher => $stream->is_live ? $stream->publish_user_name : '', - is_writeable => $c->is('publisher') - && $stream->is_writeable( $rights ), - is_recordable => $c->is('publisher') - && $stream->is_recordable( $c->session->{user}{username} ), - }; + is_writeable => $stream->is_writeable( $rights ), + is_recordable => $stream->is_recordable( $c->session->{user}{username} ), + ); + + delete $stream{publish_user_name} if ! $stream->is_live; + + push @streams, \%stream; } - $c->stash->{streams} = \@streams; + $c->render( json => \@streams ); } @@ -61,16 +61,54 @@ sub player { return; } - $c->stash->{stream} = $stream; + $c->stash->{stream} = { + $stream->get_columns, + is_live => $stream->is_live, + }; if ( ! ( $c->session->{user}{acl}{ $stream->key } & 4 ) ) { # TODO:constant $c->render('stream/403'); return; } + $c->render(); } +sub info { + my $c = shift; + + # vzdy aktualizovat + $c->session->{user}{acl} = $c->schema->resultset('ACL')->user_acl( + $c->session->{user} + ); + + # stream + my $stream = $c->schema->resultset('Stream_view')->find({ + id => $c->stash->{id} + }); + + if ( ! $stream ) { + $c->render('stream/404'); + return; + } + + my $rights = $c->session->{user}{acl}{ $stream->key }; + + if ( ! $rights ) { + $c->render('stream/403'); + return; + } + + $c->stash->{stream} = { + $stream->get_columns(), + is_live => $stream->is_live, + is_writeable => $stream->is_writeable( $rights ), + is_recordable => $stream->is_recordable( $c->session->{user}{username} ), + }; + + $c->render(); +} 1; -- GitLab