Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/custom-software/util.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { join as path_join } from "path";6import { COLORS } from "@cocalc/util/theme";7import { IconName } from "@cocalc/frontend/components/icon";89export const RESET_ICON: IconName = "redo";1011// Do NOT change this:12export type NAME_TYPE = "compute_images";13export const NAME = "compute_images" as NAME_TYPE;1415export const CUSTOM_IMG_PREFIX = "custom/";1617export const CUSTOM_SOFTWARE_HELP_URL =18"https://doc.cocalc.com/software.html#custom-environments";1920export function compute_image2name(compute_image: string): string {21const name = compute_image.slice(CUSTOM_IMG_PREFIX.length);22return name.replace("/", ":");23}2425export function compute_image2basename(compute_image: string): string {26const name = compute_image.slice(CUSTOM_IMG_PREFIX.length);27return name.split("/")[0];28}2930export const title_style: React.CSSProperties = {31textOverflow: "ellipsis",32whiteSpace: "nowrap" as "nowrap",33overflow: "hidden",34paddingLeft: "10px",35margin: "5px 10px",36color: COLORS.GRAY,37} as const;3839export function props2img(props: {40project_map?;41project_id: string;42images?;43}) {44if (props.project_map == null) return null;45const ci = props.project_map.getIn([props.project_id, "compute_image"]);46if (ci == null) return null;47if (!ci.startsWith(CUSTOM_IMG_PREFIX)) return null;48return props.images?.get(compute_image2basename(ci));49}5051// derive the actual compute image name (which will be set in the DB) from the selected ID.52export function custom_image_name(id: string): string {53let tag: string;54if (id.indexOf(":") >= 0) {55[id, tag] = id.split(":");56} else {57tag = "latest";58}59return path_join(CUSTOM_IMG_PREFIX, id, tag);60}6162export function is_custom_image(img: string): boolean {63return img.startsWith(CUSTOM_IMG_PREFIX);64}656667