@basicbenframework/cms 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client/components/Nav/DesktopNav.js +3 -1
- package/lib/client/components/Nav/MobileNav.js +3 -1
- package/lib/client/components/admin/ConfigField.d.ts +34 -0
- package/lib/client/components/admin/ConfigField.js +26 -0
- package/lib/client/hooks/useRegistrationOpen.d.ts +1 -0
- package/lib/client/hooks/useRegistrationOpen.js +31 -0
- package/lib/client/host/index.d.ts +5 -0
- package/lib/client/i18n/locales/es/site.js +40 -0
- package/lib/client/pages/Auth.js +3 -1
- package/lib/client/pages/admin/Health.js +5 -1
- package/lib/client/pages/admin/Settings.js +41 -4
- package/lib/client/styles.css +9 -0
- package/lib/controllers/AuthController.js +2 -1
- package/lib/controllers/EmailVerificationController.js +2 -1
- package/lib/controllers/HealthController.js +15 -5
- package/lib/controllers/MediaController.js +5 -5
- package/lib/controllers/PasskeyController.js +2 -1
- package/lib/controllers/PasswordResetController.js +2 -1
- package/lib/controllers/SettingsController.d.ts +0 -8
- package/lib/controllers/SettingsController.js +72 -20
- package/lib/controllers/TwoFactorController.js +2 -1
- package/lib/controllers/UserController.js +1 -1
- package/lib/features/analytics/controller.js +2 -1
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +1 -1
- package/lib/features/mysendbox/MySendboxSettingsCard.js +15 -5
- package/lib/features/mysendbox/config.d.ts +10 -7
- package/lib/features/mysendbox/config.js +17 -10
- package/lib/features/mysendbox/i18n/es.js +6 -1
- package/lib/helpers/config.d.ts +77 -0
- package/lib/helpers/config.js +158 -0
- package/lib/helpers/export-data.js +1 -1
- package/lib/helpers/health.js +4 -4
- package/lib/helpers/images.js +2 -1
- package/lib/helpers/secrets.d.ts +18 -0
- package/lib/helpers/secrets.js +52 -0
- package/lib/helpers/site-settings.d.ts +6 -0
- package/lib/helpers/site-settings.js +34 -1
- package/lib/helpers/site.d.ts +2 -2
- package/lib/helpers/site.js +4 -3
- package/lib/helpers/storage.d.ts +16 -0
- package/lib/helpers/storage.js +58 -0
- package/lib/hooks.js +11 -0
- package/lib/host/cron.js +5 -0
- package/lib/models/Page.js +1 -1
- package/lib/models/Post.js +1 -1
- package/lib/models/PublicContent.js +2 -1
- package/lib/models/Settings.d.ts +1 -1
- package/lib/models/Settings.js +4 -2
- package/lib/models/User.js +1 -1
- package/package.json +1 -1
package/lib/helpers/health.js
CHANGED
|
@@ -98,12 +98,12 @@ export function evaluateHealth(env, facts, now = new Date()) {
|
|
|
98
98
|
// --- Storage and mail ------------------------------------------------------
|
|
99
99
|
if (facts.storageDriver === 'local') {
|
|
100
100
|
checks.push(serverless
|
|
101
|
-
? check('storage', 'Media storage', 'fail', 'Local disk on a serverless host — uploads cannot work.', 'Configure object storage
|
|
101
|
+
? check('storage', 'Media storage', 'fail', 'Local disk on a serverless host — uploads cannot work.', 'Configure object storage in Settings → Storage, or with S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_ENDPOINT and S3_PUBLIC_URL in the environment (R2, S3, B2, MinIO all work).')
|
|
102
102
|
: check('storage', 'Media storage', production ? 'warn' : 'pass', 'Local disk (public/uploads).', production ? 'Uploads live on this machine only and are not in the JSON backup. Use object storage, or back the directory up separately.' : ''));
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
105
|
const publicUrl = Boolean(env.S3_PUBLIC_URL);
|
|
106
|
-
checks.push(check('storage', 'Media storage', publicUrl ? 'pass' : 'warn', `${facts.storageDriver} (bucket set, access key ${env.S3_ACCESS_KEY_ID ? 'set' : 'missing'}, secret ${env.S3_SECRET_ACCESS_KEY ? 'set' : 'missing'}${publicUrl ? ', public URL set' : ''}).`, publicUrl ? 'Use "Run storage probe" to confirm the credentials can write, read and delete.' : 'Set S3_PUBLIC_URL to the bucket\'s public or CDN address, or media URLs point at the private API host.'));
|
|
106
|
+
checks.push(check('storage', 'Media storage', publicUrl ? 'pass' : 'warn', `${facts.storageDriver} (bucket set, access key ${env.S3_ACCESS_KEY_ID ? 'set' : 'missing'}, secret ${env.S3_SECRET_ACCESS_KEY ? 'set' : 'missing'}${publicUrl ? ', public URL set' : ''}).`, publicUrl ? 'Use "Run storage probe" to confirm the credentials can write, read and delete.' : 'Set the public URL (Settings → Storage, or S3_PUBLIC_URL) to the bucket\'s public or CDN address, or media URLs point at the private API host.'));
|
|
107
107
|
}
|
|
108
108
|
if (facts.mailTransport === 'console') {
|
|
109
109
|
checks.push(check('mail', 'Email', production ? 'warn' : 'pass', 'Console transport — mail is printed to the log, not sent.', production ? 'Set RESEND_API_KEY, or configure SMTP in basicben.config.js. Until then password resets, invitations and verification emails go nowhere.' : ''));
|
|
@@ -116,7 +116,7 @@ export function evaluateHealth(env, facts, now = new Date()) {
|
|
|
116
116
|
const publicUrl = env.SITE_URL || env.APP_URL || '';
|
|
117
117
|
const which = env.SITE_URL ? 'SITE_URL' : 'APP_URL';
|
|
118
118
|
if (!publicUrl) {
|
|
119
|
-
checks.push(check('site_url', 'Site URL', production ? 'fail' : 'warn', 'Neither SITE_URL nor APP_URL is set.', 'Set APP_URL (this app) and SITE_URL (the public front end, if separate). Feeds, the sitemap and email links are built from them.'));
|
|
119
|
+
checks.push(check('site_url', 'Site URL', production ? 'fail' : 'warn', 'Neither SITE_URL nor APP_URL is set.', 'Set APP_URL (this app), and the Site URL in Settings or SITE_URL (the public front end, if separate). Feeds, the sitemap and email links are built from them.'));
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
122
|
let url = null;
|
|
@@ -174,7 +174,7 @@ export function evaluateHealth(env, facts, now = new Date()) {
|
|
|
174
174
|
checks.push(check('cron_secret', 'CRON_SECRET', 'pass', cronSecret ? `Set, ${cronSecret.length} characters.` : 'Not set (a long-running server runs its own interval).'));
|
|
175
175
|
}
|
|
176
176
|
checks.push(production && env.DISABLE_REGISTRATION !== 'true'
|
|
177
|
-
? check('registration', 'Registration', 'warn', 'Open — anyone can create an account.', '
|
|
177
|
+
? check('registration', 'Registration', 'warn', 'Open — anyone can create an account.', 'Close registration in Settings (or set DISABLE_REGISTRATION=true) and invite people from Users instead, unless open sign-up is the intent.')
|
|
178
178
|
: check('registration', 'Registration', 'pass', env.DISABLE_REGISTRATION === 'true' ? 'Disabled; accounts are by invitation.' : 'Open (fine outside production).'));
|
|
179
179
|
checks.push(facts.settings.public_api === 'true'
|
|
180
180
|
? check('public_api', 'Public content API', 'pass', 'On — /api/v1 answers without a token.', 'Intended for a public site. Drafts and private content are never served either way.')
|
package/lib/helpers/images.js
CHANGED
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
* `{url_encoded}` if the service wants it encoded. Unset, images get their
|
|
16
16
|
* dimensions and no srcset, which is still enough to stop layout shift.
|
|
17
17
|
*/
|
|
18
|
+
import { configValue } from "./config.js";
|
|
18
19
|
const WIDTHS = [320, 640, 960, 1280, 1920, 2560];
|
|
19
20
|
export function responsiveImage(url, meta = {}) {
|
|
20
21
|
if (!url)
|
|
21
22
|
return null;
|
|
22
23
|
const width = meta.width ? Number(meta.width) : null;
|
|
23
24
|
const height = meta.height ? Number(meta.height) : null;
|
|
24
|
-
const template =
|
|
25
|
+
const template = configValue('IMAGE_TRANSFORM_URL');
|
|
25
26
|
let srcset = null;
|
|
26
27
|
if (template && width) {
|
|
27
28
|
// Never upscale: offer the steps below the original, then the original.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption for secrets kept in site settings (storage keys, API keys).
|
|
3
|
+
*
|
|
4
|
+
* AES-256-GCM under a key derived from APP_KEY. A stored value reads
|
|
5
|
+
* `enc:v1:<iv>.<tag>.<ciphertext>` (base64url). GCM authenticates as well as
|
|
6
|
+
* encrypts, so a value edited in the database, or written under another
|
|
7
|
+
* APP_KEY, fails to decrypt rather than decrypting to garbage.
|
|
8
|
+
*
|
|
9
|
+
* Changing APP_KEY therefore loses these settings: `decryptSecret` returns
|
|
10
|
+
* null, the Configuration screen shows them as unreadable, and they have to be
|
|
11
|
+
* entered again. That is the trade for not keeping a second key.
|
|
12
|
+
*
|
|
13
|
+
* Imports nothing outside `node:` so the tests load it directly.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isEncrypted(value: unknown): boolean;
|
|
16
|
+
export declare function encryptSecret(plain: string, appKey?: string): string;
|
|
17
|
+
/** The plain value, or null when it cannot be read (another APP_KEY, edited, not encrypted). */
|
|
18
|
+
export declare function decryptSecret(stored: string | null | undefined, appKey?: string | undefined): string | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption for secrets kept in site settings (storage keys, API keys).
|
|
3
|
+
*
|
|
4
|
+
* AES-256-GCM under a key derived from APP_KEY. A stored value reads
|
|
5
|
+
* `enc:v1:<iv>.<tag>.<ciphertext>` (base64url). GCM authenticates as well as
|
|
6
|
+
* encrypts, so a value edited in the database, or written under another
|
|
7
|
+
* APP_KEY, fails to decrypt rather than decrypting to garbage.
|
|
8
|
+
*
|
|
9
|
+
* Changing APP_KEY therefore loses these settings: `decryptSecret` returns
|
|
10
|
+
* null, the Configuration screen shows them as unreadable, and they have to be
|
|
11
|
+
* entered again. That is the trade for not keeping a second key.
|
|
12
|
+
*
|
|
13
|
+
* Imports nothing outside `node:` so the tests load it directly.
|
|
14
|
+
*/
|
|
15
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'node:crypto';
|
|
16
|
+
const PREFIX = 'enc:v1:';
|
|
17
|
+
function key(appKey) {
|
|
18
|
+
// A label, so this key is never the same bytes as anything else APP_KEY signs.
|
|
19
|
+
return createHash('sha256').update(`basicben-cms settings v1\0${appKey}`).digest();
|
|
20
|
+
}
|
|
21
|
+
function appKeyOrThrow(appKey = process.env.APP_KEY) {
|
|
22
|
+
if (!appKey)
|
|
23
|
+
throw new Error('APP_KEY is required to store a secret setting');
|
|
24
|
+
return appKey;
|
|
25
|
+
}
|
|
26
|
+
export function isEncrypted(value) {
|
|
27
|
+
return typeof value === 'string' && value.startsWith(PREFIX);
|
|
28
|
+
}
|
|
29
|
+
export function encryptSecret(plain, appKey) {
|
|
30
|
+
const iv = randomBytes(12);
|
|
31
|
+
const cipher = createCipheriv('aes-256-gcm', key(appKeyOrThrow(appKey)), iv);
|
|
32
|
+
const body = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()]);
|
|
33
|
+
const tag = cipher.getAuthTag();
|
|
34
|
+
return PREFIX + [iv, tag, body].map((part) => part.toString('base64url')).join('.');
|
|
35
|
+
}
|
|
36
|
+
/** The plain value, or null when it cannot be read (another APP_KEY, edited, not encrypted). */
|
|
37
|
+
export function decryptSecret(stored, appKey = process.env.APP_KEY) {
|
|
38
|
+
if (!stored || !appKey || !isEncrypted(stored))
|
|
39
|
+
return null;
|
|
40
|
+
const parts = stored.slice(PREFIX.length).split('.');
|
|
41
|
+
if (parts.length !== 3)
|
|
42
|
+
return null;
|
|
43
|
+
try {
|
|
44
|
+
const [iv, tag, body] = parts.map((part) => Buffer.from(part, 'base64url'));
|
|
45
|
+
const decipher = createDecipheriv('aes-256-gcm', key(appKey), iv);
|
|
46
|
+
decipher.setAuthTag(tag);
|
|
47
|
+
return Buffer.concat([decipher.update(body), decipher.final()]).toString('utf8');
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -23,6 +23,11 @@ export type Check = (value: unknown) => {
|
|
|
23
23
|
export interface SettingDefinition {
|
|
24
24
|
group: SettingGroup;
|
|
25
25
|
check: Check;
|
|
26
|
+
/**
|
|
27
|
+
* Stored encrypted, never sent back to the admin (see helpers/config.ts).
|
|
28
|
+
* A blank value on save keeps the stored one; DELETE clears it.
|
|
29
|
+
*/
|
|
30
|
+
secret?: boolean;
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* An IANA time zone name, such as `Europe/London` or `UTC`.
|
|
@@ -71,6 +76,7 @@ export declare const checks: {
|
|
|
71
76
|
emailOrBlank: Check;
|
|
72
77
|
httpUrlOrBlank: Check;
|
|
73
78
|
};
|
|
79
|
+
export declare function isSecretDefinition(key: string): boolean;
|
|
74
80
|
/**
|
|
75
81
|
* Add a feature's settings to the allowlist. A key core or another feature
|
|
76
82
|
* already defines is refused: two owners for one setting is a bug to catch at
|
|
@@ -149,6 +149,24 @@ const httpUrlOrBlank = (value) => {
|
|
|
149
149
|
}
|
|
150
150
|
return { value: value.trim() };
|
|
151
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* An image transform URL template: blank, or a template naming the image with
|
|
154
|
+
* {url} or {url_encoded} and the size with {width}. It starts with http(s)://
|
|
155
|
+
* or with {url} (Bunny's `{url}?width={width}`). See helpers/images.ts.
|
|
156
|
+
*/
|
|
157
|
+
const imageTransformTemplate = (value) => {
|
|
158
|
+
if (value === null || value === undefined || value === '')
|
|
159
|
+
return { value: '' };
|
|
160
|
+
if (typeof value !== 'string' || value.length > MAX_URL_LENGTH)
|
|
161
|
+
return { error: 'Must be a URL template' };
|
|
162
|
+
const template = value.trim();
|
|
163
|
+
if (!/^(https?:\/\/|\{url\})/i.test(template))
|
|
164
|
+
return { error: 'Must start with http://, https:// or {url}' };
|
|
165
|
+
if (!/\{url(_encoded)?\}/.test(template) || !template.includes('{width}')) {
|
|
166
|
+
return { error: 'Must contain {url} or {url_encoded}, and {width}' };
|
|
167
|
+
}
|
|
168
|
+
return { value: template };
|
|
169
|
+
};
|
|
152
170
|
/**
|
|
153
171
|
* The known settings.
|
|
154
172
|
*
|
|
@@ -178,7 +196,19 @@ export const SETTINGS = {
|
|
|
178
196
|
// dictionary for it (src/client/i18n).
|
|
179
197
|
admin_locale: { group: 'locale', check: locale },
|
|
180
198
|
code_injection_head: { group: 'code_injection', check: text(100_000) },
|
|
181
|
-
code_injection_foot: { group: 'code_injection', check: text(100_000) }
|
|
199
|
+
code_injection_foot: { group: 'code_injection', check: text(100_000) },
|
|
200
|
+
// Configuration the environment can also set, and then wins: see
|
|
201
|
+
// helpers/config.ts. The site URL is where feeds and the sitemap link.
|
|
202
|
+
site_url: { group: 'general', check: httpUrlOrBlank },
|
|
203
|
+
disable_registration: { group: 'general', check: flag },
|
|
204
|
+
image_transform_url: { group: 'media', check: imageTransformTemplate },
|
|
205
|
+
// Object storage for the media library, as the S3_* variables would set it.
|
|
206
|
+
storage_bucket: { group: 'storage', check: text(255) },
|
|
207
|
+
storage_endpoint: { group: 'storage', check: httpUrlOrBlank },
|
|
208
|
+
storage_region: { group: 'storage', check: text(64) },
|
|
209
|
+
storage_public_url: { group: 'storage', check: httpUrlOrBlank },
|
|
210
|
+
storage_access_key_id: { group: 'storage', check: text(256), secret: true },
|
|
211
|
+
storage_secret_access_key: { group: 'storage', check: text(256), secret: true }
|
|
182
212
|
};
|
|
183
213
|
/**
|
|
184
214
|
* The validators, for a feature defining its own settings
|
|
@@ -186,6 +216,9 @@ export const SETTINGS = {
|
|
|
186
216
|
* checked exactly as strictly.
|
|
187
217
|
*/
|
|
188
218
|
export const checks = { text, flag, integer, oneOf, imageUrl, urlList, timeZone, locale, emailOrBlank, httpUrlOrBlank };
|
|
219
|
+
export function isSecretDefinition(key) {
|
|
220
|
+
return Boolean(SETTINGS[key]?.secret);
|
|
221
|
+
}
|
|
189
222
|
/**
|
|
190
223
|
* Add a feature's settings to the allowlist. A key core or another feature
|
|
191
224
|
* already defines is refused: two owners for one setting is a bug to catch at
|
package/lib/helpers/site.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* client sent, and these responses are cached — one request with a forged Host
|
|
6
6
|
* would poison every reader's feed with links to somewhere else.
|
|
7
7
|
*
|
|
8
|
-
* SITE_URL
|
|
9
|
-
* front end); APP_URL otherwise. The request is consulted only outside
|
|
8
|
+
* SITE_URL (or the Site URL setting, see helpers/config.ts) is the public site
|
|
9
|
+
* when it is separate from this app (a headless front end); APP_URL otherwise. The request is consulted only outside
|
|
10
10
|
* production, so a local checkout works without either.
|
|
11
11
|
*/
|
|
12
12
|
export declare function siteUrl(req?: {
|
package/lib/helpers/site.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configValue } from "./config.js";
|
|
1
2
|
/**
|
|
2
3
|
* The public site's origin, for links a feed, sitemap or robots.txt hands out.
|
|
3
4
|
*
|
|
@@ -5,12 +6,12 @@
|
|
|
5
6
|
* client sent, and these responses are cached — one request with a forged Host
|
|
6
7
|
* would poison every reader's feed with links to somewhere else.
|
|
7
8
|
*
|
|
8
|
-
* SITE_URL
|
|
9
|
-
* front end); APP_URL otherwise. The request is consulted only outside
|
|
9
|
+
* SITE_URL (or the Site URL setting, see helpers/config.ts) is the public site
|
|
10
|
+
* when it is separate from this app (a headless front end); APP_URL otherwise. The request is consulted only outside
|
|
10
11
|
* production, so a local checkout works without either.
|
|
11
12
|
*/
|
|
12
13
|
export function siteUrl(req) {
|
|
13
|
-
const configured =
|
|
14
|
+
const configured = configValue('SITE_URL') || process.env.APP_URL;
|
|
14
15
|
if (configured)
|
|
15
16
|
return configured.replace(/\/+$/, '');
|
|
16
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The media library's storage: what the CMS calls instead of core's
|
|
3
|
+
* `getStorage()`.
|
|
4
|
+
*
|
|
5
|
+
* - S3_BUCKET set: core's storage, configured from basicben.config.js and the
|
|
6
|
+
* S3_* variables, exactly as before.
|
|
7
|
+
* - Otherwise, a bucket in the storage settings (helpers/config.ts): an S3
|
|
8
|
+
* adapter built from them, reusing the site config's other options such as
|
|
9
|
+
* `maxSize`. Rebuilt when the settings change.
|
|
10
|
+
* - Neither: core's storage again, which is the local driver.
|
|
11
|
+
*/
|
|
12
|
+
/** The storage settings in use, or null when they are not what configures storage. */
|
|
13
|
+
export declare function settingsStorageConfig(): Record<string, string> | null;
|
|
14
|
+
export declare function getStorage(): Promise<any>;
|
|
15
|
+
/** Which configures storage right now, for the health screen. */
|
|
16
|
+
export declare function storageSource(): 'env' | 'settings' | 'default';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The media library's storage: what the CMS calls instead of core's
|
|
3
|
+
* `getStorage()`.
|
|
4
|
+
*
|
|
5
|
+
* - S3_BUCKET set: core's storage, configured from basicben.config.js and the
|
|
6
|
+
* S3_* variables, exactly as before.
|
|
7
|
+
* - Otherwise, a bucket in the storage settings (helpers/config.ts): an S3
|
|
8
|
+
* adapter built from them, reusing the site config's other options such as
|
|
9
|
+
* `maxSize`. Rebuilt when the settings change.
|
|
10
|
+
* - Neither: core's storage again, which is the local driver.
|
|
11
|
+
*/
|
|
12
|
+
import { getStorage as coreStorage, createStorage } from '@basicbenframework/core/storage';
|
|
13
|
+
import { loadConfig } from '@basicbenframework/core/server';
|
|
14
|
+
import { configValue } from "./config.js";
|
|
15
|
+
let cached = null;
|
|
16
|
+
/** The storage settings in use, or null when they are not what configures storage. */
|
|
17
|
+
export function settingsStorageConfig() {
|
|
18
|
+
if (process.env.S3_BUCKET?.trim())
|
|
19
|
+
return null;
|
|
20
|
+
const bucket = configValue('S3_BUCKET');
|
|
21
|
+
const accessKeyId = configValue('S3_ACCESS_KEY_ID');
|
|
22
|
+
const secretAccessKey = configValue('S3_SECRET_ACCESS_KEY');
|
|
23
|
+
if (!bucket || !accessKeyId || !secretAccessKey)
|
|
24
|
+
return null;
|
|
25
|
+
return {
|
|
26
|
+
bucket,
|
|
27
|
+
accessKeyId,
|
|
28
|
+
secretAccessKey,
|
|
29
|
+
endpoint: configValue('S3_ENDPOINT'),
|
|
30
|
+
region: configValue('S3_REGION') || 'auto',
|
|
31
|
+
publicUrl: configValue('S3_PUBLIC_URL')
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export async function getStorage() {
|
|
35
|
+
const fromSettings = settingsStorageConfig();
|
|
36
|
+
if (!fromSettings)
|
|
37
|
+
return coreStorage();
|
|
38
|
+
const fingerprint = JSON.stringify(fromSettings);
|
|
39
|
+
if (cached?.fingerprint === fingerprint)
|
|
40
|
+
return cached.storage;
|
|
41
|
+
const site = (await loadConfig())?.storage || {};
|
|
42
|
+
// Only the options that are not about which bucket: the site config may name
|
|
43
|
+
// the local driver or an upload path that has nothing to do with this one.
|
|
44
|
+
const storage = await createStorage({
|
|
45
|
+
...(site.maxSize !== undefined ? { maxSize: site.maxSize } : {}),
|
|
46
|
+
...(site.allowedTypes ? { allowedTypes: site.allowedTypes } : {}),
|
|
47
|
+
driver: 's3',
|
|
48
|
+
...Object.fromEntries(Object.entries(fromSettings).filter(([, value]) => value !== ''))
|
|
49
|
+
});
|
|
50
|
+
cached = { fingerprint, storage };
|
|
51
|
+
return storage;
|
|
52
|
+
}
|
|
53
|
+
/** Which configures storage right now, for the health screen. */
|
|
54
|
+
export function storageSource() {
|
|
55
|
+
if (process.env.S3_BUCKET?.trim())
|
|
56
|
+
return 'env';
|
|
57
|
+
return settingsStorageConfig() ? 'settings' : 'default';
|
|
58
|
+
}
|
package/lib/hooks.js
CHANGED
|
@@ -18,6 +18,7 @@ import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
|
18
18
|
import { deliver } from '@basicbenframework/core/webhooks';
|
|
19
19
|
import { Settings } from "./models/Settings.js";
|
|
20
20
|
import { startCronInterval } from "./host/cron.js";
|
|
21
|
+
import { refreshConfig } from "./helpers/config.js";
|
|
21
22
|
/**
|
|
22
23
|
* Trim titles before a post is written.
|
|
23
24
|
*
|
|
@@ -120,3 +121,13 @@ hooks.on(HOOKS.REQUEST_BEFORE, async (context) => {
|
|
|
120
121
|
}
|
|
121
122
|
return context;
|
|
122
123
|
}, { name: 'query:single-values', priority: 0 });
|
|
124
|
+
/**
|
|
125
|
+
* Configuration from settings (storage, site URL, mail keys: see
|
|
126
|
+
* helpers/config.ts), reloaded at most every 30 seconds, before any handler
|
|
127
|
+
* reads it. A failed read keeps the previous values rather than failing the
|
|
128
|
+
* request.
|
|
129
|
+
*/
|
|
130
|
+
hooks.on(HOOKS.REQUEST_BEFORE, async (context) => {
|
|
131
|
+
await refreshConfig();
|
|
132
|
+
return context;
|
|
133
|
+
}, { name: 'config:refresh', priority: 0 });
|
package/lib/host/cron.js
CHANGED
|
@@ -15,6 +15,7 @@ import { timingSafeEqual } from 'node:crypto';
|
|
|
15
15
|
import { getDb } from '@basicbenframework/core/db';
|
|
16
16
|
import { recordHeartbeat, readHeartbeats } from "../helpers/heartbeat.js";
|
|
17
17
|
import { cronTaskList } from "./index.js";
|
|
18
|
+
import { refreshConfig } from "../helpers/config.js";
|
|
18
19
|
const short = (err) => (err instanceof Error ? err.message : String(err)).slice(0, 200);
|
|
19
20
|
/**
|
|
20
21
|
* Run the tasks that are due, or with `only`, exactly those tasks whether due
|
|
@@ -25,6 +26,10 @@ export async function runCron(options = {}) {
|
|
|
25
26
|
const started = now();
|
|
26
27
|
const budget = options.budgetMs ?? 25_000;
|
|
27
28
|
const db = options.db ?? (await getDb());
|
|
29
|
+
// The in-process tick runs outside any request, so nothing else has loaded
|
|
30
|
+
// the configuration from settings (MySendbox's key, for one).
|
|
31
|
+
if (!options.db)
|
|
32
|
+
await refreshConfig();
|
|
28
33
|
const beats = await readHeartbeats(db);
|
|
29
34
|
const result = { ran: {}, skipped: [], failed: {} };
|
|
30
35
|
const tasks = (options.tasks ?? cronTaskList()).filter((task) => !options.only || options.only.includes(task.name));
|
package/lib/models/Page.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getDb } from '@basicbenframework/core/db';
|
|
|
3
3
|
import { insertRow } from "../helpers/insert-row.js";
|
|
4
4
|
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
5
5
|
import { renderContent } from '@basicbenframework/core/content';
|
|
6
|
-
import { getStorage } from
|
|
6
|
+
import { getStorage } from "../helpers/storage.js";
|
|
7
7
|
import { uniqueSlug } from "./derive.js";
|
|
8
8
|
import { livePage } from "./visibility.js";
|
|
9
9
|
/**
|
package/lib/models/Post.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getDb } from '@basicbenframework/core/db';
|
|
|
2
2
|
import { insertRow } from "../helpers/insert-row.js";
|
|
3
3
|
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
4
4
|
import { renderContent } from '@basicbenframework/core/content';
|
|
5
|
-
import { getStorage } from
|
|
5
|
+
import { getStorage } from "../helpers/storage.js";
|
|
6
6
|
import { derivedFields } from "./derive.js";
|
|
7
7
|
import { livePost } from "./visibility.js";
|
|
8
8
|
/**
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* email addresses is a data-protection incident rather than a feature.
|
|
13
13
|
*/
|
|
14
14
|
import { getDb } from '@basicbenframework/core/db';
|
|
15
|
-
import {
|
|
15
|
+
import { absoluteUrl } from '@basicbenframework/core/storage';
|
|
16
|
+
import { getStorage } from "../helpers/storage.js";
|
|
16
17
|
import { livePost, livePage, parseStoredTimestamp } from "./visibility.js";
|
|
17
18
|
import { responsiveImage } from "../helpers/images.js";
|
|
18
19
|
import { siteUrl } from "../helpers/site.js";
|
package/lib/models/Settings.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Settings as SettingsType } from '../types/index.ts';
|
|
|
3
3
|
export interface PublicSiteInfo {
|
|
4
4
|
name: string;
|
|
5
5
|
description: string;
|
|
6
|
-
/** The public site's origin,
|
|
6
|
+
/** The public site's origin: SITE_URL, else the Site URL setting, else APP_URL. */
|
|
7
7
|
url: string;
|
|
8
8
|
/** Absolute URL of the logo, or null. */
|
|
9
9
|
logo_url: string | null;
|
package/lib/models/Settings.js
CHANGED
|
@@ -2,6 +2,7 @@ import { getDb } from '@basicbenframework/core/db';
|
|
|
2
2
|
import { absoluteUrl } from '@basicbenframework/core/storage';
|
|
3
3
|
import { SITE_DEFAULTS } from "../helpers/site-settings.js";
|
|
4
4
|
import { siteUrl } from "../helpers/site.js";
|
|
5
|
+
import { configValue } from "../helpers/config.js";
|
|
5
6
|
export const Settings = {
|
|
6
7
|
async all() {
|
|
7
8
|
const db = await getDb();
|
|
@@ -57,8 +58,9 @@ export const Settings = {
|
|
|
57
58
|
}, {});
|
|
58
59
|
},
|
|
59
60
|
// Convenience methods for common settings
|
|
61
|
+
// SITE_NAME, when set, wins over the setting: see helpers/config.ts.
|
|
60
62
|
async getSiteName() {
|
|
61
|
-
return (await this.get('site_name')) || 'My BasicBen Blog';
|
|
63
|
+
return configValue('SITE_NAME') || (await this.get('site_name')) || 'My BasicBen Blog';
|
|
62
64
|
},
|
|
63
65
|
async getSiteDescription() {
|
|
64
66
|
return (await this.get('site_description')) || '';
|
|
@@ -111,7 +113,7 @@ export const Settings = {
|
|
|
111
113
|
const value = (key) => rows.find(row => row.key === key)?.value || '';
|
|
112
114
|
const image = (key) => (value(key) ? absoluteUrl(value(key)) : null);
|
|
113
115
|
return {
|
|
114
|
-
name: value('site_name') || 'My BasicBen Blog',
|
|
116
|
+
name: configValue('SITE_NAME') || value('site_name') || 'My BasicBen Blog',
|
|
115
117
|
description: value('site_description'),
|
|
116
118
|
url: siteUrl(),
|
|
117
119
|
logo_url: image('site_logo'),
|
package/lib/models/User.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getDb, query } from '@basicbenframework/core/db';
|
|
2
2
|
import { DEFAULT_ROLE, capabilitiesFor } from '@basicbenframework/core/auth/permissions';
|
|
3
|
-
import { getStorage } from
|
|
3
|
+
import { getStorage } from "../helpers/storage.js";
|
|
4
4
|
import { uniqueSlug } from "./derive.js";
|
|
5
5
|
// Columns update() is allowed to write. Without this, passing req.body straight
|
|
6
6
|
// through would let a caller set any column, including role.
|