Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ItemsController < ApplicationController
before_action :set_item, only: [:show, :edit, :update, :destroy]
before_action :require_login, except: [:index]
before_action :require_login, except: [:index, :authorize]

def require_login
redirect_to new_user_session_path unless current_user.present?
Expand All @@ -15,6 +15,10 @@ def index
# GET /items/1
# GET /items/1.json
def show
session[:token] ||= SecureRandom.hex(16)
Rails.cache.write(session[:token],
@item.streams.collect { |s| s["url"] },
expires_in: 1.hours)
end

# GET /items/new
Expand Down Expand Up @@ -66,6 +70,17 @@ def destroy
end
end

# GET /items/authorize
def authorize
authorized_streams = Rails.cache.read(params[:token])

if params[:name] and not authorized_streams.any? { |valid| valid.index(params[:name]).present? }
return head :forbidden
else
return head :ok
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_item
Expand Down
2 changes: 1 addition & 1 deletion app/views/items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
preload="auto"
>
<% @item.streams.each do |stream| %>
<source src="<%= stream["url"] %>" type="application/x-mpegURL" label="<%= stream["label"] %>"/>
<source src="<%= stream["url"] %>?token=<%= session[:token] %>" type="application/x-mpegURL" label="<%= stream["label"] %>"/>
<% end %>
</video>
</p>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
else
config.action_controller.perform_caching = false

config.cache_store = :null_store
config.cache_store = :memory_store
end

# Store uploaded files on the local file system (see config/storage.yml for options)
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Rails.application.routes.draw do
resources :items
resources :items do
collection do
get :authorize
end
end
devise_for :users
root to: "items#index"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
- "3000:3000"
depends_on:
- db
stdin_open: true
tty: true
streaming:
build: ./nginx
volumes:
Expand Down
2 changes: 1 addition & 1 deletion nginx/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ http {
sub_filter_once off;
sub_filter '.ts' ".ts?token=$token";

# auth_request /auth;
auth_request /auth;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
Expand Down