Spaces:
Sleeping

File size: 1,271 Bytes
41f07fa
1a49047
 
41f07fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a49047
41f07fa
 
 
1a49047
 
 
 
 
 
 
 
 
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
import { getDatasetMeta } from "./api";
import type { Bootstrap } from "./types";

interface StaticManifest {
  datasets: string[];
  default: string;
  wavelengths: Record<string, number>;
  stretches: string[];
  rgb_presets: string[][];
}

// Fetch the static manifest + the default dataset's meta so we can populate
// the initial state with something meaningful (matches what the Jinja
// bootstrap block previously provided).
export async function readBootstrap(): Promise<Bootstrap> {
  try {
    const manifest = (await (await fetch("./data/manifest.json")).json()) as StaticManifest;
    const defaultDs = manifest.default;
    if (!defaultDs) return emptyBootstrap();
    const meta = await getDatasetMeta(defaultDs);
    const defaultCube = meta.datacubes[0];
    return {
      datasets: manifest.datasets,
      default_dataset: defaultDs,
      default_datacube: defaultCube,
      datacubes: meta.datacubes,
      filters: (meta.filters[defaultCube] ?? []).map((f) => f.name),
      wavelengths: manifest.wavelengths,
    };
  } catch {
    return emptyBootstrap();
  }
}

function emptyBootstrap(): Bootstrap {
  return {
    datasets: [],
    default_dataset: "",
    default_datacube: "",
    datacubes: [],
    filters: [],
    wavelengths: {},
  };
}