mirror of
https://github.com/AIsouler/GKD_subscription.git
synced 2025-12-20 00:35:17 +08:00
chore: 增加快照链接校验
This commit is contained in:
38
src/file.ts
38
src/file.ts
@@ -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) => {
|
||||
// check duplicated group key
|
||||
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)[];
|
||||
if (newKeys.some((s) => !sortKeys.includes(s))) {
|
||||
console.log({
|
||||
|
||||
Reference in New Issue
Block a user