Skip to content

Commit

Permalink
Better support for video streaming by redirecting on fresh cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jun 13, 2013
1 parent 7f20c00 commit bdbd7a6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 15 deletions.
6 changes: 6 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
== 1.2.5

* Major changes
* To support video streaming: redirect on first document cache. WARNING: This
implies changes to vhost files !

* Minor changes
* Fixed encode_params in Ajax requests.
* Fixed cached path in vhost file.
* Added "uuid" method (generates a unique id). <== TODO: Document

== 1.2.4 2013-06-13

Expand Down
17 changes: 11 additions & 6 deletions app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,19 @@ def show
else
content_path = @node.filepath
end


# content_path is used to cache by creating a symlink
cache_ok = cache_page(:content_path => content_path, :authenticated => @node.v_public?)

if content_path
# FIXME RAILS: remove 'stream => false' when rails streaming is fixed
send_file(content_path, :filename => @node.filename, :type => @node.content_type, :disposition => 'inline', :stream => false, :x_sendfile => ENABLE_XSENDFILE)
if @node.v_public? && cache_ok
# This is the simplest working solution to save cached version and use apache for serving (all xsendfile and such do not work with video streaming).
redirect_to data_path(@node, :mode => params[:mode]) + "?1"
else
# FIXME RAILS: remove 'stream => false' when rails streaming is fixed
send_file(content_path, :filename => @node.filename, :type => @node.content_type, :disposition => 'inline', :stream => false, :x_sendfile => ENABLE_XSENDFILE)
end
end

# content_path is used to cache by creating a symlink
cache_page(:content_path => content_path, :authenticated => @node.v_public?)
else
render_and_cache
# FIXME: redirect to document format should occur in render_and_cache
Expand Down
2 changes: 2 additions & 0 deletions lib/zena.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ def init
[ "movie" , "video/x-sgi-movie" ],
[ "mp2" , "audio/mpeg" ],
[ "mp3" , "audio/mpeg" ],
[ "mp4" , "video/mp4" ],
[ "m4v" , "video/mp4" ],
[ "mpe" , "video/mpeg" ],
[ "mpeg" , "video/mpeg" ],
[ "mpg" , "video/mpeg" ],
Expand Down
9 changes: 5 additions & 4 deletions lib/zena/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,13 @@ def ancestry(path)
puts "HOST not set (use -s host=...)"
else
vhost_files = []
if self[:ssl] == :all

public_path = Bricks.raw_config['public_path'] || '/public'
cache_path = Bricks.raw_config['cache_path'] || '/public'
public_path = Bricks.raw_config['public_path'] || '/public'
cache_path = Bricks.raw_config['cache_path'] || '/public'

self[:cache_path] = cache_path.sub(%r{^#{public_path}},'')

self[:cache_path] = cache_path.sub(%r{^#{public_path}},'')
if self[:ssl] == :all
vhost = render("#{templates}/vhost.rhtml", :config => self, :ssl => true, :vhost_port => ':443')
put(vhost, "#{vhost_root}/#{self[:host]}.ssl")
vhost_files << "#{self[:host]}.ssl"
Expand Down
6 changes: 3 additions & 3 deletions lib/zena/deploy/vhost.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ end %>
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]

# Serve static (cached) assets
# Serve static (recently cached) assets
RewriteCond %{QUERY_STRING} ^[0-9]+$
RewriteCond %{DOCUMENT_ROOT}<%= config[:cache_path] %>%{REQUEST_FILENAME}.%{QUERY_STRING} -f
RewriteRule ^/(.*)$ <%= config[:cache_path] %>%{REQUEST_FILENAME}.%{QUERY_STRING} [L]
RewriteCond %{DOCUMENT_ROOT}<%= config[:cache_path] %>%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ <%= config[:cache_path] %>%{REQUEST_FILENAME} [L]

# Static CSS, JS
RewriteCond %{QUERY_STRING} ^[0-9]+$
Expand Down
6 changes: 6 additions & 0 deletions lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ module ViewMethods
safe_method [:sprintf, String, Number] => {:class => String, :method => 'sprintf'}
safe_method [:search_box, {:ajax => String, :type => String}] => {:class => String, :method => 'search_box', :html_safe => true}
safe_context [:admin_links, {:list => String}] => [String]
safe_method :uuid => String

# Return sprintf formated entry. Return '' for values eq to zero.
def sprintf_unless_zero(fmt, value)
Expand All @@ -246,6 +247,11 @@ def sprintf_unless_zero(fmt, value)
def search_box(opts={})
render_to_string(:partial=>'search/form', :locals => {:ajax => opts[:ajax], :type => opts[:type]})
end

# Return a random string that can be used as id (starts with a character)
def uuid
'u' + UUIDTools::UUID.random_create.to_s.gsub('-','')[0..8]
end

# Return the 'zip' of the node corresponding to the browser url (start node). This value is kept
# accross all Ajax calls.
Expand Down
8 changes: 7 additions & 1 deletion lib/zena/use/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ def cache_page(opts={})
:content_data => response.body,
:node_id => @node[:id]
}.merge(opts)
secure!(CachedPage) { CachedPage.create(opts) }
if secure!(CachedPage) { CachedPage.create(opts) }
true
else
false
end
else
false
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ module ViewAndControllerMethods
def host_with_port
@host_with_port ||= begin
port = request.port
if port.blank? || port.to_s == '80'
if port.blank? || port.to_s == '80' || port.to_s == '443'
current_site.host
else
"#{current_site.host}:#{port}"
Expand Down
4 changes: 4 additions & 0 deletions test/integration/zafu_compiler/display.yml
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,7 @@ with_a_custom_img_tag_field_with_JS:
invalid_document:
src: "<r:zazen text='!21!'/>"
res: "/images/ext/project.png/"

uuid:
src: "<div id='foo#{uuid}'>hop</div>"
res: "/<div id='foou[a-z0-9]+'>hop</div>/"

0 comments on commit bdbd7a6

Please sign in to comment.