This repository was archived by the owner on May 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSmtp.prompt.ts
99 lines (96 loc) · 3.66 KB
/
Smtp.prompt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* eslint-disable no-case-declarations */
import Logger from "../../Lib/Logger";
import prompt from "prompt";
import { CacheConfig } from "../../Cache/Configs.cache";
import ConfigModel from "../../Database/Models/Configs.model";
import updateSMTP from "../updateSMTP";
export default
{
name: 'SMTP',
description: 'Get all SMTP jobs',
args: [
{
name: 'action',
type: "list",
message: "Select the SMTP job you want to run",
choices: [
{
name: 'Show SMTP settings',
value: 'show_smtp_settings',
},
{
name: 'Update SMTP settings',
value: 'update_smtp_settings',
},
],
}
],
method: async ({action}: {action: string}) =>
{
switch(action)
{
case 'show_smtp_settings':
// Getting all invoices
Logger.info(`SMTP Settings:`, CacheConfig.get("smtp"));
break;
case 'update_smtp_settings':
{
const config = (await ConfigModel.find())[0];
return new Promise((resolve) =>
{
prompt.get([
{
name: "host",
description: "Host for SMTP server",
default: config.smtp.host,
required: true
},
{
name: "port",
description: "Port",
default: config.smtp.port,
required: true
},
{
name: "username",
description: "Username for user",
default: config.smtp.username,
required: true
},
{
name: "password",
description: "Password for user",
default: config.smtp.password,
required: true
},
{
name: "secure",
description: "Is connection secure?",
default: config.smtp.secure,
enum: ["true", "false"],
required: true
},
], async (err, result) =>
{
const host = result.host as string;
const port = parseInt(result.port as string) as number;
const username = result.username as string;
const password = result.password as string;
const secure = result.secure === "true";
Logger.info(`Updating smtp config..`);
await updateSMTP({
host,
port,
username,
password,
secure
});
resolve(true)
});
});
break;
}
}
return true;
}
}