Skip to content

Commit 711e5ca

Browse files
authored
Merge pull request #2 from LemmyNet/typescript_push_webhook
Add typescript_push_webhook plugin
2 parents 8f6949a + 6ff2f53 commit 711e5ca

File tree

13 files changed

+645
-10
lines changed

13 files changed

+645
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
.vscode
44

55
# tests
6-
tests/node_modules
6+
**/node_modules
7+
plugins/typescript_push_webhook/dist
78
tests/.yalc
89
tests/yalc.lock
910
tests/pict-rs
1011
tests/log
1112

1213
# lemmy plugins
1314
*.wasm
15+

.woodpecker.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,39 @@ steps:
33
image: tmknom/prettier:3.2.5
44
commands:
55
- prettier -c .
6+
when:
7+
- event: pull_request
8+
9+
build_typescript_plugin:
10+
# need to use ubuntu instead of debian because extism-js requires newer glibc version
11+
# https://github.com/extism/js-pdk/issues/129
12+
image: ubuntu
13+
commands:
14+
- apt-get update && apt-get install -y --no-install-recommends --no-install-suggests node-typescript wget gzip ca-certificates npm
15+
- wget --quiet https://github.com/extism/js-pdk/releases/download/v1.4.0/extism-js-x86_64-linux-v1.4.0.gz -O extism-js.gz
16+
- gzip -d extism-js.gz
17+
- chmod +x extism-js
18+
- mv extism-js /usr/local/bin/
19+
# for wasm-merge, version in ubuntu repo is too old
20+
- wget --quiet https://github.com/WebAssembly/binaryen/releases/download/version_122/binaryen-version_122-x86_64-linux.tar.gz -O binaryen.tar.gz
21+
- tar -xvzf binaryen.tar.gz
22+
- mv binaryen-version_122/bin/* /usr/local/bin/
23+
- cd plugins/typescript_push_webhook
24+
- npm install
25+
- npm run build
26+
when:
27+
- event: [pull_request, tag]
628

7-
build_go_plugins:
29+
build_go_plugin:
830
image: tinygo/tinygo:latest
931
backend_options:
1032
docker:
1133
user: 0:0
1234
commands:
1335
- cd plugins/go_replace_words
1436
- tinygo build -o ../go_replace_words.wasm -target wasip1 -buildmode=c-shared main.go
15-
- cd -
37+
when:
38+
- event: [pull_request, tag]
1639

1740
run_plugin_tests:
1841
image: node:22-bookworm-slim
@@ -30,12 +53,15 @@ steps:
3053
- cd tests/
3154
- pnpm i
3255
- pnpm test
56+
when:
57+
- event: pull_request
3358

3459
publish_plugins:
3560
image: woodpeckerci/plugin-release
3661
settings:
3762
files:
3863
- plugins/go_replace_words.wasm
64+
- plugins/typescript_push_webhook.wasm
3965
title: ${CI_COMMIT_TAG##v}
4066
api-key:
4167
from_secret: github_token

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22

33
This repository contains various example plugins for Lemmy. See the [Extism documentation](https://extism.org/docs/quickstart/plugin-quickstart) for details on how to write plugins. Lemmy-specific details and available hooks are [described in the RFC](https://github.com/LemmyNet/rfcs/pull/8/files).
44

5-
## Contributing
5+
## Go: Replace Words
66

7-
- Install `go`, tinygo`, `pnpm`, `postgresql`
8-
- `cd tests`
9-
- `./run.sh` to start test cases
7+
Uses the `create_local_post` hook to listen for newly created posts, replacing some words and rejecting posts containing specific terms. See [go-pdk readme](https://github.com/extism/go-pdk#readme) for detailed documentation.
108

11-
## Available Examples
9+
Use the following steps to compile it:
1210

13-
- `go_replace_words` Written in Go, uses `create_local_post` hook to replace specific words in post title, and reject posts with forbidden words in title
11+
```bash
12+
apt install go
13+
# install tinygo: https://tinygo.org/getting-started/install/linux/
14+
cd plugins/go_replace_words
15+
tinygo build -o ../go_replace_words.wasm -target wasip1 -buildmode=c-shared main.go
16+
```
17+
18+
## Typescript: Push Webhook
19+
20+
Listens to `new_post` hook which is called after any local or remote post is created. Then calls the url configured in the [manifest](https://extism.org/docs/concepts/manifest/) (`plugins/typescript_push_webhook.json`) with the post's `ap_id`. See [js-pdk readme](https://github.com/extism/js-pdk#readme) for setup and detailed documentation.
21+
22+
Use the following steps to compile it:
23+
24+
```bash
25+
apt install npm typescript
26+
# use steps in js-pdk readme to install extism-js
27+
cd plugins/typescript_push_webhook
28+
npm install
29+
npm run build
30+
```
31+
32+
## Tests
33+
34+
This repository contains test cases for the plugins. To run them install `pnpm` and `postgresql`, with a database `postgres://lemmy:password@localhost:5432/lemmy`. Then go into `tests` folder and execute `./run.sh`.

lemmy_server

399 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"wasm": [
3+
{
4+
"path": "plugins/typescript_push_webhook.wasm"
5+
}
6+
],
7+
"allowed_hosts": ["127.0.0.1"],
8+
"config": {
9+
"notify_url": "http://127.0.0.1:8927"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const esbuild = require("esbuild");
2+
3+
esbuild.build({
4+
entryPoints: ["src/index.ts"],
5+
outdir: "dist",
6+
bundle: true,
7+
sourcemap: true,
8+
minify: false, // might want to use true for production build
9+
format: "cjs", // needs to be CJS for now
10+
target: ["es2020"], // don't go over es2020 because quickjs doesn't support it
11+
});

0 commit comments

Comments
 (0)