Return proper NIP-20 responses
This commit is contained in:
parent
382f52604d
commit
dc721bcaa8
@ -14,7 +14,7 @@ Deno.test('passes events through multiple policies', async () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
assertEquals(result.action, 'reject');
|
assertEquals(result.action, 'reject');
|
||||||
assertEquals(result.msg, 'The relay is read-only.');
|
assertEquals(result.msg, 'blocked: the relay is read-only');
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('short-circuits on the first reject', async () => {
|
Deno.test('short-circuits on the first reject', async () => {
|
||||||
@ -26,7 +26,7 @@ Deno.test('short-circuits on the first reject', async () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
assertEquals(result.action, 'reject');
|
assertEquals(result.action, 'reject');
|
||||||
assertEquals(result.msg, 'The relay is read-only.');
|
assertEquals(result.msg, 'blocked: the relay is read-only');
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('accepts when all policies accept', async () => {
|
Deno.test('accepts when all policies accept', async () => {
|
||||||
|
@ -16,7 +16,7 @@ const hellthreadPolicy: Policy<Hellthread> = (msg, opts) => {
|
|||||||
return {
|
return {
|
||||||
id: msg.event.id,
|
id: msg.event.id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: `Event rejected due to ${p.length} "p" tags (${limit} is the limit).`,
|
msg: `blocked: rejected due to ${p.length} "p" tags (${limit} is the limit).`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ const keywordPolicy: Policy<Iterable<string>> = ({ event: { id, content } }, wor
|
|||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: 'Event contains a banned word or phrase.',
|
msg: 'blocked: contains a banned word or phrase.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ const pubkeyBanPolicy: Policy<Iterable<string>> = ({ event: { id, pubkey } }, pu
|
|||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: 'Pubkey is banned.',
|
msg: 'blocked: pubkey is banned.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ const rateLimitPolicy: Policy<RateLimit> = async (msg, opts) => {
|
|||||||
return {
|
return {
|
||||||
id: msg.event.id,
|
id: msg.event.id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: 'Rate-limited.',
|
msg: 'rate-limited: too many requests',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import type { Policy } from '../types.ts';
|
|||||||
const readOnlyPolicy: Policy<void> = (msg) => ({
|
const readOnlyPolicy: Policy<void> = (msg) => ({
|
||||||
id: msg.event.id,
|
id: msg.event.id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: 'The relay is read-only.',
|
msg: 'blocked: the relay is read-only',
|
||||||
});
|
});
|
||||||
|
|
||||||
export default readOnlyPolicy;
|
export default readOnlyPolicy;
|
||||||
|
@ -8,7 +8,7 @@ const regexPolicy: Policy<RegExp> = ({ event: { id, content } }, regex) => {
|
|||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: 'Event matches a banned expression.',
|
msg: 'blocked: text matches a banned expression.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ const whitelistPolicy: Policy<Iterable<string>> = ({ event: { id, pubkey } }, pu
|
|||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
msg: 'Only certain pubkeys are allowed.',
|
msg: 'blocked: only certain pubkeys are allowed to post',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user