Add pub.feedless.social as a first pub when in standalone mode
This commit is contained in:
parent
f63e2e42ab
commit
54c1e8d77b
|
@ -522,7 +522,7 @@ router.get("/pubs", async (_req, res) => {
|
||||||
res.render("desktop/pubs", { peers });
|
res.render("desktop/pubs", { peers });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/pub_invite", async (_req, res) => {
|
router.get("/pub_invite", { public: true }, async (_req, res) => {
|
||||||
const invite = await ssb.client().invite.create({ uses: 1 });
|
const invite = await ssb.client().invite.create({ uses: 1 });
|
||||||
|
|
||||||
res.json({ invite });
|
res.json({ invite });
|
||||||
|
|
|
@ -5,12 +5,14 @@ const queries = require("./queries");
|
||||||
const debug = require("debug")("express");
|
const debug = require("debug")("express");
|
||||||
const metrics = require("./metrics");
|
const metrics = require("./metrics");
|
||||||
const { ssbFolder } = require("./utils");
|
const { ssbFolder } = require("./utils");
|
||||||
|
const fetch = require("node-fetch").default;
|
||||||
|
|
||||||
let ssbClient;
|
let ssbClient;
|
||||||
|
|
||||||
let ssbSecret = ssbKeys.loadOrCreateSync(`${ssbFolder()}/secret`);
|
|
||||||
let syncing = false;
|
let syncing = false;
|
||||||
|
|
||||||
|
const mode = process.env.MODE || "standalone";
|
||||||
|
const ssbSecret = ssbKeys.loadOrCreateSync(`${ssbFolder()}/secret`);
|
||||||
|
|
||||||
const connectClient = (ssbSecret) => {
|
const connectClient = (ssbSecret) => {
|
||||||
Client(ssbSecret, ssbConfig, async (err, server) => {
|
Client(ssbSecret, ssbConfig, async (err, server) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
@ -32,9 +34,25 @@ const connectClient = (ssbSecret) => {
|
||||||
metrics.ssbProgressTotal.set(total);
|
metrics.ssbProgressTotal.set(total);
|
||||||
});
|
});
|
||||||
console.log("SSB Client ready");
|
console.log("SSB Client ready");
|
||||||
|
|
||||||
|
if (mode == "standalone") addFirstPub();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addFirstPub = async () => {
|
||||||
|
const peers = await ssbClient.gossip.peers();
|
||||||
|
if (peers.length == 0) {
|
||||||
|
console.log("No pubs found, adding pub.feedless.social as a first pub");
|
||||||
|
try {
|
||||||
|
const response = await fetch("https://feedless.social/pub_invite");
|
||||||
|
const { invite } = await response.json();
|
||||||
|
await ssbClient.invite.accept(invite);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Could add feedless pub", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.client = () => ssbClient;
|
module.exports.client = () => ssbClient;
|
||||||
module.exports.isSyncing = () => syncing;
|
module.exports.isSyncing = () => syncing;
|
||||||
module.exports.reconnectWith = connectClient;
|
module.exports.reconnectWith = connectClient;
|
||||||
|
|
|
@ -2653,6 +2653,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz",
|
||||||
"integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA=="
|
"integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA=="
|
||||||
},
|
},
|
||||||
|
"node-fetch": {
|
||||||
|
"version": "2.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||||
|
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
|
||||||
|
},
|
||||||
"node-gyp-build": {
|
"node-gyp-build": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz",
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
"ismobilejs": "^1.1.1",
|
"ismobilejs": "^1.1.1",
|
||||||
"left-pad": "^1.3.0",
|
"left-pad": "^1.3.0",
|
||||||
"mime-types": "^2.1.26",
|
"mime-types": "^2.1.26",
|
||||||
|
"node-fetch": "^2.6.0",
|
||||||
"prom-client": "^12.0.0",
|
"prom-client": "^12.0.0",
|
||||||
"pull-cat": "^1.1.11",
|
"pull-cat": "^1.1.11",
|
||||||
"pull-identify-filetype": "^1.1.0",
|
"pull-identify-filetype": "^1.1.0",
|
||||||
|
|
Loading…
Reference in New Issue