diff --git a/core/client.js b/core/client.js
index 938db2ae..9f41448a 100644
--- a/core/client.js
+++ b/core/client.js
@@ -527,6 +527,13 @@ function onMessage(event) {
var iframe = document.getElementById("iframe_" + event.data.name);
iframe.setAttribute("width", event.data.width);
iframe.setAttribute("height", event.data.height);
+ var node = iframe.parentElement;
+ while (node && !node.classList.contains("terminal")) {
+ node = node.parentElement;
+ }
+ if (node) {
+ autoScroll(node);
+ }
} else {
send({event: "onWindowMessage", message: event.data});
}
diff --git a/packages/cory/libunfurl/libunfurl.js b/packages/cory/libunfurl/libunfurl.js
index bb50298f..7ead793f 100644
--- a/packages/cory/libunfurl/libunfurl.js
+++ b/packages/cory/libunfurl/libunfurl.js
@@ -6,6 +6,7 @@ let libxml = require("libxml");
let libhttp = require("libhttp");
let gEmbedIndex = 0;
+let gCache = {};
async function unfurl(url) {
let result = {href: url};
@@ -26,10 +27,8 @@ async function unfurl(url) {
result = [{href: url}, "\n", {
name: "oEmbed" + gEmbedIndex,
iframe: `
-
- ${oEmbed.html}
-
-
-`,
+ `,
width: oEmbed.width || 320,
height: oEmbed.height || 120,
style: "margin: 0; padding: 0; border: 0; overflow: hidden",
@@ -62,6 +60,23 @@ async function test() {
//test().catch(terminal.print);
-core.register("onMessage", function(sender, message) {
- return unfurl(message).catch(error => [message, "(error retrieving: ", error, ")"]);
+core.register("onMessage", async function(sender, message) {
+ let result = message;
+ if (gCache[message] && new Date().valueOf() < gCache[message].expires) {
+ result = gCache[message].result;
+ } else {
+ if (gCache[message]) {
+ print("Didn't use", gCache[message]);
+ }
+ try {
+ result = await unfurl(message);
+ } catch (error) {
+ result = [message, "(error retrieving: ", error, ")"];
+ }
+ gCache[message] = {
+ expires: new Date().valueOf() + 7 * 24 * 60 * 60 * 1000,
+ result: result,
+ };
+ }
+ return result;
});
\ No newline at end of file