3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 02:57:20 +00:00

refactor: don't create 'name' property in config dynamically

This commit is contained in:
Dragory 2024-11-10 13:47:40 +02:00
parent 0810dd3f0e
commit 395a750e9d
No known key found for this signature in database
19 changed files with 86 additions and 154 deletions

View file

@ -9,30 +9,23 @@ interface MatchResultType {
mode: "blacklist" | "whitelist";
}
const configSchema = z
.strictObject({
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
blacklist_enabled: z.boolean().default(false),
filetype_whitelist: z.array(z.string().max(32)).max(255).default([]),
whitelist_enabled: z.boolean().default(false),
})
.transform((parsed, ctx) => {
if (parsed.blacklist_enabled && parsed.whitelist_enabled) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Cannot have both blacklist and whitelist enabled",
});
return z.NEVER;
}
if (!parsed.blacklist_enabled && !parsed.whitelist_enabled) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Must have either blacklist or whitelist enabled",
});
return z.NEVER;
}
return parsed;
});
const baseConfig = z.strictObject({
filetype_blacklist: z.array(z.string().max(32)).max(255).default([]),
filetype_whitelist: z.array(z.string().max(32)).max(255).default([]),
});
const configWithWhitelist = baseConfig.merge(z.strictObject({
whitelist_enabled: z.literal(true),
blacklist_enabled: z.literal(false).default(false),
}));
const configWithBlacklist = baseConfig.merge(z.strictObject({
blacklist_enabled: z.literal(true),
whitelist_enabled: z.literal(false).default(false),
}));
const configSchema = z.union([
configWithWhitelist,
configWithBlacklist,
]);
export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
configSchema,

View file

@ -8,30 +8,23 @@ interface MatchResultType {
mode: "blacklist" | "whitelist";
}
const configSchema = z
.strictObject({
mime_type_blacklist: z.array(z.string().max(255)).max(255).default([]),
blacklist_enabled: z.boolean().default(false),
mime_type_whitelist: z.array(z.string().max(255)).max(255).default([]),
whitelist_enabled: z.boolean().default(false),
})
.transform((parsed, ctx) => {
if (parsed.blacklist_enabled && parsed.whitelist_enabled) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Cannot have both blacklist and whitelist enabled",
});
return z.NEVER;
}
if (!parsed.blacklist_enabled && !parsed.whitelist_enabled) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Must have either blacklist or whitelist enabled",
});
return z.NEVER;
}
return parsed;
});
const baseConfig = z.strictObject({
mime_type_blacklist: z.array(z.string().max(32)).max(255).default([]),
mime_type_whitelist: z.array(z.string().max(32)).max(255).default([]),
});
const configWithWhitelist = baseConfig.merge(z.strictObject({
whitelist_enabled: z.literal(true),
blacklist_enabled: z.literal(false).default(false),
}));
const configWithBlacklist = baseConfig.merge(z.strictObject({
blacklist_enabled: z.literal(true),
whitelist_enabled: z.literal(false).default(false),
}));
const configSchema = z.union([
configWithWhitelist,
configWithBlacklist,
]);
export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
configSchema,