@bitsocial/bitsocial-cli 0.19.39 → 0.19.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -23
- package/dist/cli/base-command.js +7 -4
- package/dist/cli/commands/community/create.js +2 -2
- package/dist/cli/commands/community/delete.js +2 -2
- package/dist/cli/commands/community/edit.js +2 -2
- package/dist/cli/commands/community/get.d.ts +5 -1
- package/dist/cli/commands/community/get.js +24 -4
- package/dist/cli/commands/community/list.js +2 -2
- package/dist/cli/commands/community/start.js +2 -2
- package/dist/cli/commands/community/stop.js +2 -2
- package/dist/cli/commands/daemon.js +4 -5
- package/dist/ipfs/startIpfs.js +2 -2
- package/dist/util.d.ts +4 -3
- package/dist/util.js +2 -4
- package/dist/webui/daemon-server.js +2 -2
- package/oclif.manifest.json +707 -0
- package/package.json +4 -2
- package/dist/cli/commands/subplebbit/create.d.ts +0 -12
- package/dist/cli/commands/subplebbit/create.js +0 -54
- package/dist/cli/commands/subplebbit/edit.d.ts +0 -12
- package/dist/cli/commands/subplebbit/edit.js +0 -73
- package/dist/cli/commands/subplebbit/get.d.ts +0 -9
- package/dist/cli/commands/subplebbit/get.js +0 -32
- package/dist/cli/commands/subplebbit/list.d.ts +0 -9
- package/dist/cli/commands/subplebbit/list.js +0 -30
- package/dist/cli/commands/subplebbit/start.d.ts +0 -10
- package/dist/cli/commands/subplebbit/start.js +0 -41
- package/dist/cli/commands/subplebbit/stop.d.ts +0 -10
- package/dist/cli/commands/subplebbit/stop.js +0 -43
- package/dist/seeder.d.ts +0 -1
- package/dist/seeder.js +0 -83
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitsocial/bitsocial-cli",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.41",
|
|
4
4
|
"description": "Command line interface to Bitsocial API",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/bitsocialnet/bitsocial-cli",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"author": "Bitsocial Labs",
|
|
9
9
|
"license": "GPL-3.0-or-later",
|
|
10
10
|
"type": "module",
|
|
11
|
-
"publishConfig": {
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
12
14
|
"exports": null,
|
|
13
15
|
"scripts": {
|
|
14
16
|
"clean": "rm -rf tmp/",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from "../../base-command.js";
|
|
2
|
-
export default class Create extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: {
|
|
5
|
-
description: string;
|
|
6
|
-
command: string;
|
|
7
|
-
}[];
|
|
8
|
-
static flags: {
|
|
9
|
-
privateKeyPath: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
};
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Flags } from "@oclif/core";
|
|
2
|
-
//@ts-ignore
|
|
3
|
-
import DataObjectParser from "dataobject-parser";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import { BaseCommand } from "../../base-command.js";
|
|
6
|
-
import { getPlebbitLogger } from "../../../util.js";
|
|
7
|
-
import * as remeda from "remeda";
|
|
8
|
-
export default class Create extends BaseCommand {
|
|
9
|
-
static description = "Create a subplebbit with specific properties. A newly created sub will be started after creation and be able to receive publications. For a list of properties, visit https://github.com/plebbit/plebbit-js#subplebbiteditsubplebbiteditoptions";
|
|
10
|
-
static examples = [
|
|
11
|
-
{
|
|
12
|
-
description: "Create a subplebbit with title 'Hello Plebs' and description 'Welcome'",
|
|
13
|
-
command: "<%= config.bin %> <%= command.id %> --title 'Hello Plebs' --description 'Welcome'"
|
|
14
|
-
}
|
|
15
|
-
];
|
|
16
|
-
static flags = {
|
|
17
|
-
privateKeyPath: Flags.file({
|
|
18
|
-
exists: true,
|
|
19
|
-
description: "Private key (PEM) of the subplebbit signer that will be used to determine address (if address is not a domain). If it's not provided then Plebbit will generate a private key"
|
|
20
|
-
})
|
|
21
|
-
};
|
|
22
|
-
async run() {
|
|
23
|
-
const { flags } = await this.parse(Create);
|
|
24
|
-
const log = (await getPlebbitLogger())("plebbit-cli:commands:subplebbit:create");
|
|
25
|
-
log(`flags: `, flags);
|
|
26
|
-
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
|
|
27
|
-
const createOptions = DataObjectParser.transpose(remeda.omit(flags, ["plebbitRpcUrl", "privateKeyPath"]))["_data"];
|
|
28
|
-
if (flags.privateKeyPath)
|
|
29
|
-
try {
|
|
30
|
-
//@ts-expect-error
|
|
31
|
-
createOptions.signer = { privateKey: (await fs.promises.readFile(flags.privateKeyPath)).toString(), type: "ed25519" };
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
const error = e;
|
|
35
|
-
//@ts-expect-error
|
|
36
|
-
error.details = { ...error.details, privateKeyPath: flags.privateKeyPath };
|
|
37
|
-
await plebbit.destroy();
|
|
38
|
-
this.error(error);
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const createdSub = await plebbit.createSubplebbit(createOptions);
|
|
42
|
-
await createdSub.start();
|
|
43
|
-
this.log(createdSub.address);
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
const error = e;
|
|
47
|
-
//@ts-expect-error
|
|
48
|
-
error.details = { ...error.details, createOptions };
|
|
49
|
-
await plebbit.destroy();
|
|
50
|
-
this.error(error);
|
|
51
|
-
}
|
|
52
|
-
await plebbit.destroy();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from "../../base-command.js";
|
|
2
|
-
export default class Edit extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static args: {
|
|
5
|
-
address: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
-
};
|
|
7
|
-
static examples: {
|
|
8
|
-
description: string;
|
|
9
|
-
command: string;
|
|
10
|
-
}[];
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
//@ts-expect-error
|
|
2
|
-
import DataObjectParser from "dataobject-parser";
|
|
3
|
-
import { Args } from "@oclif/core";
|
|
4
|
-
import { BaseCommand } from "../../base-command.js";
|
|
5
|
-
import { getPlebbitLogger, mergeDeep } from "../../../util.js";
|
|
6
|
-
import * as remeda from "remeda";
|
|
7
|
-
export default class Edit extends BaseCommand {
|
|
8
|
-
static description = "Edit a subplebbit properties. For a list of properties, visit https://github.com/plebbit/plebbit-js#subplebbiteditsubplebbiteditoptions";
|
|
9
|
-
static args = {
|
|
10
|
-
address: Args.string({
|
|
11
|
-
name: "address",
|
|
12
|
-
required: true,
|
|
13
|
-
description: "Address of the subplebbit address to edit"
|
|
14
|
-
})
|
|
15
|
-
};
|
|
16
|
-
static examples = [
|
|
17
|
-
{
|
|
18
|
-
description: "Change the address of the sub to a new ENS address",
|
|
19
|
-
command: "plebbit subplebbit edit 12D3KooWG3XbzoVyAE6Y9vHZKF64Yuuu4TjdgQKedk14iYmTEPWu --address newAddress.eth"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
description: "Add the author address 'esteban.eth' as an admin on the sub",
|
|
23
|
-
command: `plebbit subplebbit edit mysub.eth '--roles["esteban.eth"].role' admin`
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
description: "Add two challenges to the sub. The first challenge will be a question and answer, and the second will be an image captcha",
|
|
27
|
-
command: `plebbit subplebbit edit mysub.eth --settings.challenges[0].name question --settings.challenges[0].options.question "what is the password?" --settings.challenges[0].options.answer thepassword --settings.challenges[1].name captcha-canvas-v3`
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
description: "Change the title and description",
|
|
31
|
-
command: `plebbit subplebbit edit mysub.eth --title "This is the new title" --description "This is the new description" `
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
description: "Remove a role from a moderator/admin/owner",
|
|
35
|
-
command: "plebbit subplebbit edit plebbit.eth --roles['rinse12.eth'] null"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
description: "Enable settings.fetchThumbnailUrls to fetch the thumbnail of url submitted by authors",
|
|
39
|
-
command: "subplebbit edit plebbit.eth --settings.fetchThumbnailUrls"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
description: "disable settings.fetchThumbnailUrls",
|
|
43
|
-
command: "subplebbit edit plebbit.eth --settings.fetchThumbnailUrls=false"
|
|
44
|
-
}
|
|
45
|
-
];
|
|
46
|
-
async run() {
|
|
47
|
-
const { flags, args } = await this.parse(Edit);
|
|
48
|
-
const log = (await getPlebbitLogger())("plebbit-cli:commands:subplebbit:edit");
|
|
49
|
-
log(`flags: `, flags);
|
|
50
|
-
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
|
|
51
|
-
const editOptions = DataObjectParser.transpose(remeda.omit(flags, ["plebbitRpcUrl"]))["_data"];
|
|
52
|
-
log("Edit options parsed:", editOptions);
|
|
53
|
-
const localSubs = plebbit.subplebbits;
|
|
54
|
-
if (!localSubs.includes(args.address))
|
|
55
|
-
this.error("Can't edit a remote subplebbit, make sure you're editing a local sub");
|
|
56
|
-
try {
|
|
57
|
-
const sub = await plebbit.createSubplebbit({ address: args.address });
|
|
58
|
-
const mergedSubState = remeda.pick(sub, remeda.keys.strict(editOptions));
|
|
59
|
-
const finalMergedState = mergeDeep(mergedSubState, editOptions);
|
|
60
|
-
log("Internal sub state after merge:", finalMergedState);
|
|
61
|
-
await sub.edit(finalMergedState);
|
|
62
|
-
this.log(sub.address);
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
//@ts-expect-error
|
|
66
|
-
e.details = { ...e.details, editOptions, address: args.address };
|
|
67
|
-
console.error(e);
|
|
68
|
-
await plebbit.destroy();
|
|
69
|
-
this.exit(1);
|
|
70
|
-
}
|
|
71
|
-
await plebbit.destroy();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from "../../base-command.js";
|
|
2
|
-
export default class Get extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static args: {
|
|
6
|
-
address: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
-
};
|
|
8
|
-
run(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Args } from "@oclif/core";
|
|
2
|
-
import { BaseCommand } from "../../base-command.js";
|
|
3
|
-
import * as remeda from "remeda";
|
|
4
|
-
export default class Get extends BaseCommand {
|
|
5
|
-
static description = "Fetch a local or remote subplebbit, and print its json in the terminal";
|
|
6
|
-
static examples = [
|
|
7
|
-
"plebbit subplebbit get plebmusic.eth",
|
|
8
|
-
"plebbit subplebbit get 12D3KooWG3XbzoVyAE6Y9vHZKF64Yuuu4TjdgQKedk14iYmTEPWu"
|
|
9
|
-
];
|
|
10
|
-
static args = {
|
|
11
|
-
address: Args.string({
|
|
12
|
-
name: "address",
|
|
13
|
-
required: true,
|
|
14
|
-
description: "Address of the subplebbit address to fetch"
|
|
15
|
-
})
|
|
16
|
-
};
|
|
17
|
-
async run() {
|
|
18
|
-
const { args, flags } = await this.parse(Get);
|
|
19
|
-
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
|
|
20
|
-
try {
|
|
21
|
-
const sub = await plebbit.getSubplebbit({ address: args.address });
|
|
22
|
-
const subJson = JSON.parse(JSON.stringify(sub));
|
|
23
|
-
this.logJson({ posts: subJson.posts, ...remeda.omit(subJson, ["posts"]) }); // make sure posts is printed first, because most users won't look at it
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
console.error(e);
|
|
27
|
-
await plebbit.destroy();
|
|
28
|
-
this.exit(1);
|
|
29
|
-
}
|
|
30
|
-
await plebbit.destroy();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from "../../base-command.js";
|
|
2
|
-
export default class List extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
-
};
|
|
8
|
-
run(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Flags } from "@oclif/core";
|
|
2
|
-
import { BaseCommand } from "../../base-command.js";
|
|
3
|
-
import { EOL } from "os";
|
|
4
|
-
import { getPlebbitLogger } from "../../../util.js";
|
|
5
|
-
import { printTable } from "@oclif/table";
|
|
6
|
-
export default class List extends BaseCommand {
|
|
7
|
-
static description = "List your subplebbits";
|
|
8
|
-
static examples = ["plebbit subplebbit list -q", "plebbit subplebbit list"];
|
|
9
|
-
static flags = {
|
|
10
|
-
quiet: Flags.boolean({ char: "q", summary: "Only display subplebbit addresses" })
|
|
11
|
-
};
|
|
12
|
-
async run() {
|
|
13
|
-
const { flags } = await this.parse(List);
|
|
14
|
-
const log = (await getPlebbitLogger())("plebbit-cli:commands:subplebbit:list");
|
|
15
|
-
log(`flags: `, flags);
|
|
16
|
-
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
|
|
17
|
-
const subs = plebbit.subplebbits;
|
|
18
|
-
if (flags.quiet) {
|
|
19
|
-
this.log(subs.join(EOL));
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
const subsWithStarted = await Promise.all(subs.map(async (subAddress) => {
|
|
23
|
-
const subInstance = await plebbit.createSubplebbit({ address: subAddress });
|
|
24
|
-
return { address: subInstance.address, started: subInstance.started };
|
|
25
|
-
}));
|
|
26
|
-
printTable({ data: subsWithStarted, sort: { started: "desc" } });
|
|
27
|
-
}
|
|
28
|
-
await plebbit.destroy();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from "../../base-command.js";
|
|
2
|
-
export default class Start extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static strict: boolean;
|
|
5
|
-
static args: {
|
|
6
|
-
addresses: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
-
};
|
|
8
|
-
static examples: string[];
|
|
9
|
-
run(): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getPlebbitLogger } from "../../../util.js";
|
|
2
|
-
import { BaseCommand } from "../../base-command.js";
|
|
3
|
-
import { Args } from "@oclif/core";
|
|
4
|
-
export default class Start extends BaseCommand {
|
|
5
|
-
static description = "Start a subplebbit";
|
|
6
|
-
static strict = false; // To allow for variable length arguments
|
|
7
|
-
static args = {
|
|
8
|
-
addresses: Args.string({
|
|
9
|
-
name: "addresses", // name of arg to show in help and reference with args[name]
|
|
10
|
-
required: true,
|
|
11
|
-
description: "Addresses of subplebbits to start. Separated by space"
|
|
12
|
-
})
|
|
13
|
-
};
|
|
14
|
-
static examples = [
|
|
15
|
-
"plebbit subplebbit start plebbit.eth",
|
|
16
|
-
"plebbit subplebbit start 12D3KooWG3XbzoVyAE6Y9vHZKF64Yuuu4TjdgQKedk14iYmTEPWu"
|
|
17
|
-
];
|
|
18
|
-
async run() {
|
|
19
|
-
const { argv, flags } = await this.parse(Start);
|
|
20
|
-
const addresses = argv;
|
|
21
|
-
const log = (await getPlebbitLogger())("plebbit-cli:commands:subplebbit:start");
|
|
22
|
-
log(`addresses: `, addresses);
|
|
23
|
-
log(`flags: `, flags);
|
|
24
|
-
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
|
|
25
|
-
for (const address of addresses) {
|
|
26
|
-
try {
|
|
27
|
-
const sub = await plebbit.createSubplebbit({ address });
|
|
28
|
-
await sub.start();
|
|
29
|
-
this.log(address);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
//@ts-expect-error
|
|
33
|
-
e.details = { ...e.details, address };
|
|
34
|
-
console.error(e);
|
|
35
|
-
await plebbit.destroy();
|
|
36
|
-
this.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
await plebbit.destroy();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from "../../base-command.js";
|
|
2
|
-
export default class Stop extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static strict: boolean;
|
|
5
|
-
static args: {
|
|
6
|
-
addresses: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
-
};
|
|
8
|
-
static examples: string[];
|
|
9
|
-
run(): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getPlebbitLogger } from "../../../util.js";
|
|
2
|
-
import { BaseCommand } from "../../base-command.js";
|
|
3
|
-
import { Args } from "@oclif/core";
|
|
4
|
-
export default class Stop extends BaseCommand {
|
|
5
|
-
static description = "Stop a subplebbit. The subplebbit will not publish or receive any publications until it is started again.";
|
|
6
|
-
static strict = false; // To allow for variable length arguments
|
|
7
|
-
static args = {
|
|
8
|
-
addresses: Args.string({
|
|
9
|
-
name: "addresses",
|
|
10
|
-
required: true,
|
|
11
|
-
description: "Addresses of subplebbits to stop. Separated by space"
|
|
12
|
-
})
|
|
13
|
-
};
|
|
14
|
-
static examples = [
|
|
15
|
-
"plebbit subplebbit stop plebbit.eth",
|
|
16
|
-
"plebbit subplebbit stop Qmb99crTbSUfKXamXwZBe829Vf6w5w5TktPkb6WstC9RFW"
|
|
17
|
-
];
|
|
18
|
-
async run() {
|
|
19
|
-
const { argv, flags } = await this.parse(Stop);
|
|
20
|
-
const log = (await getPlebbitLogger())("plebbit-cli:commands:subplebbit:stop");
|
|
21
|
-
log(`addresses: `, argv);
|
|
22
|
-
log(`flags: `, flags);
|
|
23
|
-
const addresses = argv;
|
|
24
|
-
if (!Array.isArray(addresses))
|
|
25
|
-
this.error(`Failed to parse addresses correctly (${addresses})`);
|
|
26
|
-
const plebbit = await this._connectToPlebbitRpc(flags.plebbitRpcUrl.toString());
|
|
27
|
-
for (const address of addresses) {
|
|
28
|
-
try {
|
|
29
|
-
const sub = await plebbit.createSubplebbit({ address });
|
|
30
|
-
await sub.stop(); // should stop the original subplebbit instance from running
|
|
31
|
-
this.log(address);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
//@ts-expect-error
|
|
35
|
-
e.details = { ...e.details, address };
|
|
36
|
-
console.error(e);
|
|
37
|
-
await plebbit.destroy();
|
|
38
|
-
this.exit(1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
await plebbit.destroy();
|
|
42
|
-
}
|
|
43
|
-
}
|
package/dist/seeder.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/seeder.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// import lodash from "lodash";
|
|
2
|
-
// import Logger from "@plebbit/plebbit-logger";
|
|
3
|
-
// import { Plebbit } from "@plebbit/plebbit-js/dist/node/plebbit";
|
|
4
|
-
// import { BasePages } from "@plebbit/plebbit-js/dist/node/pages";
|
|
5
|
-
// import { Comment } from "@plebbit/plebbit-js/dist/node/comment";
|
|
6
|
-
// import assert from "assert";
|
|
7
|
-
// //@ts-expect-error
|
|
8
|
-
// import { CID } from "ipfs-http-client";
|
|
9
|
-
// import { Subplebbit } from "@plebbit/plebbit-js/dist/node/subplebbit/subplebbit";
|
|
10
|
-
export {};
|
|
11
|
-
// async function _loadAllPages(pageCid: string, pagesInstance: BasePages): Promise<Comment[]> {
|
|
12
|
-
// const log = Logger("plebbit-cli:server:seed:_loadAllPages");
|
|
13
|
-
// try {
|
|
14
|
-
// let sortedCommentsPage = await pagesInstance.getPage(pageCid);
|
|
15
|
-
// let sortedComments: Comment[] = sortedCommentsPage.comments;
|
|
16
|
-
// while (sortedCommentsPage.nextCid) {
|
|
17
|
-
// sortedCommentsPage = await pagesInstance.getPage(sortedCommentsPage.nextCid);
|
|
18
|
-
// sortedComments = sortedComments.concat(sortedCommentsPage.comments);
|
|
19
|
-
// }
|
|
20
|
-
// return sortedComments;
|
|
21
|
-
// } catch (e) {
|
|
22
|
-
// log.error(`Failed to load page (${pageCid}) of sub (${pagesInstance._subplebbitAddress}) due to error:`, e);
|
|
23
|
-
// return [];
|
|
24
|
-
// }
|
|
25
|
-
// }
|
|
26
|
-
// const seededIpns: Record<string, { lastSeededAt?: number }> = {};
|
|
27
|
-
// async function _seedSub(sub: Subplebbit, pinnedCids: string[]) {
|
|
28
|
-
// const log = Logger("plebbit-cli:server:seed");
|
|
29
|
-
// if (sub.statsCid) await sub.plebbit.fetchCid(sub.statsCid); // Seed stats
|
|
30
|
-
// await sub.plebbit.pubsubSubscribe(sub.pubsubTopic || sub.address);
|
|
31
|
-
// // Load all pages
|
|
32
|
-
// if (sub.posts.pageCids) {
|
|
33
|
-
// const pagesLoaded = await Promise.all(Object.values(sub.posts.pageCids).map((pageCid) => _loadAllPages(pageCid, sub.posts)));
|
|
34
|
-
// // What if one of pages fail to load
|
|
35
|
-
// log.trace(`Loaded the newest pages of sub (${sub.address}) to seed`);
|
|
36
|
-
// const pageNames = Object.keys(sub.posts.pageCids);
|
|
37
|
-
// const loadedPagesWithNames = lodash.zipObject(pageNames, pagesLoaded);
|
|
38
|
-
// const allCidsToPin: string[] = [];
|
|
39
|
-
// if (loadedPagesWithNames["new"]) {
|
|
40
|
-
// // Fetch all comments CID
|
|
41
|
-
// allCidsToPin.push(...loadedPagesWithNames["new"].map((comment) => <string>comment.cid));
|
|
42
|
-
// // Seed IPNS
|
|
43
|
-
// for (const comment of loadedPagesWithNames["new"]) {
|
|
44
|
-
// assert(comment.ipnsName);
|
|
45
|
-
// if (seededIpns[comment.ipnsName]?.lastSeededAt !== comment.updatedAt) {
|
|
46
|
-
// try {
|
|
47
|
-
// await comment._clientsManager.fetchCommentUpdate(comment.ipnsName);
|
|
48
|
-
// seededIpns[comment.ipnsName] = { lastSeededAt: comment.updatedAt };
|
|
49
|
-
// log.trace(`Seeded comment (${comment.cid}) IPNS (${comment.ipnsName})`);
|
|
50
|
-
// } catch (e) {
|
|
51
|
-
// log.error(`Failed to seed comment (${comment.cid}) IPNS (${comment.ipnsName}) due to error`, e);
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
55
|
-
// }
|
|
56
|
-
// // Pin cids that are not already pinned
|
|
57
|
-
// const newCidsToPin = lodash.difference(lodash.uniq(allCidsToPin), pinnedCids).map((cidString) => CID.parse(cidString));
|
|
58
|
-
// if (newCidsToPin.length > 0) {
|
|
59
|
-
// log.trace(`Attempting to pin ${newCidsToPin.length} comments' cids from sub (${sub.address}): `, newCidsToPin);
|
|
60
|
-
// const defaultIpfsClient = Object.values(sub.plebbit.clients.ipfsClients)[0];
|
|
61
|
-
// assert(defaultIpfsClient);
|
|
62
|
-
// await defaultIpfsClient._client.pin.addAll(newCidsToPin);
|
|
63
|
-
// log.trace(`Pinned ${newCidsToPin.length} cids from sub (${sub.address})`);
|
|
64
|
-
// } else log.trace(`All ${lodash.uniq(allCidsToPin).length} cids from sub (${sub.address}) are pinned`);
|
|
65
|
-
// }
|
|
66
|
-
// }
|
|
67
|
-
// export async function seedSubplebbits(subAddresses: string[], plebbit: Plebbit) {
|
|
68
|
-
// const log = Logger("plebbit-cli:server:seed");
|
|
69
|
-
// log.trace("test"); // remove this line later
|
|
70
|
-
// for (const subAddress of subAddresses) {
|
|
71
|
-
// try {
|
|
72
|
-
// const sub = await plebbit.getSubplebbit(subAddress);
|
|
73
|
-
// log.trace(`Loaded the newest record of sub (${subAddress}) for seeding`);
|
|
74
|
-
// const defaultIpfsClient = Object.values(sub.plebbit.clients.ipfsClients)[0];
|
|
75
|
-
// assert(defaultIpfsClient);
|
|
76
|
-
// const pinnedCids: string[] = (await defaultIpfsClient._client.pin.ls()).map((pin) => pin.cid.toString());
|
|
77
|
-
// await _seedSub(sub, pinnedCids);
|
|
78
|
-
// } catch (e) {
|
|
79
|
-
// log.error(`Failed to load and seed sub (${subAddress}):`, String(e));
|
|
80
|
-
// }
|
|
81
|
-
// }
|
|
82
|
-
// log(`Finished this round of seeding. Will seed again later`);
|
|
83
|
-
// }
|