mirror of
https://github.com/discourse/discourse.git
synced 2025-06-17 06:05:05 +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:
@ -23,6 +23,11 @@ QUnit.module("lib:pretty-text/upload-short-url", {
|
||||
short_url: "upload://b.jpeg",
|
||||
url: "/uploads/default/original/3X/c/b/2.jpeg",
|
||||
short_path: "/uploads/short-url/b.jpeg"
|
||||
},
|
||||
{
|
||||
short_url: "upload://z.jpeg",
|
||||
url: "/uploads/default/original/3X/c/b/9.jpeg",
|
||||
short_path: "/uploads/short-url/z.jpeg"
|
||||
}
|
||||
];
|
||||
|
||||
@ -53,7 +58,8 @@ QUnit.module("lib:pretty-text/upload-short-url", {
|
||||
|
||||
fixture().html(
|
||||
imageSrcs.map(src => `<img data-orig-src="${src.url}">`).join("") +
|
||||
attachmentSrcs.map(src => `<a data-orig-href="${src.url}">`).join("")
|
||||
attachmentSrcs.map(src => `<a data-orig-href="${src.url}">`).join("") +
|
||||
`<div class="scoped-area"><img data-orig-src="${imageSrcs[2].url}"></div>`
|
||||
);
|
||||
},
|
||||
|
||||
@ -105,3 +111,23 @@ QUnit.test("resolveAllShortUrls", async assert => {
|
||||
short_path: "/uploads/short-url/e.mp3"
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("resolveAllShortUrls - scoped", async assert => {
|
||||
let lookup;
|
||||
await resolveAllShortUrls(ajax, ".scoped-area");
|
||||
|
||||
lookup = lookupCachedUploadUrl("upload://z.jpeg");
|
||||
|
||||
assert.deepEqual(lookup, {
|
||||
url: "/uploads/default/original/3X/c/b/9.jpeg",
|
||||
short_path: "/uploads/short-url/z.jpeg"
|
||||
});
|
||||
|
||||
// do this because the pretender caches ALL the urls, not
|
||||
// just the ones being looked up (like the normal behaviour)
|
||||
resetCache();
|
||||
await resolveAllShortUrls(ajax, ".scoped-area");
|
||||
|
||||
lookup = lookupCachedUploadUrl("upload://a.jpeg");
|
||||
assert.deepEqual(lookup, {});
|
||||
});
|
||||
|
Reference in New Issue
Block a user