strfry can send multiple messages at once (!!)
This commit is contained in:
parent
8c8c969486
commit
b279e042e1
16
README.md
16
README.md
@ -34,10 +34,9 @@ import {
|
||||
rateLimitPolicy,
|
||||
readStdin,
|
||||
writeStdout,
|
||||
} from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||
|
||||
const msg = await readStdin();
|
||||
} from './mod.ts';
|
||||
|
||||
for await (const msg of readStdin()) {
|
||||
const result = await pipeline(msg, [
|
||||
[hellthreadPolicy, { limit: 100 }],
|
||||
[antiDuplicationPolicy, { ttl: 60000, minLength: 50 }],
|
||||
@ -45,6 +44,8 @@ const result = await pipeline(msg, [
|
||||
]);
|
||||
|
||||
writeStdout(result);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Finally, edit `strfry.conf` and enable the policy:
|
||||
@ -110,15 +111,14 @@ Once you're done, you can either upload the file somewhere online or directly to
|
||||
```diff
|
||||
--- a/strfry-policy.ts
|
||||
+++ b/strfry-policy.ts
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
@@ -8,12 +8,14 @@ import {
|
||||
readStdin,
|
||||
writeStdout,
|
||||
} from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||
} from './mod.ts';
|
||||
+import { americanPolicy } from 'https://gist.githubusercontent.com/alexgleason/5c2d084434fa0875397f44da198f4352/raw/3d3ce71c7ed9cef726f17c3a102c378b81760a45/american-policy.ts';
|
||||
|
||||
const msg = await readStdin();
|
||||
|
||||
@@ -17,6 +18,7 @@ const result = await pipeline(msg, [
|
||||
for await (const msg of readStdin()) {
|
||||
const result = await pipeline(msg, [
|
||||
[hellthreadPolicy, { limit: 100 }],
|
||||
[antiDuplicationPolicy, { ttl: 60000, minLength: 50 }],
|
||||
[rateLimitPolicy, { whitelist: ['127.0.0.1'] }],
|
||||
|
@ -10,8 +10,7 @@ import {
|
||||
writeStdout,
|
||||
} from './mod.ts';
|
||||
|
||||
const msg = await readStdin();
|
||||
|
||||
for await (const msg of readStdin()) {
|
||||
const result = await pipeline(msg, [
|
||||
noopPolicy,
|
||||
[hellthreadPolicy, { limit: 100 }],
|
||||
@ -20,3 +19,4 @@ const result = await pipeline(msg, [
|
||||
]);
|
||||
|
||||
writeStdout(result);
|
||||
}
|
||||
|
11
src/io.ts
11
src/io.ts
@ -3,12 +3,13 @@ import { readLines } from './deps.ts';
|
||||
import type { InputMessage, OutputMessage } from './types.ts';
|
||||
|
||||
/**
|
||||
* Get the first line from stdin.
|
||||
* Can only be read ONCE, or else it returns undefined.
|
||||
* Parse strfy messages from stdin.
|
||||
* strfry may batch multiple messages at once.
|
||||
*/
|
||||
async function readStdin(): Promise<InputMessage> {
|
||||
const { value } = await readLines(Deno.stdin).next();
|
||||
return JSON.parse(value);
|
||||
async function* readStdin(): AsyncGenerator<InputMessage> {
|
||||
for await (const line of readLines(Deno.stdin)) {
|
||||
yield JSON.parse(line);
|
||||
}
|
||||
}
|
||||
|
||||
/** Writes the output message to stdout. */
|
||||
|
Loading…
Reference in New Issue
Block a user