2024-06-14 11:09:53 +00:00
|
|
|
import DataMigrationBase from "./DataMigrationBase";
|
|
|
|
import Hostname from "Common/Types/API/Hostname";
|
|
|
|
import ObjectID from "Common/Types/ObjectID";
|
|
|
|
import Port from "Common/Types/Port";
|
2024-08-07 21:50:32 +00:00
|
|
|
import GlobalConfigService from "Common/Server/Services/GlobalConfigService";
|
2024-08-05 19:00:31 +00:00
|
|
|
import { EmailServerType } from "Common/Models/DatabaseModels/GlobalConfig";
|
2024-01-11 10:49:55 +00:00
|
|
|
|
|
|
|
export default class UpdateGlobalConfigFromEnv extends DataMigrationBase {
|
2024-06-14 11:09:53 +00:00
|
|
|
public constructor() {
|
|
|
|
super("UpdateGlobalConfigFromEnv");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async migrate(): Promise<void> {
|
|
|
|
// get all the users with email isVerified true.
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
let emailServerType: EmailServerType = EmailServerType.Internal;
|
|
|
|
|
|
|
|
if (process.env["USE_INTERNAL_SMTP"] !== "true") {
|
|
|
|
emailServerType = EmailServerType.CustomSMTP;
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (process.env["SENDGRID_API_KEY"]) {
|
|
|
|
emailServerType = EmailServerType.Sendgrid;
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|
2024-06-14 11:09:53 +00:00
|
|
|
|
|
|
|
await GlobalConfigService.updateOneById({
|
|
|
|
id: ObjectID.getZeroObjectID(),
|
|
|
|
data: {
|
|
|
|
// Update Twilio
|
|
|
|
|
|
|
|
twilioAccountSID: process.env["TWILIO_ACCOUNT_SID"] || "",
|
|
|
|
twilioAuthToken: process.env["TWILIO_AUTH_TOKEN"] || "",
|
|
|
|
twilioPhoneNumber: process.env["TWILIO_PHONE_NUMBER"] || "",
|
|
|
|
|
|
|
|
// Update SMTP
|
|
|
|
smtpUsername: process.env["SMTP_USERNAME"] || "",
|
|
|
|
smtpPassword: process.env["SMTP_PASSWORD"] || "",
|
|
|
|
smtpHost: Hostname.fromString(process.env["SMTP_HOST"] || ""),
|
|
|
|
smtpPort: new Port(process.env["SMTP_PORT"] || "25"),
|
|
|
|
isSMTPSecure: process.env["SMTP_IS_SECURE"] === "true",
|
|
|
|
smtpFromEmail:
|
|
|
|
process.env["SMTP_FROM_EMAIL"] || process.env["SMTP_EMAIL"] || "",
|
|
|
|
smtpFromName: process.env["SMTP_FROM_NAME"] || "",
|
|
|
|
|
|
|
|
emailServerType: emailServerType,
|
|
|
|
|
|
|
|
// diable signup
|
|
|
|
disableSignup: process.env["DISABLE_SIGNUP"] === "true",
|
|
|
|
|
|
|
|
sendgridApiKey: process.env["SENDGRID_API_KEY"] || "",
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
isRoot: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async rollback(): Promise<void> {
|
|
|
|
return;
|
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|