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/util/consts/site-license.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { sortBy } from "lodash";6import { SiteLicenseQuota } from "../types/site-licenses";78type Keys = NonNullable<SiteLicenseQuota["idle_timeout"]>;910// Site Licenses related constants11// the license timeouts combined with the default quota (either hardcoded or the one from the site_settings)12// hence 30 minutes + 30 minutes default result in 30 minutes, and the same for "medium" and "day"13// @see DEFAULT_QUOTAS.mintime in src/packages/util/upgrade-spec.js14// medium and day imply member hosting15export const LicenseIdleTimeouts: {16[key in Keys]: {17mins: number;18label: string;19labelShort: string; // same as "label", but shorter20priceFactor: number;21requireMemberhosting?: boolean; // if true, require member hosting22};23} = {24short: {25mins: 30,26label: "30 minutes",27labelShort: "30min",28priceFactor: 1,29},30medium: { mins: 2 * 60, label: "2 hours", labelShort: "2h", priceFactor: 2 },31day: {32mins: 24 * 60,33label: "1 day",34labelShort: "1d",35priceFactor: 4,36requireMemberhosting: true,37},38} as const;3940export const LicenseIdleTimeoutsKeysOrdered = sortBy(41Object.keys(LicenseIdleTimeouts),42(v) => LicenseIdleTimeouts[v].mins43) as Readonly<Keys[]>;4445export function requiresMemberhosting(key?: Uptime | string): boolean {46if (key == null) return false;47if (key == "always_running") return true;48return LicenseIdleTimeouts[key]?.requireMemberhosting ?? false;49}5051export type Uptime = Keys | "always_running";5253export function untangleUptime(uptime?: Uptime): {54always_running: boolean;55idle_timeout: Keys;56} {57if (uptime == null) {58// Let's just support this and have it default to short, since obviously59// by explicitly allowing uptime? via typescript, we can't even tell there60// is a problem from typescript errors. See61// https://github.com/sagemathinc/cocalc/issues/625762// for how this bug causes a lot of trouble.63return { always_running: false, idle_timeout: "short" };64}65if (uptime == "always_running") {66return { always_running: true, idle_timeout: "day" };67}68return { always_running: false, idle_timeout: uptime };69}7071export function displaySiteLicense(uptime: Uptime) {72if (uptime == "always_running") {73return "Always Running";74} else {75return LicenseIdleTimeouts[uptime].label;76}77}787980