Port strfry policies to @nostrify/policies
Use packages from JSR and adapt code for new policy APIs
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
#!/bin/sh
|
||||
//bin/true; exec deno run -A "$0" "$@"
|
||||
//bin/true; exec deno run --unstable-kv -A "$0" "$@"
|
||||
import {
|
||||
antiDuplicationPolicy,
|
||||
hellthreadPolicy,
|
||||
pipeline,
|
||||
rateLimitPolicy,
|
||||
AntiDuplicationPolicy,
|
||||
HellthreadPolicy,
|
||||
PipePolicy,
|
||||
readStdin,
|
||||
writeStdout,
|
||||
} from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||
import ldapPolicy from './ldap-policy.ts';
|
||||
} from 'jsr:@nostrify/policies';
|
||||
import { strfry } from 'jsr:@nostrify/strfry';
|
||||
import { LdapConfig, LdapPolicy } from './ldap-policy.ts';
|
||||
import { load } from "https://deno.land/std@0.224.0/dotenv/mod.ts";
|
||||
|
||||
const dirname = new URL('.', import.meta.url).pathname;
|
||||
await load({ envPath: `${dirname}/.env`, export: true });
|
||||
|
||||
const ldapConfig = {
|
||||
const ldapConfig: LdapConfig = {
|
||||
url: Deno.env.get("LDAP_URL"),
|
||||
bindDN: Deno.env.get("LDAP_BIND_DN"),
|
||||
password: Deno.env.get("LDAP_PASSWORD"),
|
||||
@@ -22,13 +22,10 @@ const ldapConfig = {
|
||||
whitelistPubkeys: Deno.env.get("WHITELIST_PUBKEYS")?.split(',')
|
||||
}
|
||||
|
||||
for await (const msg of readStdin()) {
|
||||
const result = await pipeline(msg, [
|
||||
[hellthreadPolicy, { limit: 10 }],
|
||||
[antiDuplicationPolicy, { ttl: 60000, minLength: 50 }],
|
||||
[rateLimitPolicy, { whitelist: ['127.0.0.1'] }],
|
||||
[ldapPolicy, ldapConfig],
|
||||
]);
|
||||
const policy = new PipePolicy([
|
||||
new HellthreadPolicy({ limit: 10 }),
|
||||
new AntiDuplicationPolicy({ kv: await Deno.openKv(), expireIn: 60000, minLength: 50 }),
|
||||
new LdapPolicy(ldapConfig)
|
||||
]);
|
||||
|
||||
writeStdout(result);
|
||||
}
|
||||
await strfry(policy);
|
||||
|
||||
Reference in New Issue
Block a user