mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
bf8cf6254f
* feat: typesense driver (EE) - WIP * feat: typesense driver (EE) - WIP * feat: typesense * sync * fix
128 lines
2.8 KiB
TypeScript
128 lines
2.8 KiB
TypeScript
import {
|
|
IsIn,
|
|
IsNotEmpty,
|
|
IsNotIn,
|
|
IsOptional,
|
|
IsString,
|
|
IsUrl,
|
|
MinLength,
|
|
ValidateIf,
|
|
validateSync,
|
|
} from 'class-validator';
|
|
import { plainToInstance } from 'class-transformer';
|
|
import { IsISO6391 } from '../../common/validator/is-iso6391';
|
|
|
|
export class EnvironmentVariables {
|
|
@IsNotEmpty()
|
|
@IsUrl(
|
|
{
|
|
protocols: ['postgres', 'postgresql'],
|
|
require_tld: false,
|
|
allow_underscores: true,
|
|
},
|
|
{ message: 'DATABASE_URL must be a valid postgres connection string' },
|
|
)
|
|
DATABASE_URL: string;
|
|
|
|
@IsNotEmpty()
|
|
@IsUrl(
|
|
{
|
|
protocols: ['redis', 'rediss'],
|
|
require_tld: false,
|
|
allow_underscores: true,
|
|
},
|
|
{ message: 'REDIS_URL must be a valid redis connection string' },
|
|
)
|
|
REDIS_URL: string;
|
|
|
|
@IsOptional()
|
|
@IsUrl({ protocols: ['http', 'https'], require_tld: false })
|
|
APP_URL: string;
|
|
|
|
@IsNotEmpty()
|
|
@MinLength(32)
|
|
@IsNotIn(['REPLACE_WITH_LONG_SECRET'])
|
|
APP_SECRET: string;
|
|
|
|
@IsOptional()
|
|
@IsIn(['smtp', 'postmark'])
|
|
MAIL_DRIVER: string;
|
|
|
|
@IsOptional()
|
|
@IsIn(['local', 's3'])
|
|
STORAGE_DRIVER: string;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((obj) => obj.COLLAB_URL != '' && obj.COLLAB_URL != null)
|
|
@IsUrl({ protocols: ['http', 'https'], require_tld: false })
|
|
COLLAB_URL: string;
|
|
|
|
@IsOptional()
|
|
CLOUD: boolean;
|
|
|
|
@IsOptional()
|
|
@IsUrl(
|
|
{ protocols: [], require_tld: true },
|
|
{
|
|
message:
|
|
'SUBDOMAIN_HOST must be a valid FQDN domain without the http protocol. e.g example.com',
|
|
},
|
|
)
|
|
@ValidateIf((obj) => obj.CLOUD === 'true'.toLowerCase())
|
|
SUBDOMAIN_HOST: string;
|
|
|
|
@IsOptional()
|
|
@IsIn(['database', 'typesense'])
|
|
@IsString()
|
|
SEARCH_DRIVER: string;
|
|
|
|
@IsOptional()
|
|
@IsUrl(
|
|
{
|
|
protocols: ['http', 'https'],
|
|
require_tld: false,
|
|
allow_underscores: true,
|
|
},
|
|
{
|
|
message:
|
|
'TYPESENSE_URL must be a valid typesense url e.g http://localhost:8108',
|
|
},
|
|
)
|
|
@ValidateIf((obj) => obj.SEARCH_DRIVER === 'typesense')
|
|
TYPESENSE_URL: string;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((obj) => obj.SEARCH_DRIVER === 'typesense')
|
|
@IsString()
|
|
TYPESENSE_API_KEY: string;
|
|
|
|
@IsOptional()
|
|
@ValidateIf((obj) => obj.SEARCH_DRIVER === 'typesense')
|
|
@IsISO6391()
|
|
@IsString()
|
|
TYPESENSE_LOCALE: string;
|
|
}
|
|
|
|
export function validate(config: Record<string, any>) {
|
|
const validatedConfig = plainToInstance(EnvironmentVariables, config);
|
|
|
|
const errors = validateSync(validatedConfig);
|
|
|
|
if (errors.length > 0) {
|
|
console.error(
|
|
'The Environment variables has failed the following validations:',
|
|
);
|
|
|
|
errors.map((error) => {
|
|
console.error(JSON.stringify(error.constraints));
|
|
});
|
|
|
|
console.error(
|
|
'Please fix the environment variables and try again. Exiting program...',
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
return validatedConfig;
|
|
}
|