mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-18 22:13:25 +00:00
Merge pull request #44659 from is-a-dev/wdhdev-patch-1
feat(raw-api): push domain JSONs
This commit is contained in:
1 file changed
+31
-38
+31
-38
@@ -3,54 +3,48 @@ const path = require("path");
|
|||||||
|
|
||||||
const directoryPath = path.join(__dirname, "../domains");
|
const directoryPath = path.join(__dirname, "../domains");
|
||||||
const outputDir = path.join(__dirname, "../raw-api");
|
const outputDir = path.join(__dirname, "../raw-api");
|
||||||
|
const domainsOutputDir = path.join(outputDir, "v2", "domains");
|
||||||
|
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
if (!fs.existsSync(domainsOutputDir)) {
|
||||||
|
fs.mkdirSync(domainsOutputDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
const internal = require(path.join(__dirname, "internal.json"));
|
const internal = require(path.join(__dirname, "internal.json"));
|
||||||
const reserved = require(path.join(__dirname, "reserved.json"));
|
const reserved = require(path.join(__dirname, "reserved.json"));
|
||||||
|
|
||||||
const v2 = [];
|
const v2 = [];
|
||||||
|
|
||||||
|
function writeDomainFile(entry) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(domainsOutputDir, `${entry.subdomain}.json`),
|
||||||
|
JSON.stringify(entry)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (const subdomain of internal) {
|
for (const subdomain of internal) {
|
||||||
const commonData = {
|
const entry = {
|
||||||
domain: `${subdomain}.is-a.dev`,
|
domain: `${subdomain}.is-a.dev`,
|
||||||
subdomain: subdomain,
|
subdomain: subdomain,
|
||||||
owner: {
|
owner: { username: "is-a-dev" },
|
||||||
username: "is-a-dev"
|
records: { CNAME: "internal.is-a.dev" },
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const records = {
|
|
||||||
CNAME: "internal.is-a.dev"
|
|
||||||
};
|
|
||||||
|
|
||||||
v2.push({
|
|
||||||
...commonData,
|
|
||||||
records: records,
|
|
||||||
internal: true
|
internal: true
|
||||||
});
|
};
|
||||||
|
v2.push(entry);
|
||||||
|
writeDomainFile(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const subdomain of reserved) {
|
for (const subdomain of reserved) {
|
||||||
const commonData = {
|
const entry = {
|
||||||
domain: `${subdomain}.is-a.dev`,
|
domain: `${subdomain}.is-a.dev`,
|
||||||
subdomain: subdomain,
|
subdomain: subdomain,
|
||||||
owner: {
|
owner: { username: "is-a-dev" },
|
||||||
username: "is-a-dev"
|
records: { URL: "https://is-a.dev/reserved" },
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const records = {
|
|
||||||
URL: "https://is-a.dev/reserved"
|
|
||||||
};
|
|
||||||
|
|
||||||
v2.push({
|
|
||||||
...commonData,
|
|
||||||
records: records,
|
|
||||||
reserved: true
|
reserved: true
|
||||||
});
|
};
|
||||||
|
v2.push(entry);
|
||||||
|
writeDomainFile(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readdir(directoryPath, function (err, files) {
|
fs.readdir(directoryPath, function (err, files) {
|
||||||
@@ -67,31 +61,30 @@ fs.readdir(directoryPath, function (err, files) {
|
|||||||
const item = JSON.parse(data);
|
const item = JSON.parse(data);
|
||||||
const name = path.parse(file).name;
|
const name = path.parse(file).name;
|
||||||
|
|
||||||
item.domain = name + ".is-a.dev";
|
item.domain = `${name}.is-a.dev`;
|
||||||
item.subdomain = name;
|
item.subdomain = name;
|
||||||
|
|
||||||
delete item.owner.email;
|
delete item.owner.email;
|
||||||
|
|
||||||
let itemV2 = {
|
const itemV2 = {
|
||||||
domain: item.domain,
|
domain: item.domain,
|
||||||
subdomain: item.subdomain,
|
subdomain: item.subdomain,
|
||||||
owner: item.owner,
|
owner: item.owner,
|
||||||
records: item.records
|
records: item.records
|
||||||
};
|
};
|
||||||
|
|
||||||
if (item.redirect_config) itemV2.redirect_config = item.redirect_config;
|
if (item.redirect_config) itemV2.redirect_config = item.redirect_config;
|
||||||
|
|
||||||
if (item.proxied) itemV2.proxied = item.proxied;
|
if (item.proxied) itemV2.proxied = item.proxied;
|
||||||
|
|
||||||
v2.push(itemV2);
|
v2.push(itemV2);
|
||||||
|
writeDomainFile(itemV2);
|
||||||
|
|
||||||
processedCount++;
|
processedCount++;
|
||||||
if (processedCount === files.length) {
|
if (processedCount === files.length) {
|
||||||
v2.sort((a, b) => a.domain.localeCompare(b.subdomain));
|
v2.sort((a, b) => a.domain.localeCompare(b.subdomain));
|
||||||
|
fs.writeFile(
|
||||||
fs.writeFile("raw-api/v2.json", JSON.stringify(v2), (err) => {
|
path.join(outputDir, "v2.json"),
|
||||||
if (err) throw err;
|
JSON.stringify(v2),
|
||||||
});
|
(err) => { if (err) throw err; }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user