FIX: Oneboxing root domains could stop previewing

This commit is contained in:
Robin Ward 2017-06-12 12:13:05 -04:00
parent 4112c2b883
commit bd70656b90
1 changed files with 12 additions and 6 deletions

View File

@ -19,7 +19,7 @@ function loadNext(ajax) {
data: { url, refresh, user_id: userId },
cache: true
}).then(html => {
localCache[url] = html;
localCache[normalize(url)] = html;
$elem.replaceWith(html);
}, result => {
if (result && result.jqXHR && result.jqXHR.status === 429) {
@ -27,7 +27,7 @@ function loadNext(ajax) {
removeLoading = false;
loadingQueue.unshift({ url, refresh, $elem, userId });
} else {
failedCache[url] = true;
failedCache[normalize(url)] = true;
}
}).finally(() => {
timeout = Ember.run.later(() => loadNext(ajax), timeoutMs);
@ -52,11 +52,11 @@ export function load(e, refresh, ajax, userId, synchronous) {
// Unless we're forcing a refresh...
if (!refresh) {
// If we have it in our cache, return it.
const cached = localCache[url];
const cached = localCache[normalize(url)];
if (cached) return cached;
// If the request failed, don't do anything
const failed = failedCache[url];
const failed = failedCache[normalize(url)];
if (failed) return;
}
@ -74,6 +74,12 @@ export function load(e, refresh, ajax, userId, synchronous) {
}
}
export function lookupCache(url) {
return localCache[url];
// Sometimes jQuery will return URLs with trailing slashes when the
// `href` didn't have them.
function normalize(url) {
return url.replace(/\/$/, '');
}
export function lookupCache(url) {
return localCache[normalize(url)];
}