2017-07-20 03:08:54 +08:00
|
|
|
let _cache = {};
|
|
|
|
|
|
|
|
export function applyInlineOneboxes(inline, ajax) {
|
2018-01-30 05:39:41 +08:00
|
|
|
Object.keys(inline).forEach(url => {
|
|
|
|
// cache a blank locally, so we never trigger a lookup
|
|
|
|
_cache[url] = {};
|
|
|
|
});
|
|
|
|
|
2017-07-20 03:08:54 +08:00
|
|
|
return ajax("/inline-onebox", {
|
2018-06-15 23:03:24 +08:00
|
|
|
data: { urls: Object.keys(inline) }
|
2017-07-20 03:08:54 +08:00
|
|
|
}).then(result => {
|
2018-06-15 23:03:24 +08:00
|
|
|
result["inline-oneboxes"].forEach(onebox => {
|
2018-11-13 04:14:20 +08:00
|
|
|
if (onebox.title) {
|
|
|
|
_cache[onebox.url] = onebox;
|
|
|
|
let links = inline[onebox.url] || [];
|
|
|
|
links.forEach(link => {
|
|
|
|
link.text(onebox.title);
|
|
|
|
});
|
|
|
|
}
|
2017-07-20 03:08:54 +08:00
|
|
|
});
|
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2017-07-20 03:08:54 +08:00
|
|
|
|
|
|
|
export function cachedInlineOnebox(url) {
|
|
|
|
return _cache[url];
|
|
|
|
}
|