File size: 1,056 Bytes
da5cba1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6abb7be
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
// Data more than one view reads: every Harbor dataset on the Hub, and the signed-in visitor's own. Fetched once.
import { api } from "./util.js";
import { getSession } from "./session.js";

let envs = null, mine = null;

export function environments() {
  if (!envs) {
    envs = api("/api/environments").then((d) => {
      d.datasets.forEach((x) => { x._blob = `${x.id} ${x.heading || ""} ${x.brief} ${x.tags.join(" ")}`.toLowerCase(); });
      d.byKey = Object.fromEntries(d.datasets.map((x) => [x.key, x]));
      return d;
    }).catch((e) => { envs = null; throw e; });
  }
  return envs;
}

// the visitor's own Harbor datasets and their organizations', private ones included; [] when signed out
export function myDatasets() {
  if (!getSession().user) return Promise.resolve([]);
  if (!mine) mine = api("/api/environments/mine").then((d) => d.datasets).catch(() => { mine = null; return []; });
  return mine;
}
export function forgetMine() { mine = null; }

// Ranking is centralized in /api/search so list, filters and individual ranks agree.