update source
continuous-integration/drone/push Build is passing Details

This commit is contained in:
186526 2023-03-05 16:36:34 +08:00
parent 20433ae2d4
commit 956cd0df1d
1 changed files with 22 additions and 7 deletions

View File

@ -2,10 +2,16 @@ import bgpq4 from "./bgpq4";
import fs from "node:fs"; import fs from "node:fs";
import YAML from "yaml"; import YAML from "yaml";
import { getNetName } from "./pdb"; import { getNetName } from "./pdb";
import LRUCache from "lru-cache";
import axios from "axios"; import axios from "axios";
import { env } from "node:process"; import { env } from "node:process";
const cache = new LRUCache({
max: 500,
ttl: 1000 * 60 * 5,
});
const main = async () => { const main = async () => {
const config: { const config: {
"MNT-BY": string[]; "MNT-BY": string[];
@ -44,6 +50,7 @@ const main = async () => {
Object.keys(config["AS-SETS"]).length Object.keys(config["AS-SETS"]).length
})\n` })\n`
); );
let members = await Promise.all( let members = await Promise.all(
config.members.map(async (member) => { config.members.map(async (member) => {
const setName = Object.keys(member)[0]; const setName = Object.keys(member)[0];
@ -60,9 +67,18 @@ const main = async () => {
console.log("Add", setName, answer, "to", asSetName); console.log("Add", setName, answer, "to", asSetName);
return answer.filter( const asnList = answer
(as) => !(config["AS-SETS"][asSetName].expect ?? [0]).includes(as) .filter(
); (as) => !(config["AS-SETS"][asSetName].expect ?? [0]).includes(as)
)
.filter(Boolean)
.sort();
asnList.forEach((k) => {
if (!cache.has(k)) cache.set(k, setName);
});
return asnList;
}) })
); );
@ -79,9 +95,7 @@ const main = async () => {
"TECH-C": config["TECH-C"], "TECH-C": config["TECH-C"],
"ADMIN-C": config["ADMIN-C"], "ADMIN-C": config["ADMIN-C"],
remarks: config["AS-SETS"][asSetName].remarks, remarks: config["AS-SETS"][asSetName].remarks,
members: Array.from(new Set(members.flat(Infinity))) members: [...new Set(members.flat(Infinity))].filter(Boolean) as any,
.filter(Boolean)
.sort() as number[],
include: (config["AS-SETS"][asSetName].include ?? []).sort(), include: (config["AS-SETS"][asSetName].include ?? []).sort(),
}); });
i++; i++;
@ -99,7 +113,8 @@ ${k.remarks.map((k) => `remarks: ${k}`).join("\n")}
${( ${(
await Promise.all( await Promise.all(
k.members.map( k.members.map(
async (k) => `remarks: ${await getNetName(k)}\nmembers: AS${k}` async (k) =>
`remarks: ${await getNetName(k)} from ${cache.get(k)}\nmembers: AS${k}`
) )
) )
).join("\n")}${k.include.map((k) => `\nmembers: ${k}`)} ).join("\n")}${k.include.map((k) => `\nmembers: ${k}`)}