discourse/app/assets/javascripts/pretty-text/image-short-url.js.es6

19 lines
515 B
Plaintext
Raw Normal View History

let _cache = {};
export function lookupCachedUploadUrl(shortUrl) {
return _cache[shortUrl];
}
export function lookupUncachedUploadUrls(urls, ajax) {
return ajax('/uploads/lookup-urls', { method: 'POST', data: { short_urls: urls } })
.then(uploads => {
uploads.forEach(upload => _cache[upload.short_url] = upload.url);
urls.forEach(url => _cache[url] = _cache[url] || "missing");
return uploads;
});
}
export function cacheShortUploadUrl(shortUrl, url) {
_cache[shortUrl] = url;
}