-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedit.js
73 lines (62 loc) · 2.25 KB
/
edit.js
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
const array = process.env.EVENT_ISSUE_BODY.split("### ")
const flare = require("cloudflare")
const { logSuccess, getValidRecordType,logErrorAndExit, DNS_ZONE_ID, nonascii } = require('./utils');
/**
* CONSTANTS
*/
const TTL = 60;
const subdomain = array[1][1]
const cf = flare({
token: process.env.CF_TOKEN
})
// dark magic starts here, don't ask.
array.forEach((item, index) => {
array[index] = item.split("\n\n")
})
const original = array[3][1]
array[3][1] = original.split("\n")[0]
array[3].push(original.split("\n")[1])
// End of the dark magic.
if (
!(
array.length === 4 &&
array[0].length === 1 &&
array[0][0] === "" &&
array[1][0] === "Subdomain Name" &&
array[1].length === 3 &&
array[2][0] === "DNS Record" &&
array[2].length === 3 &&
array[3].length === 3 &&
array[3][0] === "Agreement" &&
array[3][1] === "- [X] I have ensured that this subdomain is mine" &&
array[3][2] === undefined &&
!subdomain.includes(" ") &&
!array[2][1].includes(" ") &&
!nonascii.test(subdomain) &&
!nonascii.test(array[2][1]) &&
array[1][1] !== ".lgbt.sh" &&
array[1][1].endsWith(".lgbt.sh")
)
) {
return logErrorAndExit("Format invalid! It's usually because you didn't check the agreements, or the domain/record you entered is invalid!", subdomain)
}
cf.dnsRecords.browse(DNS_ZONE_ID)
.then((dnsRecords) => {
const dnsAvailable = dnsRecords.result.filter((foundDNS) => { return (foundDNS.name === subdomain && foundDNS.comment === process.env.EVENT_USER_LOGIN) })
if (!dnsAvailable[0])
logErrorAndExit(`This subdomain is not yours or the subdomain is not found!`, subdomain)
const recordType = getValidRecordType(array);
return cf.dnsRecords.edit(DNS_ZONE_ID, dnsAvailable[0].id, {
content: array[2][1],
name: subdomain,
proxied: false,
type: recordType,
ttl: TTL,
comment: process.env.EVENT_USER_LOGIN,
});
}).then((cloudFlareResponse) => {
if (!cloudFlareResponse.success) {
return logErrorAndExit(`CloudFlare Error: ${cloudFlareResponse.errors[0].message}`, subdomain);
}
logSuccess(subdomain);
}).catch((error) => console.error("An error occurred:", error));