Skip to content

Commit b95fa04

Browse files
fix (embed): migrate embed to fastboot
1 parent 3d571b7 commit b95fa04

File tree

7 files changed

+96
-70
lines changed

7 files changed

+96
-70
lines changed

public/assets/boot/bundler_init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ window.bundler = (function(origin) {
1111
);
1212
code = code.replace(/(?<!["])\bimport\.meta\.url\b(?!["])/g, `"${origin + path}"`);
1313
code += `\n//# sourceURL=${path}`;
14-
esModules[path] = "data:text/javascript," + encodeURIComponent(code);
14+
esModules[origin + path] = "data:text/javascript," + encodeURIComponent(code);
1515
} else if (path.endsWith(".css")) {
1616
code = code.replace(/@import url\("([^"]+)"\);/g, (m, rel) => {
1717
const $style = document.head.querySelector(`style[id="${new URL(rel, origin + path).href}"]`);

public/assets/embed/filestash-image.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import { init as initConfig, getVersion, get } from "../model/config.js";
2-
3-
const DEBOUNCETIME = 100;
4-
5-
await initConfig();
6-
71
class FilestashImage extends HTMLElement {
82
constructor() {
93
super();
@@ -31,7 +25,7 @@ class FilestashImage extends HTMLElement {
3125
type: "refresh",
3226
payload: { name: this.getAttribute("name"), src: this.getAttribute("src") },
3327
}, "*");
34-
}, DEBOUNCETIME);
28+
}, 100);
3529
}
3630
}
3731

@@ -43,7 +37,6 @@ class FilestashImage extends HTMLElement {
4337
connectedCallback() {
4438
const src = this.getAttribute("src") || "";
4539
const name = this.getAttribute("name") || "main.dat";
46-
const mime = get("mime", {})[name.split(".").pop().toLowerCase()];
4740

4841
this.style.display = "inline-block";
4942
this.iframe.srcdoc = `<!DOCTYPE html>
@@ -84,32 +77,45 @@ class FilestashImage extends HTMLElement {
8477
</script>
8578
8679
<script type="module" defer>
87-
import { render } from "${import.meta.url}/../../${getVersion()}/index.js";
88-
import * as Application from "${import.meta.url}/../../${getVersion()}/pages/viewerpage/application_image.js";
89-
import { init as initCache } from "${import.meta.url}/../../${getVersion()}/pages/filespage/cache.js";
90-
91-
await initCache();
92-
93-
const $app = document.querySelector("#app");
94-
render(Application, $app, {
95-
mime: "${mime}",
96-
hasMenubar: true,
97-
getFilename: () => "${name}",
98-
getDownloadUrl: () => "${src}",
99-
});
100-
window.addEventListener("message", (event) => {
101-
if(event.data.type === "refresh") {
80+
const [{ version, mimes }] = await Promise.all([
81+
fetch("${import.meta.url}/../../../api/config").then(async (resp) => {
82+
if (!resp.ok) return "na";
83+
const { result } = await resp.json();
84+
return { version: result.version, mimes: result.mime };
85+
}),
86+
import("${import.meta.url}/../../boot/bundler_init.js").then(async () => {
87+
await new Promise((resolve, reject) => document.head.appendChild(Object.assign(document.createElement("script"), {
88+
type: "module",
89+
src: new URL("../bundle.js", "${import.meta.url}"),
90+
onload: resolve,
91+
onerror: reject,
92+
})));
93+
await import("${import.meta.url}/../../boot/bundler_complete.js");
94+
}),
95+
]);
96+
97+
const { render } = await import("${import.meta.url}/../../"+ version +"/index.js");
98+
const Application = await import("${import.meta.url}/../../"+ version +"/pages/viewerpage/application_image.js");
99+
100+
const $app = document.querySelector("#app");
101+
const mime = mimes["${name}".split(".").pop().toLowerCase()];
102+
render(Application, $app, {
103+
mime: mime,
104+
hasMenubar: true,
105+
getFilename: () => "${name}",
106+
getDownloadUrl: () => "${src}",
107+
});
108+
window.addEventListener("message", (event) => {
109+
if(event.data.type !== "refresh") return;
102110
render(Application, $app, {
103-
mime: "${mime}",
111+
mime: mime,
104112
hasMenubar: true,
105113
getFilename: () => event.data.payload.name,
106114
getDownloadUrl: () => event.data.payload.src,
107115
});
108-
}
109-
});
116+
});
110117
</script>
111118
112-
<script type="module" src="${import.meta.url}/../../${getVersion()}/components/modal.js"></script>
113119
<component-modal></component-modal>
114120
</body>
115121
</html>`;

public/assets/embed/filestash-map.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import { init as initConfig, getVersion } from "../model/config.js";
2-
3-
const DEBOUNCETIME = 100;
4-
5-
await initConfig();
6-
71
class FilestashMap extends HTMLElement {
82
constructor() {
93
super();
@@ -30,7 +24,7 @@ class FilestashMap extends HTMLElement {
3024
type: "refresh",
3125
payload: { name: this.getAttribute("name"), src: this.getAttribute("src") },
3226
}, "*");
33-
}, DEBOUNCETIME);
27+
}, 100);
3428
}
3529
}
3630

