forked from Tevemadar/meshview-demo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudloaders.js
59 lines (58 loc) · 2.39 KB
/
cloudloaders.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
async function loadlz(filename) {
const lz = await fetch(
`https://data-proxy.ebrains.eu/api/v1/buckets/${state["clb-collab-id"]}/${filename}?redirect=false`,
{headers: {Authorization: `Bearer ${state.token}`}})
.then(response => response.json())
.then(json => fetch(json.url.includes("?")?json.url:json.url+"?"+Date.now()))
.then(response => response.json());
const cloud = [];
//debugger;
for (const section of lz.sections)
if (section.ouv && section.poi) { // todo: propagation, nonlin
const {filename, ouv, poi} = section;
const triplets = poi.flatMap(p2d => [
ouv[0] + p2d.x * ouv[3] / section.width + p2d.y * ouv[6] / section.height,
ouv[1] + p2d.x * ouv[4] / section.width + p2d.y * ouv[7] / section.height,
ouv[2] + p2d.x * ouv[5] / section.width + p2d.y * ouv[8] / section.height
]);
cloud.push({name: filename, r: 0, g: 0, b: 0, triplets});
}
return {filename, lz, cloud};
}
async function loadzip(filename, pre) {
let phase = 0;
let msg = `Opening ${filename} `;
const spinner = setInterval(() => {
pre.innerText = msg + ("-\\|/".charAt(phase++));
phase &= 3;
}, 20);
const update = line => msg += `\n${line}`;
const stop = () => {
clearInterval(spinner);
pre.innerText = msg;
};
const zipdir = await netunzip( // TODO? Date.now()
async() => fetch(
`https://data-proxy.ebrains.eu/api/v1/buckets/${state["clb-collab-id"]}/${filename}?redirect=false`,
{headers: {Authorization: `Bearer ${state.token}`}})
.then(response => response.json()).then(json => json.url)).catch(ex => {
update(ex);
});
if (!zipdir)
return{stop};
const td = new TextDecoder();
let json, label;
for (const [_, entry] of zipdir.entries) {
if (entry.name.endsWith("combined.json")) {
update("Combined JSON found ");
json = JSON.parse(td.decode(await zipdir.get(entry)));
}
if (entry.name.endsWith("nutil.nut")) {
update("Nutil configuration found ");
label = td.decode(await zipdir.get(entry)).match(/label_file = (.*)/m)[1];
}
}
if (label && json)
return {label, json, update, stop};
return{stop};
}