feat: initial s5 network bridge

This commit is contained in:
Derrick Hammer 2023-12-11 20:23:17 -05:00
parent dc7110d361
commit 8151d8a7ec
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 30 additions and 0 deletions

30
bridge.mts Normal file
View File

@ -0,0 +1,30 @@
import * as fs from "fs";
import { S5Client } from "@lumeweb/s5-js";
import { CID } from "@lumeweb/libs5";
import axios from "axios";
type SiteList = {
[domain: string]: {
pubkey: string;
};
};
const sites = JSON.parse(
fs.readFileSync("sites.json", { encoding: "utf8" }),
) as SiteList;
const client = new S5Client("https://s5.web3portal.com");
for (const siteName in sites) {
const site = sites[siteName];
const sub = await client.subscribeToEntry(Buffer.from(site.pubkey, "hex"));
sub.listen((entry) => {
const cid = CID.fromRegistry(entry.data);
axios.post("http://localhost/api/events/siteUpdateReceived", {
cid: cid.toString(),
site: siteName,
});
});
}