From 7b25b364c19aef18da29b6db376b67f2f53af867 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz>
Date: Wed, 23 Dec 2020 19:02:46 +0100
Subject: [PATCH] Podpora volneho pristupu l verejnym streamum

---
 lib/PiTube/Controller/Nginx.pm | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/PiTube/Controller/Nginx.pm b/lib/PiTube/Controller/Nginx.pm
index 789af4a..82a6c1b 100644
--- a/lib/PiTube/Controller/Nginx.pm
+++ b/lib/PiTube/Controller/Nginx.pm
@@ -86,15 +86,20 @@ sub callback_recorder {
 sub callback_hls {
     my $c = shift;
 
+    my $code = 403;
+
     if ($c->req->headers->header('X-Original-URI') =~ HLS ) {
-        if ( $c->session->{user}{acl}{ $1 } & 4 ) { #TODO: constant
-            $c->render( status => 204, text => '' );
-            return;
+        $code = 204 if $c->session->{user}{acl}{ $1 } & 4;
+
+        if (! $code) {
+            my $is_public = $c->schema->resultset('Stream')->count({
+                key => $1, is_public => 't'
+            });
+            $code = 204 if $is_public;
         }
     }
 
-    $c->render( status => 403, text => '');
-
+    $c->render( status => $code, text => '');
 }
 
 sub callback_record {
-- 
GitLab