FIX: locally uploaded audio & video files should onebox even when the extension is uppercase

This commit is contained in:
Régis Hanol 2016-12-15 23:21:44 +01:00
parent 21682fd60b
commit 197517d55e
3 changed files with 11 additions and 8 deletions

View File

@ -384,11 +384,11 @@ Discourse::Application.routes.draw do
post "uploads" => "uploads#create"
# used to download original images
get "uploads/:site/:sha" => "uploads#show", constraints: { site: /\w+/, sha: /[a-f0-9]{40}/ }
get "uploads/:site/:sha.:extension" => "uploads#show", constraints: { site: /\w+/, sha: /\h{40}/, extension: /[a-z0-9\.]+/i }
# used to download attachments
get "uploads/:site/original/:tree:sha" => "uploads#show", constraints: { site: /\w+/, tree: /(\w+\/)+/i, sha: /[a-f0-9]{40}/ }
get "uploads/:site/original/:tree:sha.:extension" => "uploads#show", constraints: { site: /\w+/, tree: /([a-z0-9]+\/)+/i, sha: /\h{40}/, extension: /[a-z0-9\.]+/i }
# used to download attachments (old route)
get "uploads/:site/:id/:sha" => "uploads#show", constraints: { site: /\w+/, id: /\d+/, sha: /[a-f0-9]{16}/ }
get "uploads/:site/:id/:sha" => "uploads#show", constraints: { site: /\w+/, id: /\d+/, sha: /\h{16}/ }
get "posts" => "posts#latest", id: "latest_posts"
get "private-posts" => "posts#latest", id: "private_posts"

View File

@ -34,9 +34,9 @@ module Onebox
def upload_html(path)
case File.extname(path)
when /^\.(mov|mp4|webm|ogv)$/
when /^\.(mov|mp4|webm|ogv)$/i
"<video width='100%' height='100%' controls><source src='#{@url}'><a href='#{@url}'>#{@url}</a></video>"
when /^\.(mp3|ogg|wav)$/
when /^\.(mp3|ogg|wav|m4a)$/i
"<audio controls><source src='#{@url}'><a href='#{@url}'>#{@url}</a></audio>"
end
end

View File

@ -66,20 +66,23 @@ describe Onebox::Engine::DiscourseLocalOnebox do
context "for a link to an internal audio or video file" do
let(:sha) { Digest::SHA1.hexdigest("discourse") }
let(:path) { "/uploads/default/original/3X/5/c/#{sha}" }
it "returns nil if file type is not audio or video" do
url = "#{Discourse.base_url}/uploads/default/original/3X/5/c/24asdf42.pdf"
url = "#{Discourse.base_url}#{path}.pdf"
FakeWeb.register_uri(:get, url, body: "")
expect(Onebox.preview(url).to_s).to eq("")
end
it "returns some onebox goodness for audio file" do
url = "#{Discourse.base_url}/uploads/default/original/3X/5/c/24asdf42.mp3"
url = "#{Discourse.base_url}#{path}.MP3"
html = Onebox.preview(url).to_s
expect(html).to eq("<audio controls><source src='#{url}'><a href='#{url}'>#{url}</a></audio>")
end
it "returns some onebox goodness for video file" do
url = "#{Discourse.base_url}/uploads/default/original/3X/5/c/24asdf42.mp4"
url = "#{Discourse.base_url}#{path}.mov"
html = Onebox.preview(url).to_s
expect(html).to eq("<video width='100%' height='100%' controls><source src='#{url}'><a href='#{url}'>#{url}</a></video>")
end