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