Skip to content
Snippets Groups Projects
Verified Commit aa5e4cda authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

pridan endpoint pro rizeni nahravani

parent a536b7a9
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,8 @@ sub startup { ...@@ -73,6 +73,8 @@ sub startup {
$r->get('/api/streams')->to('Stream#list'); $r->get('/api/streams')->to('Stream#list');
$r->get('/streams/:id')->to('Stream#info'); $r->get('/streams/:id')->to('Stream#info');
$r->put('/streams/:id/recording')->to('Stream#recording');
# $r->get('/streams/add')->over( is => 'administrator' )->to('Stream#add'); # $r->get('/streams/add')->over( is => 'administrator' )->to('Stream#add');
# $r->get('/streams/:id/form')->over( is => 'administrator' )->to('Stream#form'); # $r->get('/streams/:id/form')->over( is => 'administrator' )->to('Stream#form');
# $r->post('/streams')->over( is => 'administrator' )->to('Stream#create'); # $r->post('/streams')->over( is => 'administrator' )->to('Stream#create');
......
package PiTube::Controller::Stream; package PiTube::Controller::Stream;
use Mojo::Base 'Mojolicious::Controller'; use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use constant CONTENT_TYPE => { use constant CONTENT_TYPE => {
m3u8 => 'application/vnd.apple.mpegurl', m3u8 => 'application/vnd.apple.mpegurl',
ts => 'video/mp2t', ts => 'video/mp2t',
}; };
use constant CONTROL_URL => '%s/control/record/%s?app=stream&name=%s&rec=%s';
sub list { sub list {
my $c = shift; my $c = shift;
...@@ -39,7 +42,7 @@ sub list { ...@@ -39,7 +42,7 @@ sub list {
$stream->get_columns(), $stream->get_columns(),
is_live => $stream->is_live, is_live => $stream->is_live,
is_writeable => $stream->is_writeable( $rights ), is_writeable => $stream->is_writeable( $rights ),
is_recordable => $stream->is_recordable( $c->session->{user}{username} ), is_recordable => $stream->is_recordable( $c->session->{user}{id} ),
); );
delete $stream{publish_user_name} if ! $stream->is_live; delete $stream{publish_user_name} if ! $stream->is_live;
...@@ -112,12 +115,58 @@ sub info { ...@@ -112,12 +115,58 @@ sub info {
$stream->get_columns(), $stream->get_columns(),
is_live => $stream->is_live, is_live => $stream->is_live,
is_writeable => $stream->is_writeable( $rights ), is_writeable => $stream->is_writeable( $rights ),
is_recordable => $stream->is_recordable( $c->session->{user}{username} ), is_recordable => $stream->is_recordable( $c->session->{user}{id} ),
}; };
$c->render(); $c->render();
} }
sub recording {
my $c = shift;
# akce
if ( ! $c->param('action') || $c->param('action') !~ /(stop|start)/) {
$c->render( status => 400, text => '');
return;
}
# stream
my $stream = $c->schema->resultset('Stream')->find({
id => $c->stash->{id}
});
if ( ! $stream ) {
$c->render( status => 404, text => '');
return;
}
if ( $stream->publish_user_id != $c->session->{user}{id}) {
$c->render( status => 403, text => '');
return;
}
my $ua = Mojo::UserAgent->new;
my $res = $ua->get(sprintf(CONTROL_URL,
$c->config->{nginx}{base_url},
$c->param('action'),
$stream->key,
'all'
))->result;
my $recording = ( $c->param('action') eq 'start' ) ? 1 : 0;
if ($res->is_success) {
# TRANSAKCE
$stream->update({
recording => $recording
});
# create/update records
}
$c->render( json => { recording => $stream->recording } );
}
1; 1;
__END__ __END__
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment