Path: blob/master/src/packages/database/settings/customize.ts
1503 views
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import getStrategies from "@cocalc/database/settings/get-sso-strategies";6import { KUCALC_COCALC_COM } from "@cocalc/util/db-schema/site-defaults";7import type { Strategy } from "@cocalc/util/types/sso";8import { ServerSettings, getServerSettings } from "./server-settings";9import siteURL from "./site-url";10import { copy_with } from "@cocalc/util/misc";11import type { Customize } from "@cocalc/util/db-schema/server-settings";12export type { Customize };1314const fallback = (a?: string, b?: string): string =>15typeof a == "string" && a.length > 0 ? a : `${b}`;1617/*18Create a Javascript object that describes properties of the server.19This is used on the next.js server landing pages and the share server20to customize their look and behavior.2122This function is cached via the parameters in ./server-settings, i.e.,23for a few seconds.24*/2526let cachedSettings: ServerSettings | undefined = undefined;27let cachedCustomize: Customize | undefined = undefined;28export default async function getCustomize(29fields?: string[],30): Promise<Customize> {31const [settings, strategies]: [ServerSettings, Strategy[]] =32await Promise.all([getServerSettings(), getStrategies()]);3334if (!(settings === cachedSettings && cachedCustomize != null)) {35cachedSettings = settings;36cachedCustomize = {37siteName: fallback(settings.site_name, "On Premises CoCalc"),38siteDescription: fallback(39settings.site_description,40"Collaborative Calculation using Python, Sage, R, Julia, and more.",41),4243organizationName: settings.organization_name,44organizationEmail: settings.organization_email,45organizationURL: settings.organization_url,46termsOfServiceURL: settings.terms_of_service_url,4748helpEmail: settings.help_email,49contactEmail: fallback(settings.organization_email, settings.help_email),5051isCommercial: settings.commercial,5253kucalc: settings.kucalc,54sshGateway: settings.ssh_gateway,55sshGatewayDNS: settings.ssh_gateway_dns,5657anonymousSignup: settings.anonymous_signup,58anonymousSignupLicensedShares: settings.anonymous_signup_licensed_shares,59emailSignup: settings.email_signup,60accountCreationInstructions: settings.account_creation_email_instructions,6162logoSquareURL: settings.logo_square,63logoRectangularURL: settings.logo_rectangular,64splashImage: settings.splash_image,6566shareServer: !!settings.share_server,6768// additionally restrict showing landing pages only in cocalc.com-mode69landingPages:70!!settings.landing_pages && settings.kucalc === KUCALC_COCALC_COM,7172googleAnalytics: settings.google_analytics,7374indexInfo: settings.index_info_html,75indexTagline: settings.index_tagline,76imprint: settings.imprint,77policies: settings.policies,78support: settings.support,79supportVideoCall: settings.support_video_call,8081// Is important for invite emails, password reset, etc. (e.g., so we can construct a url to our site).82// This *can* start with http:// to explicitly use http instead of https, and can end83// in something like :3594 to indicate a port.84dns: settings.dns,85// siteURL is derived from settings.dns and the basePath -- it combines the dns, https://86// and the basePath. It never ends in a slash. This is used in practice for87// things like invite emails, password reset, etc.88siteURL: await siteURL(settings.dns),8990zendesk:91settings.zendesk_token &&92settings.zendesk_username &&93settings.zendesk_uri,9495// obviously only the public key here!96stripePublishableKey: settings.stripe_publishable_key,9798// obviously only the public key here too!99reCaptchaKey: settings.re_captcha_v3_publishable_key,100101// a sandbox project102sandboxProjectId: settings.sandbox_project_id,103sandboxProjectsEnabled: settings.sandbox_projects_enabled,104105// true if openai integration is enabled -- this impacts the UI only, and can be106// turned on and off independently of whether there is an api key set.107openaiEnabled: settings.openai_enabled,108// same for google vertex (exposed as gemini), and others109googleVertexaiEnabled: settings.google_vertexai_enabled,110mistralEnabled: settings.mistral_enabled,111anthropicEnabled: settings.anthropic_enabled,112ollamaEnabled: settings.ollama_enabled,113114neuralSearchEnabled: settings.neural_search_enabled,115116// if extra Jupyter API functionality for sandboxed ephemeral code execution is available.117jupyterApiEnabled: settings.jupyter_api_enabled,118119computeServersEnabled: settings.compute_servers_enabled,120cloudFilesystemsEnabled: settings.cloud_filesystems_enabled,121122// GitHub proxy project123githubProjectId: settings.github_project_id,124125// public info about SSO strategies126strategies,127128verifyEmailAddresses: settings.verify_emails && settings.email_enabled,129130version: {131min_project: parseInt(settings.version_min_project),132min_compute_server: parseInt(settings.version_min_compute_server),133min_browser: parseInt(settings.version_min_browser),134recommended_browser: parseInt(settings.version_recommended_browser),135compute_server_min_project: parseInt(136settings.version_compute_server_min_project,137),138},139};140}141return fields ? copy_with(cachedCustomize, fields) : cachedCustomize;142}143144145