Skip to content

Commit

Permalink
Merge pull request #167 from blackcandy-org/fix-cannot-generate-trans…
Browse files Browse the repository at this point in the history
…code-cache

Fix #158, cannot generate transcode cache on docker build
  • Loading branch information
aidewoode committed Apr 12, 2022
2 parents 50f8a40 + 44dd78c commit 5c5d6d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 1 addition & 3 deletions app/controllers/cached_transcoded_stream_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def new

private

def set_header
return unless nginx_senfile?

def set_nginx_header
response.headers["X-Accel-Redirect"] = File.join("/private_cache_media", @stream.transcode_cache_file_path.sub(Stream::TRANSCODE_CACHE_DIRECTORY.to_s, ""))
end
end
11 changes: 5 additions & 6 deletions app/controllers/stream_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class StreamController < ApplicationController
before_action :find_stream
before_action :set_header

def new
if need_transcode? @stream.format
Expand All @@ -14,11 +13,9 @@ def new

private

# Let nginx can get value of media_path dynamically in the nginx config,
# when use X-Accel-Redirect header to send file.
def set_header
return unless nginx_senfile?

def set_nginx_header
# Let nginx can get value of media_path dynamically in the nginx config,
# when use X-Accel-Redirect header to send file.
response.headers["X-Media-Path"] = Setting.media_path
response.headers["X-Accel-Redirect"] = File.join("/private_media", @stream.file_path.sub(File.expand_path(Setting.media_path), ""))
end
Expand All @@ -34,6 +31,8 @@ def nginx_senfile?

def send_local_file(file_path)
if nginx_senfile?
set_nginx_header

send_file file_path
return
end
Expand Down
2 changes: 1 addition & 1 deletion config/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ http {

location /private_cache_media/ {
internal;
alias /tmp/cache/media_file/;
alias /app/tmp/cache/media_file/;
}

location / {
Expand Down

0 comments on commit 5c5d6d3

Please sign in to comment.