Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/database/settings/customize.ts
5613 views
1
/*
2
* This file is part of CoCalc: Copyright © 2021-2025 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import getStrategies from "@cocalc/database/settings/get-sso-strategies";
7
import { KUCALC_COCALC_COM } from "@cocalc/util/db-schema/site-defaults";
8
import type { Strategy } from "@cocalc/util/types/sso";
9
import { ServerSettings, getServerSettings } from "./server-settings";
10
import siteURL from "./site-url";
11
import { copy_with } from "@cocalc/util/misc";
12
import type { Customize } from "@cocalc/util/db-schema/server-settings";
13
export type { Customize };
14
15
const fallback = (a?: string, b?: string): string =>
16
typeof a == "string" && a.length > 0 ? a : `${b}`;
17
18
/*
19
Create a Javascript object that describes properties of the server.
20
This is used on the next.js server landing pages and the share server
21
to customize their look and behavior.
22
23
This function is cached via the parameters in ./server-settings, i.e.,
24
for a few seconds.
25
*/
26
27
let cachedSettings: ServerSettings | undefined = undefined;
28
let cachedCustomize: Customize | undefined = undefined;
29
export default async function getCustomize(
30
fields?: string[],
31
): Promise<Customize> {
32
const [settings, strategies]: [ServerSettings, Strategy[]] =
33
await Promise.all([getServerSettings(), getStrategies()]);
34
35
if (!(settings === cachedSettings && cachedCustomize != null)) {
36
cachedSettings = settings;
37
cachedCustomize = {
38
siteName: fallback(settings.site_name, "On Premises CoCalc"),
39
siteDescription: fallback(
40
settings.site_description,
41
"Collaborative Calculation using Python, Sage, R, Julia, and more.",
42
),
43
44
organizationName: settings.organization_name,
45
organizationEmail: settings.organization_email,
46
organizationURL: settings.organization_url,
47
termsOfServiceURL: settings.terms_of_service_url,
48
49
helpEmail: settings.help_email,
50
contactEmail: fallback(settings.organization_email, settings.help_email),
51
52
isCommercial: settings.commercial,
53
54
kucalc: settings.kucalc,
55
sshGateway: settings.ssh_gateway,
56
sshGatewayDNS: settings.ssh_gateway_dns,
57
58
anonymousSignup: settings.anonymous_signup,
59
anonymousSignupLicensedShares: settings.anonymous_signup_licensed_shares,
60
emailSignup: settings.email_signup,
61
accountCreationInstructions: settings.account_creation_email_instructions,
62
63
logoSquareURL: settings.logo_square,
64
logoRectangularURL: settings.logo_rectangular,
65
splashImage: settings.splash_image,
66
67
shareServer: !!settings.share_server,
68
69
// additionally restrict showing landing pages only in cocalc.com-mode
70
landingPages:
71
!!settings.landing_pages && settings.kucalc === KUCALC_COCALC_COM,
72
73
googleAnalytics: settings.google_analytics,
74
75
indexInfo: settings.index_info_html,
76
indexTagline: settings.index_tagline,
77
imprint: settings.imprint,
78
policies: settings.policies,
79
support: settings.support,
80
supportVideoCall: settings.support_video_call,
81
82
// Is important for invite emails, password reset, etc. (e.g., so we can construct a url to our site).
83
// This *can* start with http:// to explicitly use http instead of https, and can end
84
// in something like :3594 to indicate a port.
85
dns: settings.dns,
86
// siteURL is derived from settings.dns and the basePath -- it combines the dns, https://
87
// and the basePath. It never ends in a slash. This is used in practice for
88
// things like invite emails, password reset, etc.
89
siteURL: await siteURL(settings.dns),
90
91
zendesk:
92
settings.zendesk_token &&
93
settings.zendesk_username &&
94
settings.zendesk_uri,
95
96
// obviously only the public key here!
97
stripePublishableKey: settings.stripe_publishable_key,
98
99
// obviously only the public key here too!
100
reCaptchaKey: settings.re_captcha_v3_publishable_key,
101
102
// a sandbox project
103
sandboxProjectId: settings.sandbox_project_id,
104
sandboxProjectsEnabled: settings.sandbox_projects_enabled,
105
106
// true if openai integration is enabled -- this impacts the UI only, and can be
107
// turned on and off independently of whether there is an api key set.
108
openaiEnabled: settings.openai_enabled,
109
// same for google vertex (exposed as gemini), and others
110
googleVertexaiEnabled: settings.google_vertexai_enabled,
111
mistralEnabled: settings.mistral_enabled,
112
anthropicEnabled: settings.anthropic_enabled,
113
xaiEnabled: settings.xai_enabled,
114
ollamaEnabled: settings.ollama_enabled,
115
116
neuralSearchEnabled: settings.neural_search_enabled,
117
118
// if extra Jupyter API functionality for sandboxed ephemeral code execution is available.
119
jupyterApiEnabled: settings.jupyter_api_enabled,
120
121
computeServersEnabled: settings.compute_servers_enabled,
122
cloudFilesystemsEnabled: settings.cloud_filesystems_enabled,
123
124
// GitHub proxy project
125
githubProjectId: settings.github_project_id,
126
127
// public info about SSO strategies
128
strategies,
129
130
verifyEmailAddresses: settings.verify_emails && settings.email_enabled,
131
132
version: {
133
min_project: parseInt(settings.version_min_project),
134
min_compute_server: parseInt(settings.version_min_compute_server),
135
min_browser: parseInt(settings.version_min_browser),
136
recommended_browser: parseInt(settings.version_recommended_browser),
137
compute_server_min_project: parseInt(
138
settings.version_compute_server_min_project,
139
),
140
},
141
};
142
}
143
return fields ? copy_with(cachedCustomize, fields) : cachedCustomize;
144
}
145
146