mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
d7a2584c6e
Shorten all image uploads to use short urls, this is the client side implementation.
19 lines
515 B
JavaScript
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;
|
|
}
|