CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/config.ts
Views: 687
1
import { redux } from "@cocalc/frontend/app-framework";
2
import { CLOUDS_BY_NAME, Cloud } from "@cocalc/util/db-schema/compute-servers";
3
4
// Returns true if in admin compute_servers_enabled is true *and* at least
5
// one cloud is also enabled, since otherwise compute servers are not in any
6
// way useful. Returns false, if compute servers are not enabled or no cloud
7
// enabled. Returns null if we don't know yet, since e.g., page is just loading
8
// and/or backend server is slow to initialize the customize store.
9
export function computeServersEnabled(): true | false | null {
10
const customize = redux.getStore("customize");
11
if (customize == null || customize.get("time") == null) {
12
// definitely NOT loaded yet.
13
return null;
14
}
15
if (!customize.get("compute_servers_enabled")) {
16
return false;
17
}
18
for (const cloud in CLOUDS_BY_NAME) {
19
if (customize.get(`compute_servers_${cloud}_enabled`)) {
20
return true;
21
}
22
}
23
return false;
24
}
25
26
export function cloudFilesystemsEnabled(): true | false | null {
27
const customize = redux.getStore("customize");
28
if (customize == null || customize.get("time") == null) {
29
// definitely NOT loaded yet.
30
return null;
31
}
32
// requires also google cloud and compute servers in general:
33
return (
34
!!customize.get("compute_servers_enabled") &&
35
!!customize.get("compute_servers_google-cloud_enabled") &&
36
!!customize.get("cloud_filesystems_enabled")
37
);
38
}
39
40
export function availableClouds(): Cloud[] {
41
const v: Cloud[] = [];
42
const customize = redux.getStore("customize");
43
if (customize == null) {
44
return v;
45
}
46
for (const cloud in CLOUDS_BY_NAME) {
47
if (customize.get(`compute_servers_${cloud}_enabled`)) {
48
v.push(CLOUDS_BY_NAME[cloud].name);
49
}
50
}
51
return v;
52
}
53
54