-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (28 loc) · 973 Bytes
/
app.js
File metadata and controls
33 lines (28 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
async function isFileView() {
const params = new URLSearchParams(window.location.search);
const cache = await caches.open(CACHE);
const req = new Request("index.html", { method: "GET" });
return params.has("f") || params.has("d") || !(await cache.match(req));
}
async function getFilesFromHash() {
const hash = window.location.hash;
if (hash === "") return [];
const hashData = hash.substring(1);
const compressedBytes = base64ToBytes(hashData);
const decompressedBytes = await decompress(compressedBytes);
const files = unbundleFiles(decompressedBytes);
return files;
}
setLinkText(window.location.href);
(async () => {
const files = await getFilesFromHash();
if (!files.length) return;
await addFiles(files);
if (await isFileView()) {
const blob = new Blob([defaultHtmlContent], { type: "text/html" });
const url = URL.createObjectURL(blob);
window.location.href = url;
} else {
location.href = "index.html"
}
})();