mirror of
https://github.com/discourse/discourse.git
synced 2025-06-13 13:50:00 +08:00
FIX: locally uploaded audio & video files should onebox even when the extension is uppercase
This commit is contained in:
@ -384,11 +384,11 @@ Discourse::Application.routes.draw do
|
|||||||
post "uploads" => "uploads#create"
|
post "uploads" => "uploads#create"
|
||||||
|
|
||||||
# used to download original images
|
# 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
|
# 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)
|
# 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 "posts" => "posts#latest", id: "latest_posts"
|
||||||
get "private-posts" => "posts#latest", id: "private_posts"
|
get "private-posts" => "posts#latest", id: "private_posts"
|
||||||
|
@ -34,9 +34,9 @@ module Onebox
|
|||||||
|
|
||||||
def upload_html(path)
|
def upload_html(path)
|
||||||
case File.extname(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>"
|
"<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>"
|
"<audio controls><source src='#{@url}'><a href='#{@url}'>#{@url}</a></audio>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -66,20 +66,23 @@ describe Onebox::Engine::DiscourseLocalOnebox do
|
|||||||
|
|
||||||
context "for a link to an internal audio or video file" 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
|
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: "")
|
FakeWeb.register_uri(:get, url, body: "")
|
||||||
expect(Onebox.preview(url).to_s).to eq("")
|
expect(Onebox.preview(url).to_s).to eq("")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns some onebox goodness for audio file" do
|
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
|
html = Onebox.preview(url).to_s
|
||||||
expect(html).to eq("<audio controls><source src='#{url}'><a href='#{url}'>#{url}</a></audio>")
|
expect(html).to eq("<audio controls><source src='#{url}'><a href='#{url}'>#{url}</a></audio>")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns some onebox goodness for video file" do
|
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
|
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>")
|
expect(html).to eq("<video width='100%' height='100%' controls><source src='#{url}'><a href='#{url}'>#{url}</a></video>")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user