2023-09-11 10:29:36 +00:00
|
|
|
import Protocol from 'Common/Types/API/Protocol';
|
|
|
|
import ObjectID from 'Common/Types/ObjectID';
|
|
|
|
import Hostname from 'Common/Types/API/Hostname';
|
|
|
|
import { JSONValue } from 'Common/Types/JSON';
|
|
|
|
import URL from 'Common/Types/API/URL';
|
|
|
|
import GlobalConfigService from './Services/GlobalConfigService';
|
|
|
|
import BadDataException from 'Common/Types/Exception/BadDataException';
|
|
|
|
import GlobalConfig from 'Model/Models/GlobalConfig';
|
2023-09-11 14:23:47 +00:00
|
|
|
import { AccountsRoute, DashboardRoute } from 'Common/ServiceRoute';
|
2023-09-11 10:29:36 +00:00
|
|
|
|
|
|
|
export default class DatabaseConfig {
|
|
|
|
public static async getFromGlobalConfig(key: string): Promise<JSONValue> {
|
|
|
|
const globalConfig: GlobalConfig | null =
|
|
|
|
await GlobalConfigService.findOneBy({
|
|
|
|
query: {
|
|
|
|
_id: ObjectID.getZeroObjectID().toString(),
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
isRoot: true,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
[key]: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!globalConfig) {
|
|
|
|
throw new BadDataException('Global Config not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
return globalConfig.getColumnValue(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async getHost(): Promise<Hostname> {
|
2023-09-20 09:58:20 +00:00
|
|
|
return Promise.resolve(
|
|
|
|
new Hostname(process.env['HOST'] || 'localhost')
|
2023-09-11 10:29:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async getHttpProtocol(): Promise<Protocol> {
|
2023-09-29 11:24:45 +00:00
|
|
|
return Promise.resolve((process.env['HTTP_PROTOCOL'] === 'https')
|
2023-09-11 10:29:36 +00:00
|
|
|
? Protocol.HTTPS
|
2023-09-29 11:24:45 +00:00
|
|
|
: Protocol.HTTP);
|
2023-09-11 10:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static async getAccountsUrl(): Promise<URL> {
|
|
|
|
const host: Hostname = await DatabaseConfig.getHost();
|
|
|
|
return new URL(
|
|
|
|
await DatabaseConfig.getHttpProtocol(),
|
|
|
|
host,
|
|
|
|
AccountsRoute
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async getDashboardUrl(): Promise<URL> {
|
|
|
|
const host: Hostname = await DatabaseConfig.getHost();
|
|
|
|
return new URL(
|
|
|
|
await DatabaseConfig.getHttpProtocol(),
|
|
|
|
host,
|
|
|
|
DashboardRoute
|
|
|
|
);
|
|
|
|
}
|
2023-09-11 14:41:04 +00:00
|
|
|
|
|
|
|
public static async shouldDisableSignup(): Promise<boolean> {
|
2023-09-13 07:40:24 +00:00
|
|
|
return (await DatabaseConfig.getFromGlobalConfig(
|
|
|
|
'disableSignup'
|
|
|
|
)) as boolean;
|
2023-09-11 14:41:04 +00:00
|
|
|
}
|
2023-09-11 10:29:36 +00:00
|
|
|
}
|