discourse/app/assets/javascripts/pretty-text/image-short-url.js.es6
Sam d7a2584c6e FEATURE: image uploads now have short urls
Shorten all image uploads to use short urls, this is the client
side implementation.
2017-08-22 16:40:08 -04:00

19 lines
515 B
JavaScript

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;
}