This refactors the data handlers into a more standard/understood model-like architecture, to prepare for a new, more robust config system. It also fixes a problem with creating new Notes and uploading new Photos via the web interface (related to #58). Finally, it speeds up docker builds by sending in less files, which aren't necessary or will be built anyway. This is all in preparation to allow building #13 more robustly.
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import 'std/dotenv/load.ts';
|
|
|
|
import { UserModel } from './models/user.ts';
|
|
|
|
export async function isSignupAllowed() {
|
|
const areSignupsAllowed = Deno.env.get('CONFIG_ALLOW_SIGNUPS') === 'true';
|
|
|
|
const areThereAdmins = await UserModel.isThereAnAdmin();
|
|
|
|
if (areSignupsAllowed || !areThereAdmins) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
export function isAppEnabled(app: 'news' | 'notes' | 'photos' | 'expenses') {
|
|
const enabledApps = (Deno.env.get('CONFIG_ENABLED_APPS') || '').split(',') as typeof app[];
|
|
|
|
return enabledApps.includes(app);
|
|
}
|
|
|
|
export function isCookieDomainAllowed(domain: string) {
|
|
const allowedDomains = (Deno.env.get('CONFIG_ALLOWED_COOKIE_DOMAINS') || '').split(',') as typeof domain[];
|
|
|
|
if (allowedDomains.length === 0) {
|
|
return true;
|
|
}
|
|
|
|
return allowedDomains.includes(domain);
|
|
}
|
|
|
|
export function isCookieDomainSecurityDisabled() {
|
|
const isCookieDomainSecurityDisabled = Deno.env.get('CONFIG_SKIP_COOKIE_DOMAIN_SECURITY') === 'true';
|
|
|
|
return isCookieDomainSecurityDisabled;
|
|
}
|
|
|
|
export function isEmailEnabled() {
|
|
const areEmailsAllowed = Deno.env.get('CONFIG_ENABLE_EMAILS') === 'true';
|
|
|
|
return areEmailsAllowed;
|
|
}
|
|
|
|
export function isForeverSignupEnabled() {
|
|
const areForeverAccountsEnabled = Deno.env.get('CONFIG_ENABLE_FOREVER_SIGNUP') === 'true';
|
|
|
|
return areForeverAccountsEnabled;
|
|
}
|
|
|
|
export function getFilesRootPath() {
|
|
const configRootPath = Deno.env.get('CONFIG_FILES_ROOT_PATH') || '';
|
|
|
|
const filesRootPath = `${Deno.cwd()}/${configRootPath}`;
|
|
|
|
return filesRootPath;
|
|
}
|