CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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