mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
This implements a huge change, where Fresh is removed as a framework and serving files, allowing more control over importing, bundling, and serving files and components. The biggest challenge was to continue making sure that there weren't too many places to look into for import versions, and `PasswordlessPasskeyLogin.tsx` became a prototype in migrating a component to fully SSR, no need for frontend parsing (via Babel) or bundling (via a custom-script, downloading frontend dependencies from esm.sh). Still, there are too many components to migrate like that, and it's all working, so I likely won't even attempt it unless there's some bug, new feature, or security vulnerability to address that warrants a rewrite of those. This also updates all dependencies (except `@libs/xml` because that still causes some breaking in DAV endpoints), including Deno! All other advantages can be seen in the related issues, and the breaking change this (v4.0.0) introduces is related simply to `config.email.tlsMode` (which had a deprecation warning throughout v3), and because, while I tested many things exhaustively, it's not impossible something broke that I didn't see. Closes #141 Closes #132
223 lines
5.4 KiB
TypeScript
223 lines
5.4 KiB
TypeScript
import { isAbsolute, join } from '@std/path';
|
|
import { UserModel } from './models/user.ts';
|
|
import { Config, OptionalApp } from './types.ts';
|
|
|
|
export class AppConfig {
|
|
private static config: Config;
|
|
|
|
private static getDefaultConfig(): Config {
|
|
return {
|
|
auth: {
|
|
baseUrl: 'http://localhost:8000',
|
|
allowSignups: false,
|
|
enableEmailVerification: false,
|
|
enableForeverSignup: true,
|
|
enableMultiFactor: false,
|
|
allowedCookieDomains: [],
|
|
skipCookieDomainSecurity: false,
|
|
enableSingleSignOn: false,
|
|
singleSignOnUrl: '',
|
|
singleSignOnEmailAttribute: 'email',
|
|
singleSignOnScopes: ['openid', 'email'],
|
|
},
|
|
files: {
|
|
rootPath: 'data-files',
|
|
allowPublicSharing: false,
|
|
allowDirectoryDownloads: false,
|
|
},
|
|
core: {
|
|
enabledApps: ['dashboard', 'files', 'news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'],
|
|
},
|
|
visuals: {
|
|
title: '',
|
|
description: '',
|
|
helpEmail: 'help@bewcloud.com',
|
|
},
|
|
email: {
|
|
from: 'help@bewcloud.com',
|
|
host: 'localhost',
|
|
port: 465,
|
|
tlsMode: 'auto',
|
|
tlsVerify: true,
|
|
},
|
|
contacts: {
|
|
enableCardDavServer: true,
|
|
cardDavUrl: 'http://radicale:5232',
|
|
},
|
|
calendar: {
|
|
enableCalDavServer: true,
|
|
calDavUrl: 'http://radicale:5232',
|
|
},
|
|
};
|
|
}
|
|
|
|
private static async loadConfig(): Promise<void> {
|
|
if (this.config) {
|
|
return;
|
|
}
|
|
|
|
const initialConfig = this.getDefaultConfig();
|
|
|
|
const config: Config = {
|
|
...initialConfig,
|
|
};
|
|
|
|
try {
|
|
const configFromFile: Config = (await import(`${Deno.cwd()}/bewcloud.config.ts`)).default;
|
|
|
|
this.config = {
|
|
...config,
|
|
auth: {
|
|
...config.auth,
|
|
...configFromFile.auth,
|
|
},
|
|
files: {
|
|
...config.files,
|
|
...configFromFile.files,
|
|
},
|
|
core: {
|
|
...config.core,
|
|
...configFromFile.core,
|
|
},
|
|
visuals: {
|
|
...config.visuals,
|
|
...configFromFile.visuals,
|
|
},
|
|
email: {
|
|
...config.email,
|
|
...configFromFile.email,
|
|
},
|
|
contacts: {
|
|
...config.contacts,
|
|
...configFromFile.contacts,
|
|
},
|
|
calendar: {
|
|
...config.calendar,
|
|
...configFromFile.calendar,
|
|
},
|
|
};
|
|
|
|
console.info('\nConfig loaded from bewcloud.config.ts', JSON.stringify(this.config, null, 2), '\n');
|
|
|
|
if (this.config.core.enabledApps.length === 0) {
|
|
throw new Error('At least one app must be enabled. Please check the config.core.enabledApps array.');
|
|
}
|
|
|
|
return;
|
|
} catch (error) {
|
|
console.error('Error loading config from bewcloud.config.ts. Using default config instead.', error);
|
|
}
|
|
|
|
this.config = config;
|
|
}
|
|
|
|
static async getConfig(): Promise<Config> {
|
|
await this.loadConfig();
|
|
|
|
return this.config;
|
|
}
|
|
|
|
static async isSignupAllowed(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
const areSignupsAllowed = this.config.auth.allowSignups;
|
|
|
|
const areThereAdmins = await UserModel.isThereAnAdmin();
|
|
|
|
if (areSignupsAllowed || !areThereAdmins) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static async isAppEnabled(app: OptionalApp): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
const enabledApps = this.config.core.enabledApps;
|
|
|
|
return enabledApps.includes(app);
|
|
}
|
|
|
|
static async isCookieDomainAllowed(domain: string): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
const allowedDomains = this.config.auth.allowedCookieDomains;
|
|
|
|
if (allowedDomains.length === 0) {
|
|
return true;
|
|
}
|
|
|
|
return allowedDomains.includes(domain);
|
|
}
|
|
|
|
static async isCookieDomainSecurityDisabled(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.auth.skipCookieDomainSecurity;
|
|
}
|
|
|
|
static async isEmailVerificationEnabled(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.auth.enableEmailVerification;
|
|
}
|
|
|
|
static async isForeverSignupEnabled(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.auth.enableForeverSignup;
|
|
}
|
|
|
|
static async isMultiFactorAuthEnabled(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.auth.enableMultiFactor;
|
|
}
|
|
|
|
static async isSingleSignOnEnabled(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.auth.enableSingleSignOn;
|
|
}
|
|
|
|
static async isPublicFileSharingAllowed(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.files.allowPublicSharing;
|
|
}
|
|
|
|
static async areDirectoryDownloadsAllowed(): Promise<boolean> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.files.allowDirectoryDownloads;
|
|
}
|
|
|
|
static async getFilesRootPath(): Promise<string> {
|
|
await this.loadConfig();
|
|
|
|
if (isAbsolute(this.config.files.rootPath)) {
|
|
return this.config.files.rootPath;
|
|
} else {
|
|
return join(Deno.cwd(), this.config.files.rootPath);
|
|
}
|
|
}
|
|
|
|
static async getEmailConfig(): Promise<Config['email']> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.email;
|
|
}
|
|
|
|
static async getContactsConfig(): Promise<Config['contacts']> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.contacts;
|
|
}
|
|
|
|
static async getCalendarConfig(): Promise<Config['calendar']> {
|
|
await this.loadConfig();
|
|
|
|
return this.config.calendar;
|
|
}
|
|
}
|