mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 04:58:53 +08:00
Dropbox has introduced a new sharing URL format using `/scl/fi/` instead of the legacy `/s/` path. This updates VideoOnebox and ImageOnebox to: - Detect and transform new `/scl/` format URLs - Convert to dl.dropboxusercontent.com domain - Ensure raw=1 parameter is present for direct download - Maintain backward compatibility with legacy `/s/` format - Also...added test coverage for both old and new Dropbox formats. All existing tests continue to pass. Co-Authored-By: Claude Sonnet 4.5 --------- Co-authored-by: Loïc Guitaut <loic@discourse.org>
87 lines
2.4 KiB
Ruby
Vendored
87 lines
2.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe Onebox::Engine::ImageOnebox do
|
|
it "supports png" do
|
|
expect(Onebox.preview("http://www.discourse.org/images/logo.png").to_s).to match(/<img/)
|
|
end
|
|
|
|
it "supports jpg" do
|
|
expect(
|
|
Onebox.preview("http://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg").to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports jpeg" do
|
|
expect(
|
|
Onebox.preview("http://upload.wikimedia.org/wikipedia/en/b/bb/Poster.jpeg").to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports gif" do
|
|
expect(
|
|
Onebox.preview("http://upload.wikimedia.org/wikipedia/commons/5/55/Tesseract.gif").to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports tif" do
|
|
expect(
|
|
Onebox.preview(
|
|
"http://www.fileformat.info/format/tiff/sample/1f37bbd5603048178487ec88b1a6425b/MARBLES.tif",
|
|
).to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports bmp" do
|
|
expect(
|
|
Onebox.preview(
|
|
"http://www.fileformat.info/format/bmp/sample/d4202a5fc22a48c388d9e1c636792cc6/LAND.BMP",
|
|
).to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports webp" do
|
|
expect(Onebox.preview("https://www.gstatic.com/webp/gallery/1.sm.webp").to_s).to match(/<img/)
|
|
end
|
|
|
|
it "supports avif" do
|
|
expect(
|
|
Onebox.preview(
|
|
"https://raw.githubusercontent.com/AOMediaCodec/av1-avif/master/testFiles/Xiph/abandoned_filmgrain.avif",
|
|
).to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports image URLs with query parameters" do
|
|
expect(
|
|
Onebox.preview(
|
|
"https://www.google.com/logos/doodles/2014/percy-julians-115th-birthday-born-1899-5688801926053888-hp.jpg?foo=bar",
|
|
).to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "supports protocol relative image URLs" do
|
|
expect(
|
|
Onebox.preview(
|
|
"//www.google.com/logos/doodles/2014/percy-julians-115th-birthday-born-1899-5688801926053888-hp.jpg",
|
|
).to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
it "includes a direct link to the image" do
|
|
expect(Onebox.preview("http://www.discourse.org/images/logo.png").to_s).to match(/<a.*png/)
|
|
end
|
|
|
|
it "matches on content_type" do
|
|
expect(
|
|
Onebox.preview("http://www.discourse.org/images/logo", { content_type: "image/png" }).to_s,
|
|
).to match(/<img/)
|
|
end
|
|
|
|
context "with Dropbox URL" do
|
|
let(:html) { Onebox.preview("https://www.dropbox.com/scl/fi/abc123/image.png?rlkey=xyz").to_s }
|
|
|
|
it "transforms to direct download link" do
|
|
expect(html).to include("dl.dropboxusercontent.com")
|
|
end
|
|
end
|
|
end
|