Path: blob/master/src/packages/frontend/custom-software/util.ts
5747 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import type { IconName } from "@cocalc/frontend/components/icon";67import { join as path_join } from "path";89import { COLORS } from "@cocalc/util/theme";1011export const RESET_ICON: IconName = "redo";1213// Do NOT change this:14export type NAME_TYPE = "compute_images";15export const NAME = "compute_images" as NAME_TYPE;1617export const CUSTOM_IMG_PREFIX = "custom/";1819export const CUSTOM_SOFTWARE_HELP_URL =20"https://doc.cocalc.com/software.html#custom-environments";2122export function compute_image2name(compute_image: string): string {23const name = compute_image.slice(CUSTOM_IMG_PREFIX.length);24return name.replace("/", ":");25}2627export function compute_image2basename(compute_image: string): string {28const name = compute_image.slice(CUSTOM_IMG_PREFIX.length);29return name.split("/")[0];30}3132export const title_style: React.CSSProperties = {33textOverflow: "ellipsis",34whiteSpace: "nowrap" as "nowrap",35overflow: "hidden",36paddingLeft: "10px",37margin: "5px 10px",38color: COLORS.GRAY,39} as const;4041export function props2img(props: {42project_map?;43project_id: string;44images?;45}) {46if (props.project_map == null) return null;47const ci = props.project_map.getIn([props.project_id, "compute_image"]);48if (ci == null) return null;49if (!is_custom_image(ci)) return null;50return props.images?.get(compute_image2basename(ci));51}5253// derive the actual compute image name (which will be set in the DB) from the selected ID.54export function custom_image_name(id: string): string {55let tag: string;56if (id.indexOf(":") >= 0) {57[id, tag] = id.split(":");58} else {59tag = "latest";60}61return path_join(CUSTOM_IMG_PREFIX, id, tag);62}6364export function is_custom_image(img: string): boolean {65return img.startsWith(CUSTOM_IMG_PREFIX);66}676869