mirror of
https://github.com/discourse/discourse.git
synced 2025-06-19 22:23:04 +08:00
FIX: Stop infinite lookup-urls issue for video/audio on page (#9096)
Meta report: https://meta.discourse.org/t/excessive-requests-to-uploads-lookup-urls-leading-to-429-response/143119 * The data-orig-src attribute was not being removed from cooked video and audio so the composer was infinitely trying to get the URLs for them, which would never resolve to anything * Also the code that retrieved the short URL was unscoped, and was getting everything on the page. if running from the composer we now scope to the preview window * Also fixed a minor issue where the element href for the video and audio tags was not being set when the short URL was found
This commit is contained in:
@ -1012,6 +1012,32 @@ QUnit.test("video", assert => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("video - mapped url - secure media enabled", assert => {
|
||||
function lookupUploadUrls() {
|
||||
let cache = {};
|
||||
cache["upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4"] = {
|
||||
short_url: "upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4",
|
||||
url: "/secure-media-uploads/original/3X/c/b/test.mp4",
|
||||
short_path: "/uploads/short-url/blah"
|
||||
};
|
||||
return cache;
|
||||
}
|
||||
assert.cookedOptions(
|
||||
"",
|
||||
{
|
||||
siteSettings: { secure_media: true },
|
||||
lookupUploadUrls: lookupUploadUrls
|
||||
},
|
||||
`<p><div class="video-container">
|
||||
<video width="100%" height="100%" preload="none" controls>
|
||||
<source src="/secure-media-uploads/original/3X/c/b/test.mp4">
|
||||
<a href="/secure-media-uploads/original/3X/c/b/test.mp4">/secure-media-uploads/original/3X/c/b/test.mp4</a>
|
||||
</video>
|
||||
</div></p>`,
|
||||
"It returns the correct video HTML when the URL is mapped with secure media, removing data-orig-src"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("audio", assert => {
|
||||
assert.cooked(
|
||||
"",
|
||||
@ -1023,6 +1049,30 @@ QUnit.test("audio", assert => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("audio - mapped url - secure media enabled", assert => {
|
||||
function lookupUploadUrls() {
|
||||
let cache = {};
|
||||
cache["upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3"] = {
|
||||
short_url: "upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp3",
|
||||
url: "/secure-media-uploads/original/3X/c/b/test.mp3",
|
||||
short_path: "/uploads/short-url/blah"
|
||||
};
|
||||
return cache;
|
||||
}
|
||||
assert.cookedOptions(
|
||||
"",
|
||||
{
|
||||
siteSettings: { secure_media: true },
|
||||
lookupUploadUrls: lookupUploadUrls
|
||||
},
|
||||
`<p><audio preload="none" controls>
|
||||
<source src="/secure-media-uploads/original/3X/c/b/test.mp3">
|
||||
<a href="/secure-media-uploads/original/3X/c/b/test.mp3">/secure-media-uploads/original/3X/c/b/test.mp3</a>
|
||||
</audio></p>`,
|
||||
"It returns the correct audio HTML when the URL is mapped with secure media, removing data-orig-src"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("censoring", assert => {
|
||||
assert.cookedOptions(
|
||||
"Pleased to meet you, but pleeeease call me later, xyz123",
|
||||
|
Reference in New Issue
Block a user