web3.news/scripts/bridge.mts

33 lines
771 B
TypeScript
Raw Normal View History

2023-12-12 01:23:17 +00:00
import { S5Client } from "@lumeweb/s5-js";
import { CID } from "@lumeweb/libs5";
import axios from "axios";
2023-12-25 03:43:58 +00:00
import { getAvailableSites } from "../app/utils.js";
2023-12-12 01:23:17 +00:00
2023-12-22 09:11:03 +00:00
const sites = getAvailableSites();
2023-12-12 01:23:17 +00:00
const client = new S5Client("https://s5.web3portal.com");
const httpClient = axios.create({
2023-12-28 06:41:51 +00:00
baseURL: "http://app:8080",
});
2023-12-12 01:23:17 +00:00
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);
2023-12-28 06:46:51 +00:00
console.log({
cid: cid.toString(),
site: siteName,
});
try {
httpClient.post("/api/events/siteUpdateReceived", {
cid: cid.toString(),
site: siteName,
});
} catch {}
2023-12-12 01:23:17 +00:00
});
}