chore: 增加快照链接校验

This commit is contained in:
lisonge
2023-09-15 16:25:34 +08:00
parent b0c06b5fda
commit e47ccae000

View File

@@ -72,6 +72,11 @@ export async function* walk(dirPath: string) {
} }
} }
export const validSnapshotUrl = (s: string) => {
const u = new URL(s);
return u.pathname.startsWith('/import/');
};
export const checkConfig = (newConfig: SubscriptionConfig) => { export const checkConfig = (newConfig: SubscriptionConfig) => {
// check duplicated group key // check duplicated group key
newConfig.apps?.forEach((app) => { newConfig.apps?.forEach((app) => {
@@ -138,6 +143,39 @@ export const checkConfig = (newConfig: SubscriptionConfig) => {
}); });
}); });
}); });
// check snapshotUrls
newConfig.apps?.forEach((app) => {
app.groups?.forEach((g) => {
iArrayToArray(g.snapshotUrls).forEach((u) => {
if (!validSnapshotUrl(u)) {
console.error({
appId: app.id,
groupKey: g.key,
});
throw new Error(
`invalid snapshotUrls: ${u}\nit should like https://gkd-kit.gitee.io/import/12506571`,
);
}
});
iArrayToArray(g.rules).forEach((r, ruleIndex) => {
if (typeof r == 'string') return;
iArrayToArray(r.snapshotUrls).forEach((u) => {
if (!validSnapshotUrl(u)) {
console.error({
appId: app.id,
groupKey: g.key,
ruleIndex: ruleIndex,
ruleKey: r.key,
});
throw new Error(
`invalid snapshotUrls: ${u}\nit should like https://gkd-kit.gitee.io/import/12506571`,
);
}
});
});
});
});
const newKeys = Object.keys(newConfig) as (keyof SubscriptionConfig)[]; const newKeys = Object.keys(newConfig) as (keyof SubscriptionConfig)[];
if (newKeys.some((s) => !sortKeys.includes(s))) { if (newKeys.some((s) => !sortKeys.includes(s))) {
console.log({ console.log({