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/cloud-filesystem/util.ts
Views: 687
1
import { capitalize } from "@cocalc/util/misc";
2
import { markup } from "@cocalc/util/compute/cloud/google-cloud/compute-cost";
3
4
export function editModalStyle(cloudFilesystem) {
5
return {
6
borderWidth: "0.5px 10px",
7
borderStyle: "solid",
8
padding: "10px 15px",
9
borderRadius: "5px",
10
borderColor: cloudFilesystem.color ?? "#666",
11
};
12
}
13
14
// Price returned from this includes markup
15
export function getDataStoragePriceRange({
16
priceData,
17
bucket_location,
18
bucket_storage_class,
19
}): { min: number | null; max: number | null } {
20
if (priceData == null) {
21
return { min: null, max: null };
22
}
23
if (bucket_storage_class.startsWith("autoclass")) {
24
const min = getDataStoragePrice({
25
priceData,
26
bucket_location,
27
bucket_storage_class: bucket_storage_class.split("-")[1],
28
});
29
const max = getDataStoragePrice({
30
priceData,
31
bucket_location,
32
bucket_storage_class: "standard",
33
});
34
return { min, max };
35
} else {
36
const price = getDataStoragePrice({
37
priceData,
38
bucket_location,
39
bucket_storage_class,
40
});
41
return { min: price, max: price };
42
}
43
}
44
45
// Price returned from this includes markup
46
export function getDataStoragePrice({
47
priceData,
48
bucket_location,
49
bucket_storage_class,
50
}): number | null {
51
if (priceData == null) {
52
return null;
53
}
54
let cost;
55
if (!bucket_location.includes("-")) {
56
cost =
57
priceData.storage?.atRest?.multiRegions?.[bucket_location]?.[
58
capitalize(bucket_storage_class)
59
];
60
} else {
61
cost =
62
priceData.storage?.atRest?.regions?.[bucket_location]?.[
63
capitalize(bucket_storage_class)
64
];
65
}
66
return markup({
67
cost,
68
priceData,
69
});
70
}
71
72
const alpha = "abcdefghijklmnopqrstuvwxyz".split("");
73
export function getCity({ region, priceData }) {
74
if (priceData?.zones == null) {
75
return "";
76
}
77
for (const x of alpha) {
78
const z = priceData.zones[`${region}-${x}`];
79
if (z != null) {
80
return z.location.split(",")[1].trim();
81
}
82
}
83
return "";
84
}
85
86