From fc2219d0084a7d46190ce6f479330742370c72e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz>
Date: Thu, 15 Oct 2020 22:43:59 +0200
Subject: [PATCH] Prejmenovani, callback pro cteni

---
 .../Controller/{NginxRTMP.pm => Nginx.pm}     | 22 +++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
 rename lib/PiTube/Controller/{NginxRTMP.pm => Nginx.pm} (61%)

diff --git a/lib/PiTube/Controller/NginxRTMP.pm b/lib/PiTube/Controller/Nginx.pm
similarity index 61%
rename from lib/PiTube/Controller/NginxRTMP.pm
rename to lib/PiTube/Controller/Nginx.pm
index fca7915..ae5416b 100644
--- a/lib/PiTube/Controller/NginxRTMP.pm
+++ b/lib/PiTube/Controller/Nginx.pm
@@ -1,7 +1,9 @@
-package PiTube::Controller::NginxRTMP;
+package PiTube::Controller::Nginx;
 use Mojo::Base 'Mojolicious::Controller';
 
-sub callback {
+use constant HLS => qr/^\/hls\/([a-z0-9\-]+)(_\w+)?(\/\w+)?\.(m3u8|ts)$/i;
+
+sub callback_rtmp {
     my $c = shift;
 
     if ( $c->param('call') =~ /publish/ ) {
@@ -29,4 +31,20 @@ sub callback {
     $c->render( status => 204, text => '' );
 }
 
+sub callback_hls {
+    my $c = shift;
+
+    $c->app->log->debug($c->req->headers->header('X-Original-URI'));
+
+    if ($c->req->headers->header('X-Original-URI') =~ HLS ) {
+        if ( $c->session->{user}{acl}{ $1 } ) {
+            $c->render( status => 204, text => '' );
+            return;
+        }
+    }
+
+    $c->render( status => 403, text => '');
+
+}
+
 1;
-- 
GitLab