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/custom-software/util.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { join as path_join } from "path";
7
import { COLORS } from "@cocalc/util/theme";
8
import { IconName } from "@cocalc/frontend/components/icon";
9
10
export const RESET_ICON: IconName = "redo";
11
12
// Do NOT change this:
13
export type NAME_TYPE = "compute_images";
14
export const NAME = "compute_images" as NAME_TYPE;
15
16
export const CUSTOM_IMG_PREFIX = "custom/";
17
18
export const CUSTOM_SOFTWARE_HELP_URL =
19
"https://doc.cocalc.com/software.html#custom-environments";
20
21
export function compute_image2name(compute_image: string): string {
22
const name = compute_image.slice(CUSTOM_IMG_PREFIX.length);
23
return name.replace("/", ":");
24
}
25
26
export function compute_image2basename(compute_image: string): string {
27
const name = compute_image.slice(CUSTOM_IMG_PREFIX.length);
28
return name.split("/")[0];
29
}
30
31
export const title_style: React.CSSProperties = {
32
textOverflow: "ellipsis",
33
whiteSpace: "nowrap" as "nowrap",
34
overflow: "hidden",
35
paddingLeft: "10px",
36
margin: "5px 10px",
37
color: COLORS.GRAY,
38
} as const;
39
40
export function props2img(props: {
41
project_map?;
42
project_id: string;
43
images?;
44
}) {
45
if (props.project_map == null) return null;
46
const ci = props.project_map.getIn([props.project_id, "compute_image"]);
47
if (ci == null) return null;
48
if (!ci.startsWith(CUSTOM_IMG_PREFIX)) return null;
49
return props.images?.get(compute_image2basename(ci));
50
}
51
52
// derive the actual compute image name (which will be set in the DB) from the selected ID.
53
export function custom_image_name(id: string): string {
54
let tag: string;
55
if (id.indexOf(":") >= 0) {
56
[id, tag] = id.split(":");
57
} else {
58
tag = "latest";
59
}
60
return path_join(CUSTOM_IMG_PREFIX, id, tag);
61
}
62
63
export function is_custom_image(img: string): boolean {
64
return img.startsWith(CUSTOM_IMG_PREFIX);
65
}
66
67