@@ -41,12 +35,7 @@ class FilestashMap extends HTMLElement {
4135

4236
connectedCallback() {
4337
const src = this.getAttribute("src") || "";
44-
const name = this.getAttribute("name") || "main.dbf";
45-
const mime = {
46-
"geojson": "application/geo+json",
47-
"shp": "application/vnd.shp",
48-
"wms": "application/vnd.ogc.wms_xml",
49-
}[name.split(".").pop().toLowerCase()];
38+
const name = this.getAttribute("name") || "main.dat";
5039

5140
this.style.display = "inline-block";
5241
this.iframe.srcdoc = `<!DOCTYPE html>
@@ -87,29 +76,45 @@ class FilestashMap extends HTMLElement {
8776
</script>
8877
8978
<script type="module" defer>
90-
import { render } from "${import.meta.url}/../../${getVersion()}/index.js";
91-
import * as Application from "${import.meta.url}/../../${getVersion()}/pages/viewerpage/application_map.js";
79+
const [{ version, mimes }] = await Promise.all([
80+
fetch("${import.meta.url}/../../../api/config").then(async (resp) => {
81+
if (!resp.ok) return "na";
82+
const { result } = await resp.json();
83+
return { version: result.version, mimes: result.mime };
84+
}),
85+
import("${import.meta.url}/../../boot/bundler_init.js").then(async () => {
86+
await new Promise((resolve, reject) => document.head.appendChild(Object.assign(document.createElement("script"), {
87+
type: "module",
88+
src: new URL("../bundle.js", "${import.meta.url}"),
89+
onload: resolve,
90+
onerror: reject,
91+
})));
92+
await import("${import.meta.url}/../../boot/bundler_complete.js");
93+
}),
94+
]);
9295
93-
const $app = document.querySelector("#app");
94-
render(Application, $app, {
95-
mime: "${mime}",
96-
hasMenubar: true,
97-
getFilename: () => "${name}",
98-
getDownloadUrl: () => "${src}",
99-
});
100-
window.addEventListener("message", (event) => {
101-
if(event.data.type === "refresh") {
96+
const { render } = await import("${import.meta.url}/../../"+ version +"/index.js");
97+
const Application = await import("${import.meta.url}/../../"+ version +"/pages/viewerpage/application_map.js");
98+
99+
const $app = document.querySelector("#app");
100+
const mime = mimes["${name}".split(".").pop().toLowerCase()];
101+
render(Application, $app, {
102+
mime: mime,
103+
hasMenubar: true,
104+
getFilename: () => "${name}",
105+
getDownloadUrl: () => "${src}",
106+
});
107+
window.addEventListener("message", (event) => {
108+
if(event.data.type !== "refresh") return;
102109
render(Application, $app, {
103-
mime: "${mime}",
110+
mime: mime,
104111
hasMenubar: true,
105112
getFilename: () => event.data.payload.name,
106113
getDownloadUrl: () => event.data.payload.src,
107114
});
108-
}
109-
});
115+
});
110116
</script>
111117
112-
<script type="module" src="${import.meta.url}/../../${getVersion()}/components/modal.js"></script>
113118
<component-modal></component-modal>
114119
</body>
115120
</html>`;

public/assets/embed/filestash-table.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,42 @@ class FilestashTable extends HTMLElement {
7575
});
7676
</script>
7777
<script type="module" defer>
78-
import { init as initConfig, getVersion, get } from "${import.meta.url}/../../model/config.js";
78+
const [{ version, mimes }] = await Promise.all([
79+
fetch("${import.meta.url}/../../../api/config").then(async (resp) => {
80+
if (!resp.ok) return "na";
81+
const { result } = await resp.json();
82+
return { version: result.version, mimes: result.mime };
83+
}),
84+
import("${import.meta.url}/../../boot/bundler_init.js").then(async () => {
85+
await new Promise((resolve, reject) => document.head.appendChild(Object.assign(document.createElement("script"), {
86+
type: "module",
87+
src: new URL("../bundle.js", "${import.meta.url}"),
88+
onload: resolve,
89+
onerror: reject,
90+
})));
91+
await import("${import.meta.url}/../../boot/bundler_complete.js");
92+
}),
93+
]);
7994
80-
await initConfig();
81-
const { render } = await import("${import.meta.url}/../../"+ getVersion() +"/index.js");
82-
const Application = await import("${import.meta.url}/../../"+ getVersion() +"/pages/viewerpage/application_table.js");
95+
const { render } = await import("${import.meta.url}/../../"+ version +"/index.js");
96+
const Application = await import("${import.meta.url}/../../"+ version +"/pages/viewerpage/application_table.js");
8397
8498
const $app = document.querySelector("#app");
85-
const mime = get("mime", {})["${name}".split(".").pop().toLowerCase()];
99+
const mime = mimes["${name}".split(".").pop().toLowerCase()];
86100
render(Application, $app, {
87101
mime: mime,
88102
hasMenubar: true,
89103
getFilename: () => "${name}",
90104
getDownloadUrl: () => "${src}",
91105
});
92106
window.addEventListener("message", (event) => {
93-
if(event.data.type === "refresh") {
94-
render(Application, $app, {
95-
mime: mime,
96-
hasMenubar: true,
97-
getFilename: () => event.data.payload.name,
98-
getDownloadUrl: () => event.data.payload.src,
99-
});
100-
}
107+
if(event.data.type !== "refresh") return;
108+
render(Application, $app, {
109+
mime: mime,
110+
hasMenubar: true,
111+
getFilename: () => event.data.payload.name,
112+
getDownloadUrl: () => event.data.payload.src,
113+
});
101114
});
102115
</script>
103116

public/assets/pages/filespage/cache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export async function init() {
221221
const setup_cache = () => {
222222
cache = new InMemoryCache();
223223
if (!("indexedDB" in window)) return;
224+
else if (window.self !== window.top) return;
224225

225226
cache = assert.truthy(new IndexDBCache());
226227
return cache.db.catch((err) => {

public/index.frontoffice.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
src: `./assets/bundle.js?version=${window.VERSION}`,
4545
onload: resolve,
4646
onerror: reject,
47-
})))
47+
})));
4848
{{ load_asset "assets/boot/bundler_complete.js" }}
4949
} catch (err) { console.error(err); }
5050

server/ctrl/static.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ func ServeBundle() func(*App, http.ResponseWriter, *http.Request) {
376376
"/assets/" + BUILD_REF + "/pages/viewerpage/model_files.js",
377377
"/assets/" + BUILD_REF + "/pages/viewerpage/common.js",
378378
"/assets/" + BUILD_REF + "/pages/viewerpage/application_downloader.js",
379+
"/assets/" + BUILD_REF + "/pages/viewerpage/application_downloader.css",
379380
"/assets/" + BUILD_REF + "/pages/viewerpage/component_menubar.js",
380381
"/assets/" + BUILD_REF + "/pages/viewerpage/component_menubar.css",
381382
}

0 commit comments

Comments
 (0)