web-dc-api 0.1.5 → 0.1.6
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/dist/cjs/index.js +1 -1
- package/dist/dc.min.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +934 -878
- package/package.json +4 -8
- package/dist/cjs/helia-core-B1Xqha7a.js +0 -1
- package/dist/cjs/helia-core-D8Uv1KjQ.js +0 -1
- package/dist/cjs/polkadot-api-7PhQf3ws.js +0 -1
- package/dist/cjs/polkadot-api-CtrJVWuZ.js +0 -1
- package/dist/esm/chunks/helia-core-BxMqyK2Y.js +0 -1
- package/dist/esm/chunks/helia-core-DMXRpcO-.js +0 -1
- package/dist/esm/chunks/polkadot-api-5Y9Bw8VT.js +0 -1
- package/dist/esm/chunks/polkadot-api-D69Ioun_.js +0 -1
- package/lib/common/blowfish/block.ts +0 -259
- package/lib/common/blowfish/cipher.ts +0 -144
- package/lib/common/blowfish/const.ts +0 -195
- package/lib/common/chain.ts +0 -469
- package/lib/common/commonclient.ts +0 -202
- package/lib/common/constants.ts +0 -55
- package/lib/common/dc-key/ed25519.ts +0 -343
- package/lib/common/dc-key/keyManager.ts +0 -424
- package/lib/common/dcapi.ts +0 -98
- package/lib/common/dcutil.ts +0 -627
- package/lib/common/define.ts +0 -70
- package/lib/common/error.ts +0 -67
- package/lib/common/grpc-dc.ts +0 -104
- package/lib/common/module-system.ts +0 -184
- package/lib/common/service-worker.ts +0 -234
- package/lib/common/types/types.ts +0 -344
- package/lib/dc.ts +0 -701
- package/lib/implements/account/client.ts +0 -185
- package/lib/implements/account/manager.ts +0 -683
- package/lib/implements/aiproxy/client.ts +0 -357
- package/lib/implements/aiproxy/manager.ts +0 -670
- package/lib/implements/cache/client.ts +0 -105
- package/lib/implements/cache/manager.ts +0 -127
- package/lib/implements/comment/client.ts +0 -982
- package/lib/implements/comment/manager.ts +0 -1151
- package/lib/implements/dc/client.ts +0 -51
- package/lib/implements/dc/manager.ts +0 -33
- package/lib/implements/file/client.ts +0 -253
- package/lib/implements/file/file-cache-manager.ts +0 -142
- package/lib/implements/file/manager.ts +0 -1240
- package/lib/implements/file/seekableFileStream.ts +0 -344
- package/lib/implements/file/streamwriter.ts +0 -322
- package/lib/implements/keyvalue/client.ts +0 -376
- package/lib/implements/keyvalue/manager.ts +0 -759
- package/lib/implements/message/client.ts +0 -250
- package/lib/implements/message/manager.ts +0 -215
- package/lib/implements/threaddb/cbor/coding.ts +0 -62
- package/lib/implements/threaddb/cbor/event.ts +0 -336
- package/lib/implements/threaddb/cbor/node.ts +0 -542
- package/lib/implements/threaddb/cbor/record.ts +0 -398
- package/lib/implements/threaddb/common/AsyncMutex.ts +0 -24
- package/lib/implements/threaddb/common/addrinfo.ts +0 -135
- package/lib/implements/threaddb/common/dispatcher.ts +0 -81
- package/lib/implements/threaddb/common/idbstore-adapter.ts +0 -260
- package/lib/implements/threaddb/common/json-patcher.ts +0 -204
- package/lib/implements/threaddb/common/key.ts +0 -290
- package/lib/implements/threaddb/common/level-adapter.ts +0 -235
- package/lib/implements/threaddb/common/lineReader.ts +0 -79
- package/lib/implements/threaddb/common/logstore.ts +0 -215
- package/lib/implements/threaddb/common/transformed-datastore.ts +0 -308
- package/lib/implements/threaddb/core/app.ts +0 -206
- package/lib/implements/threaddb/core/core.ts +0 -230
- package/lib/implements/threaddb/core/db.ts +0 -249
- package/lib/implements/threaddb/core/event.ts +0 -54
- package/lib/implements/threaddb/core/head.ts +0 -89
- package/lib/implements/threaddb/core/identity.ts +0 -171
- package/lib/implements/threaddb/core/logstore.ts +0 -137
- package/lib/implements/threaddb/core/options.ts +0 -14
- package/lib/implements/threaddb/core/record.ts +0 -54
- package/lib/implements/threaddb/db/collection.ts +0 -1910
- package/lib/implements/threaddb/db/db.ts +0 -698
- package/lib/implements/threaddb/db/json2Query.ts +0 -192
- package/lib/implements/threaddb/db/query.ts +0 -524
- package/lib/implements/threaddb/dbclient.ts +0 -543
- package/lib/implements/threaddb/dbmanager.ts +0 -1906
- package/lib/implements/threaddb/lsstoreds/addr_book.ts +0 -549
- package/lib/implements/threaddb/lsstoreds/cache.ts +0 -36
- package/lib/implements/threaddb/lsstoreds/cyclic_batch.ts +0 -87
- package/lib/implements/threaddb/lsstoreds/global.ts +0 -151
- package/lib/implements/threaddb/lsstoreds/headbook.ts +0 -373
- package/lib/implements/threaddb/lsstoreds/keybook.ts +0 -297
- package/lib/implements/threaddb/lsstoreds/logstore.ts +0 -29
- package/lib/implements/threaddb/lsstoreds/metadata.ts +0 -223
- package/lib/implements/threaddb/net/define.ts +0 -149
- package/lib/implements/threaddb/net/grpcClient.ts +0 -589
- package/lib/implements/threaddb/net/grpcserver.ts +0 -146
- package/lib/implements/threaddb/net/net.ts +0 -2047
- package/lib/implements/threaddb/pb/lstore.proto +0 -38
- package/lib/implements/threaddb/pb/lstore.ts +0 -393
- package/lib/implements/threaddb/pb/lstore_pb.d.ts +0 -433
- package/lib/implements/threaddb/pb/lstore_pb.js +0 -1085
- package/lib/implements/threaddb/pb/net.proto +0 -194
- package/lib/implements/threaddb/pb/net_pb.d.ts +0 -2349
- package/lib/implements/threaddb/pb/net_pb.js +0 -5525
- package/lib/implements/threaddb/pb/proto-custom-types.ts +0 -212
- package/lib/implements/util/client.ts +0 -72
- package/lib/implements/util/manager.ts +0 -146
- package/lib/implements/wallet/manager.ts +0 -671
- package/lib/index.ts +0 -57
- package/lib/interfaces/DCContext.ts +0 -51
- package/lib/interfaces/aiproxy-interface.ts +0 -145
- package/lib/interfaces/auth-interface.ts +0 -118
- package/lib/interfaces/cache-interface.ts +0 -22
- package/lib/interfaces/client-interface.ts +0 -11
- package/lib/interfaces/comment-interface.ts +0 -167
- package/lib/interfaces/components/news-component.ts +0 -0
- package/lib/interfaces/database-interface.ts +0 -169
- package/lib/interfaces/file-interface.ts +0 -120
- package/lib/interfaces/index.ts +0 -10
- package/lib/interfaces/keyvalue-interface.ts +0 -156
- package/lib/interfaces/message-interface.ts +0 -22
- package/lib/interfaces/util-interface.ts +0 -31
- package/lib/modules/aiproxy-module.ts +0 -246
- package/lib/modules/auth-module.ts +0 -753
- package/lib/modules/cache-module.ts +0 -99
- package/lib/modules/client-module.ts +0 -71
- package/lib/modules/comment-module.ts +0 -429
- package/lib/modules/components/news-components.ts +0 -390
- package/lib/modules/database-module.ts +0 -598
- package/lib/modules/file-module.ts +0 -291
- package/lib/modules/index.ts +0 -13
- package/lib/modules/keyvalue-module.ts +0 -379
- package/lib/modules/message-module.ts +0 -107
- package/lib/modules/util-module.ts +0 -148
- package/lib/polyfills/process-env-browser.ts +0 -1
- package/lib/proto/datasource.ts +0 -93
- package/lib/proto/dcnet.proto +0 -1601
- package/lib/proto/dcnet_proto.d.ts +0 -22857
- package/lib/proto/dcnet_proto.js +0 -55204
- package/lib/proto/dcnet_proto_sparse.js +0 -55166
- package/lib/proto/oidfetch.proto +0 -25
- package/lib/proto/oidfetch_proto.d.ts +0 -585
- package/lib/proto/oidfetch_proto.js +0 -1247
- package/lib/serverless/babel-browser.ts +0 -39
- package/lib/serverless/base_entity.ts +0 -78
- package/lib/serverless/base_repository.ts +0 -414
- package/lib/serverless/browser_schema_extractor.ts +0 -283
- package/lib/serverless/decorator_factory.ts +0 -322
- package/lib/util/BrowserLineReader.ts +0 -73
- package/lib/util/base64.ts +0 -105
- package/lib/util/bcrypt.ts +0 -206
- package/lib/util/curve25519Encryption.ts +0 -418
- package/lib/util/dccrypt.ts +0 -73
- package/lib/util/logger.ts +0 -104
- package/lib/util/utils.ts +0 -289
|
@@ -1,982 +0,0 @@
|
|
|
1
|
-
import { Libp2pGrpcClient } from "grpc-libp2p-client";
|
|
2
|
-
import type { Client } from "../../common/dcapi";
|
|
3
|
-
import { dcnet } from "../../proto/dcnet_proto";
|
|
4
|
-
import { DataSource } from "../../proto/datasource";
|
|
5
|
-
import { HeliaLibp2p } from "helia";
|
|
6
|
-
import { unixfs } from "@helia/unixfs";
|
|
7
|
-
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
8
|
-
import { FileManager } from "../file/manager";
|
|
9
|
-
import { Errors } from "../../common/error";
|
|
10
|
-
import { DCContext } from "../../../lib/interfaces/DCContext";
|
|
11
|
-
import { Libp2p } from "@libp2p/interface";
|
|
12
|
-
|
|
13
|
-
export class CommentClient {
|
|
14
|
-
client: Client;
|
|
15
|
-
dcNodeClient: HeliaLibp2p<Libp2p>;
|
|
16
|
-
context:DCContext
|
|
17
|
-
|
|
18
|
-
constructor(
|
|
19
|
-
dcClient: Client,
|
|
20
|
-
dcNodeClient: HeliaLibp2p<Libp2p>,
|
|
21
|
-
context:DCContext
|
|
22
|
-
) {
|
|
23
|
-
this.client = dcClient;
|
|
24
|
-
this.dcNodeClient = dcNodeClient;
|
|
25
|
-
this.context = context;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async addUserOffChainSpace(
|
|
29
|
-
pubkey: string,
|
|
30
|
-
blockheight: number,
|
|
31
|
-
peerid: string,
|
|
32
|
-
signature: Uint8Array
|
|
33
|
-
): Promise<boolean> {
|
|
34
|
-
console.log("AddUserOffChainSpace2 pubkey", pubkey);
|
|
35
|
-
console.log("AddUserOffChainSpace2 blockheight", blockheight);
|
|
36
|
-
console.log("AddUserOffChainSpace2 peerid", peerid);
|
|
37
|
-
console.log("AddUserOffChainSpace2 signature", signature);
|
|
38
|
-
const message = new dcnet.pb.AddUserOffChainSpaceRequest({});
|
|
39
|
-
message.userPubkey = new TextEncoder().encode(pubkey);
|
|
40
|
-
message.blockheight = blockheight;
|
|
41
|
-
message.peerid = new TextEncoder().encode(peerid);
|
|
42
|
-
message.signature = signature;
|
|
43
|
-
const messageBytes =
|
|
44
|
-
dcnet.pb.AddUserOffChainSpaceRequest.encode(message).finish();
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
48
|
-
this.client.p2pNode,
|
|
49
|
-
this.client.peerAddr,
|
|
50
|
-
this.client.token,
|
|
51
|
-
this.client.protocol
|
|
52
|
-
);
|
|
53
|
-
const reply = await grpcClient.unaryCall(
|
|
54
|
-
"/dcnet.pb.Service/AddUserOffChainSpace",
|
|
55
|
-
messageBytes,
|
|
56
|
-
30000
|
|
57
|
-
);
|
|
58
|
-
console.log("AddUserOffChainSpace2 reply", reply);
|
|
59
|
-
const decoded = dcnet.pb.AddUserOffChainSpaceReply.decode(reply);
|
|
60
|
-
console.log("AddUserOffChainSpace2 decoded", decoded);
|
|
61
|
-
return true;
|
|
62
|
-
} catch (error: any) {
|
|
63
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
64
|
-
// try to get token
|
|
65
|
-
const token = await this.client.GetToken(
|
|
66
|
-
this.context.appInfo.appId || "",
|
|
67
|
-
this.context.getPublicKey().string(),
|
|
68
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
69
|
-
return this.context.sign(payload);
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
if (!token) {
|
|
73
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
74
|
-
}
|
|
75
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
76
|
-
this.client.p2pNode,
|
|
77
|
-
this.client.peerAddr,
|
|
78
|
-
this.client.token,
|
|
79
|
-
this.client.protocol
|
|
80
|
-
);
|
|
81
|
-
const reply = await grpcClient.unaryCall(
|
|
82
|
-
"/dcnet.pb.Service/AddUserOffChainSpace",
|
|
83
|
-
messageBytes,
|
|
84
|
-
30000
|
|
85
|
-
);
|
|
86
|
-
console.log("AddUserOffChainSpace2 reply", reply);
|
|
87
|
-
const decoded = dcnet.pb.AddUserOffChainSpaceReply.decode(reply);
|
|
88
|
-
console.log("AddUserOffChainSpace2 decoded", decoded);
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
console.error("AddUserOffChainSpace error:", error);
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
async getUserOffChainUsedInfo(
|
|
98
|
-
vaccount: string = ""
|
|
99
|
-
): Promise<dcnet.pb.GetUserOffChainUsedInfoReply> {
|
|
100
|
-
const message = new dcnet.pb.GetUserOffChainUsedInfoRequest({});
|
|
101
|
-
message.vaccount = new TextEncoder().encode(vaccount);
|
|
102
|
-
const messageBytes =
|
|
103
|
-
dcnet.pb.GetUserOffChainUsedInfoRequest.encode(message).finish();
|
|
104
|
-
try {
|
|
105
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
106
|
-
this.client.p2pNode,
|
|
107
|
-
this.client.peerAddr,
|
|
108
|
-
this.client.token,
|
|
109
|
-
this.client.protocol
|
|
110
|
-
);
|
|
111
|
-
const reply = await grpcClient.unaryCall(
|
|
112
|
-
"/dcnet.pb.Service/GetUserOffChainUsedInfo",
|
|
113
|
-
messageBytes,
|
|
114
|
-
30000
|
|
115
|
-
);
|
|
116
|
-
const decoded = dcnet.pb.GetUserOffChainUsedInfoReply.decode(reply);
|
|
117
|
-
return decoded;
|
|
118
|
-
} catch (error: any) {
|
|
119
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
120
|
-
// try to get token
|
|
121
|
-
const token = await this.client.GetToken(
|
|
122
|
-
this.context.appInfo.appId || "",
|
|
123
|
-
this.context.getPublicKey().string(),
|
|
124
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
125
|
-
return this.context.sign(payload);
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
if (!token) {
|
|
129
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
130
|
-
}
|
|
131
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
132
|
-
this.client.p2pNode,
|
|
133
|
-
this.client.peerAddr,
|
|
134
|
-
this.client.token,
|
|
135
|
-
this.client.protocol
|
|
136
|
-
);
|
|
137
|
-
const reply = await grpcClient.unaryCall(
|
|
138
|
-
"/dcnet.pb.Service/GetUserOffChainUsedInfo",
|
|
139
|
-
messageBytes,
|
|
140
|
-
30000
|
|
141
|
-
);
|
|
142
|
-
const decoded = dcnet.pb.GetUserOffChainUsedInfoReply.decode(reply);
|
|
143
|
-
console.log("GetUserOffChainUsedInfo decoded", decoded);
|
|
144
|
-
return decoded;
|
|
145
|
-
}
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async addUserOffChainOpTimes(
|
|
152
|
-
pubkey: string,
|
|
153
|
-
blockheight: number,
|
|
154
|
-
peerid: string,
|
|
155
|
-
times: number,
|
|
156
|
-
signature: Uint8Array,
|
|
157
|
-
vaccount: string
|
|
158
|
-
): Promise<boolean> {
|
|
159
|
-
const message = new dcnet.pb.AddUserOffChainOpTimesRequest({});
|
|
160
|
-
|
|
161
|
-
message.userPubkey = new TextEncoder().encode(pubkey);
|
|
162
|
-
message.blockheight = blockheight;
|
|
163
|
-
message.peerid = new TextEncoder().encode(peerid);
|
|
164
|
-
message.times = times;
|
|
165
|
-
message.vaccount = new TextEncoder().encode(vaccount);
|
|
166
|
-
message.signature = signature;
|
|
167
|
-
const messageBytes =
|
|
168
|
-
dcnet.pb.AddUserOffChainOpTimesRequest.encode(message).finish();
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
172
|
-
this.client.p2pNode,
|
|
173
|
-
this.client.peerAddr,
|
|
174
|
-
this.client.token,
|
|
175
|
-
this.client.protocol
|
|
176
|
-
);
|
|
177
|
-
const reply = await grpcClient.unaryCall(
|
|
178
|
-
"/dcnet.pb.Service/AddUserOffChainOpTimes",
|
|
179
|
-
messageBytes,
|
|
180
|
-
30000
|
|
181
|
-
);
|
|
182
|
-
const decoded = dcnet.pb.AddUserOffChainOpTimesReply.decode(reply);
|
|
183
|
-
return true;
|
|
184
|
-
} catch (error: any) {
|
|
185
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
186
|
-
// try to get token
|
|
187
|
-
const token = await this.client.GetToken(
|
|
188
|
-
this.context.appInfo.appId || "",
|
|
189
|
-
this.context.getPublicKey().string(),
|
|
190
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
191
|
-
return this.context.sign(payload);
|
|
192
|
-
}
|
|
193
|
-
);
|
|
194
|
-
if (!token) {
|
|
195
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
196
|
-
}
|
|
197
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
198
|
-
this.client.p2pNode,
|
|
199
|
-
this.client.peerAddr,
|
|
200
|
-
this.client.token,
|
|
201
|
-
this.client.protocol
|
|
202
|
-
);
|
|
203
|
-
const reply = await grpcClient.unaryCall(
|
|
204
|
-
"/dcnet.pb.Service/AddUserOffChainOpTimes",
|
|
205
|
-
messageBytes,
|
|
206
|
-
30000
|
|
207
|
-
);
|
|
208
|
-
const decoded = dcnet.pb.AddUserOffChainOpTimesReply.decode(reply);
|
|
209
|
-
console.log("AddUserOffChainSpace2 decoded", decoded);
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
async addThemeObj(
|
|
220
|
-
appId: string,
|
|
221
|
-
theme: string,
|
|
222
|
-
blockheight: number,
|
|
223
|
-
commentSpace: number,
|
|
224
|
-
userPubkey: string,
|
|
225
|
-
openFlag: number,
|
|
226
|
-
signature: Uint8Array
|
|
227
|
-
): Promise<number> {
|
|
228
|
-
const message = new dcnet.pb.AddThemeObjRequest({});
|
|
229
|
-
message.theme = new TextEncoder().encode(theme);
|
|
230
|
-
message.appId = new TextEncoder().encode(appId);
|
|
231
|
-
message.blockheight = blockheight;
|
|
232
|
-
message.commentSpace = commentSpace;
|
|
233
|
-
message.userPubkey = new TextEncoder().encode(userPubkey);
|
|
234
|
-
message.openFlag = openFlag;
|
|
235
|
-
message.signature = signature;
|
|
236
|
-
const messageBytes = dcnet.pb.AddThemeObjRequest.encode(message).finish();
|
|
237
|
-
try {
|
|
238
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
239
|
-
this.client.p2pNode,
|
|
240
|
-
this.client.peerAddr,
|
|
241
|
-
this.client.token,
|
|
242
|
-
this.client.protocol
|
|
243
|
-
);
|
|
244
|
-
const reply = await grpcClient.unaryCall(
|
|
245
|
-
"/dcnet.pb.Service/AddThemeObj",
|
|
246
|
-
messageBytes,
|
|
247
|
-
30000
|
|
248
|
-
);
|
|
249
|
-
console.log("AddThemeObj reply", reply);
|
|
250
|
-
const decoded = dcnet.pb.AddThemeObjReply.decode(reply);
|
|
251
|
-
console.log("AddThemeObj decoded", decoded);
|
|
252
|
-
return decoded.flag;
|
|
253
|
-
} catch (error: any) {
|
|
254
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
255
|
-
// try to get token
|
|
256
|
-
const token = await this.client.GetToken(
|
|
257
|
-
appId || "",
|
|
258
|
-
userPubkey,
|
|
259
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
260
|
-
return this.context.sign(payload);
|
|
261
|
-
}
|
|
262
|
-
);
|
|
263
|
-
if (!token) {
|
|
264
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
265
|
-
}
|
|
266
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
267
|
-
this.client.p2pNode,
|
|
268
|
-
this.client.peerAddr,
|
|
269
|
-
this.client.token,
|
|
270
|
-
this.client.protocol
|
|
271
|
-
);
|
|
272
|
-
const reply = await grpcClient.unaryCall(
|
|
273
|
-
"/dcnet.pb.Service/AddThemeObj",
|
|
274
|
-
messageBytes,
|
|
275
|
-
30000
|
|
276
|
-
);
|
|
277
|
-
console.log("AddThemeObj reply", reply);
|
|
278
|
-
const decoded = dcnet.pb.AddThemeObjReply.decode(reply);
|
|
279
|
-
console.log("AddThemeObj decoded", decoded);
|
|
280
|
-
return decoded.flag;
|
|
281
|
-
}
|
|
282
|
-
console.error("AddThemeObj error:", error);
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
async deleteThemeObj(
|
|
291
|
-
appId: string,
|
|
292
|
-
theme: string,
|
|
293
|
-
blockheight: number,
|
|
294
|
-
userPubkey: string,
|
|
295
|
-
signature: Uint8Array
|
|
296
|
-
): Promise<number> {
|
|
297
|
-
const message = new dcnet.pb.DeleteThemeObjRequest({});
|
|
298
|
-
message.theme = new TextEncoder().encode(theme);
|
|
299
|
-
message.appId = new TextEncoder().encode(appId);
|
|
300
|
-
message.blockheight = blockheight;
|
|
301
|
-
message.userPubkey = new TextEncoder().encode(userPubkey);
|
|
302
|
-
message.signature = signature;
|
|
303
|
-
const messageBytes = dcnet.pb.DeleteThemeObjRequest.encode(message).finish();
|
|
304
|
-
try {
|
|
305
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
306
|
-
this.client.p2pNode,
|
|
307
|
-
this.client.peerAddr,
|
|
308
|
-
this.client.token,
|
|
309
|
-
this.client.protocol
|
|
310
|
-
);
|
|
311
|
-
const reply = await grpcClient.unaryCall(
|
|
312
|
-
"/dcnet.pb.Service/DeleteThemeObj",
|
|
313
|
-
messageBytes,
|
|
314
|
-
30000
|
|
315
|
-
);
|
|
316
|
-
console.log("DeleteThemeObj reply", reply);
|
|
317
|
-
const decoded = dcnet.pb.DeleteThemeObjReply.decode(reply);
|
|
318
|
-
console.log("DeleteThemeObj decoded", decoded);
|
|
319
|
-
return decoded.flag;
|
|
320
|
-
} catch (error: any) {
|
|
321
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
322
|
-
// try to get token
|
|
323
|
-
const token = await this.client.GetToken(
|
|
324
|
-
appId || "",
|
|
325
|
-
userPubkey,
|
|
326
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
327
|
-
return this.context.sign(payload);
|
|
328
|
-
}
|
|
329
|
-
);
|
|
330
|
-
if (!token) {
|
|
331
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
332
|
-
}
|
|
333
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
334
|
-
this.client.p2pNode,
|
|
335
|
-
this.client.peerAddr,
|
|
336
|
-
this.client.token,
|
|
337
|
-
this.client.protocol
|
|
338
|
-
);
|
|
339
|
-
const reply = await grpcClient.unaryCall(
|
|
340
|
-
"/dcnet.pb.Service/DeleteThemeObj",
|
|
341
|
-
messageBytes,
|
|
342
|
-
30000
|
|
343
|
-
);
|
|
344
|
-
console.log("DeleteThemeObj reply", reply);
|
|
345
|
-
const decoded = dcnet.pb.DeleteThemeObjReply.decode(reply);
|
|
346
|
-
console.log("DeleteThemeObj decoded", decoded);
|
|
347
|
-
return decoded.flag;
|
|
348
|
-
}
|
|
349
|
-
console.error("DeleteThemeObj error:", error);
|
|
350
|
-
throw error;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
async addThemeSpace(
|
|
355
|
-
appId: string,
|
|
356
|
-
theme: string,
|
|
357
|
-
blockheight: number,
|
|
358
|
-
addSpace: number,
|
|
359
|
-
userPubkey: string,
|
|
360
|
-
signature: Uint8Array
|
|
361
|
-
): Promise<number> {
|
|
362
|
-
const message = new dcnet.pb.AddThemeSpaceRequest({});
|
|
363
|
-
message.theme = new TextEncoder().encode(theme);
|
|
364
|
-
message.appId = new TextEncoder().encode(appId);
|
|
365
|
-
message.blockheight = blockheight;
|
|
366
|
-
message.addspace = addSpace;
|
|
367
|
-
message.userPubkey = new TextEncoder().encode(userPubkey);
|
|
368
|
-
message.signature = signature;
|
|
369
|
-
const messageBytes = dcnet.pb.AddThemeSpaceRequest.encode(message).finish();
|
|
370
|
-
try {
|
|
371
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
372
|
-
this.client.p2pNode,
|
|
373
|
-
this.client.peerAddr,
|
|
374
|
-
this.client.token,
|
|
375
|
-
this.client.protocol
|
|
376
|
-
);
|
|
377
|
-
const reply = await grpcClient.unaryCall(
|
|
378
|
-
"/dcnet.pb.Service/AddThemeSpace",
|
|
379
|
-
messageBytes,
|
|
380
|
-
30000
|
|
381
|
-
);
|
|
382
|
-
console.log("AddThemeSpace reply", reply);
|
|
383
|
-
const decoded = dcnet.pb.AddThemeSpaceReply.decode(reply);
|
|
384
|
-
console.log("AddThemeSpace decoded", decoded);
|
|
385
|
-
return decoded.flag;
|
|
386
|
-
} catch (error: any) {
|
|
387
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
388
|
-
// try to get token
|
|
389
|
-
const token = await this.client.GetToken(
|
|
390
|
-
appId || "",
|
|
391
|
-
userPubkey,
|
|
392
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
393
|
-
return this.context.sign(payload);
|
|
394
|
-
}
|
|
395
|
-
);
|
|
396
|
-
if (!token) {
|
|
397
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
398
|
-
}
|
|
399
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
400
|
-
this.client.p2pNode,
|
|
401
|
-
this.client.peerAddr,
|
|
402
|
-
this.client.token,
|
|
403
|
-
this.client.protocol
|
|
404
|
-
);
|
|
405
|
-
const reply = await grpcClient.unaryCall(
|
|
406
|
-
"/dcnet.pb.Service/AddThemeSpace",
|
|
407
|
-
messageBytes,
|
|
408
|
-
30000
|
|
409
|
-
);
|
|
410
|
-
console.log("AddThemeSpace reply", reply);
|
|
411
|
-
const decoded = dcnet.pb.AddThemeSpaceReply.decode(reply);
|
|
412
|
-
console.log("AddThemeSpace decoded", decoded);
|
|
413
|
-
return decoded.flag;
|
|
414
|
-
}
|
|
415
|
-
console.error("AddThemeSpace error:", error);
|
|
416
|
-
throw error;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async publishCommentToTheme(
|
|
421
|
-
appId: string,
|
|
422
|
-
theme: string,
|
|
423
|
-
themeAuthor: string,
|
|
424
|
-
blockheight: number,
|
|
425
|
-
userPubkey: string,
|
|
426
|
-
commentType: number,
|
|
427
|
-
commentCid: string,
|
|
428
|
-
comment: string,
|
|
429
|
-
refercommentkey: string,
|
|
430
|
-
signature: Uint8Array,
|
|
431
|
-
openFlag?: number
|
|
432
|
-
): Promise<number> {
|
|
433
|
-
const message = new dcnet.pb.PublishCommentToThemeRequest({});
|
|
434
|
-
message.theme = new TextEncoder().encode(theme);
|
|
435
|
-
message.appId = new TextEncoder().encode(appId);
|
|
436
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
437
|
-
message.blockheight = blockheight;
|
|
438
|
-
message.userPubkey = new TextEncoder().encode(userPubkey);
|
|
439
|
-
message.type = commentType;
|
|
440
|
-
message.commentCid = new TextEncoder().encode(commentCid);
|
|
441
|
-
message.comment = new TextEncoder().encode(comment);
|
|
442
|
-
message.commentSize = message.comment.length;
|
|
443
|
-
message.refercommentkey = new TextEncoder().encode(refercommentkey);
|
|
444
|
-
if (openFlag !== undefined) {
|
|
445
|
-
message.type = openFlag;
|
|
446
|
-
}
|
|
447
|
-
message.signature = signature;
|
|
448
|
-
const messageBytes =
|
|
449
|
-
dcnet.pb.PublishCommentToThemeRequest.encode(message).finish();
|
|
450
|
-
try {
|
|
451
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
452
|
-
this.client.p2pNode,
|
|
453
|
-
this.client.peerAddr,
|
|
454
|
-
this.client.token,
|
|
455
|
-
this.client.protocol
|
|
456
|
-
);
|
|
457
|
-
const reply = await grpcClient.unaryCall(
|
|
458
|
-
"/dcnet.pb.Service/PublishCommentToTheme",
|
|
459
|
-
messageBytes,
|
|
460
|
-
30000
|
|
461
|
-
);
|
|
462
|
-
console.log("PublishCommentToTheme reply", reply);
|
|
463
|
-
const decoded = dcnet.pb.PublishCommentToThemeReply.decode(reply);
|
|
464
|
-
console.log("PublishCommentToTheme decoded", decoded);
|
|
465
|
-
return decoded.flag;
|
|
466
|
-
} catch (error: any) {
|
|
467
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
468
|
-
// try to get token
|
|
469
|
-
const token = await this.client.GetToken(
|
|
470
|
-
appId || "",
|
|
471
|
-
userPubkey,
|
|
472
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
473
|
-
return this.context.sign(payload);
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
if (!token) {
|
|
477
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
478
|
-
}
|
|
479
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
480
|
-
this.client.p2pNode,
|
|
481
|
-
this.client.peerAddr,
|
|
482
|
-
this.client.token,
|
|
483
|
-
this.client.protocol
|
|
484
|
-
);
|
|
485
|
-
const reply = await grpcClient.unaryCall(
|
|
486
|
-
"/dcnet.pb.Service/PublishCommentToTheme",
|
|
487
|
-
messageBytes,
|
|
488
|
-
30000
|
|
489
|
-
);
|
|
490
|
-
console.log("PublishCommentToTheme reply", reply);
|
|
491
|
-
const decoded = dcnet.pb.PublishCommentToThemeReply.decode(reply);
|
|
492
|
-
console.log("PublishCommentToTheme decoded", decoded);
|
|
493
|
-
return decoded.flag;
|
|
494
|
-
}
|
|
495
|
-
console.error("PublishCommentToTheme error:", error);
|
|
496
|
-
throw error;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
async configThemeObjAuth(
|
|
503
|
-
theme: string,
|
|
504
|
-
appId: string,
|
|
505
|
-
themeAuthor: string,
|
|
506
|
-
blockHeight: number,
|
|
507
|
-
userPubkeyStr: string,
|
|
508
|
-
contentCid: string,
|
|
509
|
-
content: string,
|
|
510
|
-
contentSize: number,
|
|
511
|
-
type: number,
|
|
512
|
-
signature: Uint8Array,
|
|
513
|
-
vAccount?: string
|
|
514
|
-
): Promise<number> {
|
|
515
|
-
const message = new dcnet.pb.ConfigThemeObjAuthRequest({});
|
|
516
|
-
message.appId = new TextEncoder().encode(appId);
|
|
517
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
518
|
-
message.theme = new TextEncoder().encode(theme);
|
|
519
|
-
message.blockheight = blockHeight;
|
|
520
|
-
message.content = new TextEncoder().encode(content);
|
|
521
|
-
message.contentCid = new TextEncoder().encode(contentCid)
|
|
522
|
-
message.contentSize = contentSize
|
|
523
|
-
message.signature = signature;
|
|
524
|
-
message.type = type;
|
|
525
|
-
message.userPubkey = new TextEncoder().encode(userPubkeyStr);
|
|
526
|
-
if(vAccount){
|
|
527
|
-
message.vaccount = new TextEncoder().encode(vAccount)
|
|
528
|
-
}
|
|
529
|
-
const messageBytes = dcnet.pb.ConfigThemeObjAuthRequest.encode(message).finish();
|
|
530
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
531
|
-
this.client.p2pNode,
|
|
532
|
-
this.client.peerAddr,
|
|
533
|
-
this.client.token,
|
|
534
|
-
this.client.protocol
|
|
535
|
-
);
|
|
536
|
-
try {
|
|
537
|
-
const reply = await grpcClient.unaryCall(
|
|
538
|
-
"/dcnet.pb.Service/ConfigThemeObjAuth",
|
|
539
|
-
messageBytes,
|
|
540
|
-
30000
|
|
541
|
-
);
|
|
542
|
-
console.log("ConfigThemeObjAuth reply", reply);
|
|
543
|
-
const decoded = dcnet.pb.ConfigThemeObjAuthReply.decode(reply);
|
|
544
|
-
console.log("ConfigThemeObjAuth decoded", decoded);
|
|
545
|
-
return decoded.flag;
|
|
546
|
-
} catch (error: any) {
|
|
547
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
548
|
-
// try to get token
|
|
549
|
-
const token = await this.client.GetToken(
|
|
550
|
-
appId || "",
|
|
551
|
-
this.context.getPublicKey().string(),
|
|
552
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
553
|
-
return this.context.sign(payload);
|
|
554
|
-
}
|
|
555
|
-
);
|
|
556
|
-
if (!token) {
|
|
557
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
558
|
-
}
|
|
559
|
-
const reply = await grpcClient.unaryCall(
|
|
560
|
-
"/dcnet.pb.Service/ConfigThemeObjAuth",
|
|
561
|
-
messageBytes,
|
|
562
|
-
30000
|
|
563
|
-
);
|
|
564
|
-
console.log("ConfigThemeObjAuth reply", reply);
|
|
565
|
-
const decoded = dcnet.pb.GetUserCommentsReply.decode(reply);
|
|
566
|
-
console.log("ConfigThemeObjAuth decoded", decoded);
|
|
567
|
-
return decoded.flag;
|
|
568
|
-
}
|
|
569
|
-
console.error("ConfigThemeObjAuth error:", error);
|
|
570
|
-
throw error;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
async deleteSelfComment(
|
|
575
|
-
appId: string,
|
|
576
|
-
theme: string,
|
|
577
|
-
themeAuthor: string,
|
|
578
|
-
blockheight: number,
|
|
579
|
-
userPubkey: string,
|
|
580
|
-
commentCid: string,
|
|
581
|
-
commentBlockHeight: number,
|
|
582
|
-
signature: Uint8Array
|
|
583
|
-
): Promise<number> {
|
|
584
|
-
const message = new dcnet.pb.DeleteSelfCommentRequest({});
|
|
585
|
-
message.theme = new TextEncoder().encode(theme);
|
|
586
|
-
message.appId = new TextEncoder().encode(appId);
|
|
587
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
588
|
-
message.blockheight = blockheight;
|
|
589
|
-
message.userPubkey = new TextEncoder().encode(userPubkey);
|
|
590
|
-
message.commentCid = new TextEncoder().encode(commentCid);
|
|
591
|
-
message.commentBlockheight = commentBlockHeight;
|
|
592
|
-
message.signature = signature;
|
|
593
|
-
const messageBytes =
|
|
594
|
-
dcnet.pb.DeleteSelfCommentRequest.encode(message).finish();
|
|
595
|
-
try {
|
|
596
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
597
|
-
this.client.p2pNode,
|
|
598
|
-
this.client.peerAddr,
|
|
599
|
-
this.client.token,
|
|
600
|
-
this.client.protocol
|
|
601
|
-
);
|
|
602
|
-
const reply = await grpcClient.unaryCall(
|
|
603
|
-
"/dcnet.pb.Service/DeleteSelfComment",
|
|
604
|
-
messageBytes,
|
|
605
|
-
30000
|
|
606
|
-
);
|
|
607
|
-
console.log("DeleteSelfComment reply", reply);
|
|
608
|
-
const decoded = dcnet.pb.DeleteSelfCommentReply.decode(reply);
|
|
609
|
-
console.log("DeleteSelfComment decoded", decoded);
|
|
610
|
-
return decoded.flag;
|
|
611
|
-
} catch (error: any) {
|
|
612
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
613
|
-
// try to get token
|
|
614
|
-
const token = await this.client.GetToken(
|
|
615
|
-
appId || "",
|
|
616
|
-
userPubkey,
|
|
617
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
618
|
-
return this.context.sign(payload);
|
|
619
|
-
}
|
|
620
|
-
);
|
|
621
|
-
if (!token) {
|
|
622
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
623
|
-
}
|
|
624
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
625
|
-
this.client.p2pNode,
|
|
626
|
-
this.client.peerAddr,
|
|
627
|
-
this.client.token,
|
|
628
|
-
this.client.protocol
|
|
629
|
-
);
|
|
630
|
-
const reply = await grpcClient.unaryCall(
|
|
631
|
-
"/dcnet.pb.Service/DeleteSelfComment",
|
|
632
|
-
messageBytes,
|
|
633
|
-
30000
|
|
634
|
-
);
|
|
635
|
-
console.log("DeleteSelfComment reply", reply);
|
|
636
|
-
const decoded = dcnet.pb.DeleteSelfCommentReply.decode(reply);
|
|
637
|
-
console.log("DeleteSelfComment decoded", decoded);
|
|
638
|
-
return decoded.flag;
|
|
639
|
-
}
|
|
640
|
-
console.error("DeleteSelfComment error:", error);
|
|
641
|
-
throw error;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
async deleteCommentToObj(
|
|
646
|
-
appId: string,
|
|
647
|
-
theme: string,
|
|
648
|
-
themeAuthor: string,
|
|
649
|
-
blockheight: number,
|
|
650
|
-
userPubkey: string,
|
|
651
|
-
commentCid: string,
|
|
652
|
-
commentBlockHeight: number,
|
|
653
|
-
signature: Uint8Array
|
|
654
|
-
): Promise<number> {
|
|
655
|
-
const message = new dcnet.pb.DeleteCommentToObjRequest({});
|
|
656
|
-
message.theme = new TextEncoder().encode(theme);
|
|
657
|
-
message.appId = new TextEncoder().encode(appId);
|
|
658
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
659
|
-
message.blockheight = blockheight;
|
|
660
|
-
message.userPubkey = new TextEncoder().encode(userPubkey);
|
|
661
|
-
message.commentCid = new TextEncoder().encode(commentCid);
|
|
662
|
-
message.commentBlockheight = commentBlockHeight;
|
|
663
|
-
message.signature = signature;
|
|
664
|
-
const messageBytes =
|
|
665
|
-
dcnet.pb.DeleteCommentToObjRequest.encode(message).finish();
|
|
666
|
-
try {
|
|
667
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
668
|
-
this.client.p2pNode,
|
|
669
|
-
this.client.peerAddr,
|
|
670
|
-
this.client.token,
|
|
671
|
-
this.client.protocol
|
|
672
|
-
);
|
|
673
|
-
const reply = await grpcClient.unaryCall(
|
|
674
|
-
"/dcnet.pb.Service/DeleteCommentToObj",
|
|
675
|
-
messageBytes,
|
|
676
|
-
30000
|
|
677
|
-
);
|
|
678
|
-
console.log("DeleteCommentToObj reply", reply);
|
|
679
|
-
const decoded = dcnet.pb.DeleteCommentToObjReply.decode(reply);
|
|
680
|
-
console.log("DeleteCommentToObj decoded", decoded);
|
|
681
|
-
return decoded.flag;
|
|
682
|
-
} catch (error: any) {
|
|
683
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
684
|
-
// try to get token
|
|
685
|
-
const token = await this.client.GetToken(
|
|
686
|
-
appId || "",
|
|
687
|
-
userPubkey,
|
|
688
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
689
|
-
return this.context.sign(payload);
|
|
690
|
-
}
|
|
691
|
-
);
|
|
692
|
-
if (!token) {
|
|
693
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
694
|
-
}
|
|
695
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
696
|
-
this.client.p2pNode,
|
|
697
|
-
this.client.peerAddr,
|
|
698
|
-
this.client.token,
|
|
699
|
-
this.client.protocol
|
|
700
|
-
);
|
|
701
|
-
const reply = await grpcClient.unaryCall(
|
|
702
|
-
"/dcnet.pb.Service/DeleteCommentToObj",
|
|
703
|
-
messageBytes,
|
|
704
|
-
30000
|
|
705
|
-
);
|
|
706
|
-
console.log("DeleteCommentToObj reply", reply);
|
|
707
|
-
const decoded = dcnet.pb.DeleteCommentToObjReply.decode(reply);
|
|
708
|
-
console.log("DeleteCommentToObj decoded", decoded);
|
|
709
|
-
return decoded.flag;
|
|
710
|
-
}
|
|
711
|
-
console.error("DeleteSelfComment error:", error);
|
|
712
|
-
throw error;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
//判断主题是否存在
|
|
717
|
-
async isThemeExist(
|
|
718
|
-
appId: string,
|
|
719
|
-
theme: string,
|
|
720
|
-
themeAuthor: string
|
|
721
|
-
): Promise<boolean> {
|
|
722
|
-
const message = new dcnet.pb.IsThemeExistRequest({});
|
|
723
|
-
message.appId = new TextEncoder().encode(appId);
|
|
724
|
-
message.theme = new TextEncoder().encode(theme);
|
|
725
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
726
|
-
const messageBytes = dcnet.pb.IsThemeExistRequest.encode(message).finish();
|
|
727
|
-
|
|
728
|
-
try {
|
|
729
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
730
|
-
this.client.p2pNode,
|
|
731
|
-
this.client.peerAddr,
|
|
732
|
-
this.client.token,
|
|
733
|
-
this.client.protocol
|
|
734
|
-
);
|
|
735
|
-
const reply = await grpcClient.unaryCall(
|
|
736
|
-
"/dcnet.pb.Service/IsThemeExist",
|
|
737
|
-
messageBytes,
|
|
738
|
-
30000
|
|
739
|
-
);
|
|
740
|
-
console.log("IsThemeExist reply", reply);
|
|
741
|
-
const decoded = dcnet.pb.IsThemeExistReply.decode(reply);
|
|
742
|
-
console.log("IsThemeExist decoded", decoded);
|
|
743
|
-
if (decoded.flag == 0) {
|
|
744
|
-
return true;
|
|
745
|
-
}
|
|
746
|
-
return false;
|
|
747
|
-
} catch (error: any) {
|
|
748
|
-
console.error("IsThemeExist error:", error);
|
|
749
|
-
throw error;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
async getThemeObj(
|
|
755
|
-
appId: string,
|
|
756
|
-
themeAuthor: string,
|
|
757
|
-
startHeight: number,
|
|
758
|
-
direction: number,
|
|
759
|
-
offset: number,
|
|
760
|
-
limit: number,
|
|
761
|
-
seekKey: string
|
|
762
|
-
): Promise<string> {
|
|
763
|
-
const message = new dcnet.pb.GetThemeObjRequest({});
|
|
764
|
-
message.appId = new TextEncoder().encode(appId);
|
|
765
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
766
|
-
message.startHeight = startHeight;
|
|
767
|
-
message.direction = direction;
|
|
768
|
-
message.offset = offset;
|
|
769
|
-
message.limit = limit;
|
|
770
|
-
message.seekKey = new TextEncoder().encode(seekKey);
|
|
771
|
-
const messageBytes = dcnet.pb.GetThemeObjRequest.encode(message).finish();
|
|
772
|
-
|
|
773
|
-
try {
|
|
774
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
775
|
-
this.client.p2pNode,
|
|
776
|
-
this.client.peerAddr,
|
|
777
|
-
this.client.token,
|
|
778
|
-
this.client.protocol
|
|
779
|
-
);
|
|
780
|
-
const reply = await grpcClient.unaryCall(
|
|
781
|
-
"/dcnet.pb.Service/GetThemeObj",
|
|
782
|
-
messageBytes,
|
|
783
|
-
30000
|
|
784
|
-
);
|
|
785
|
-
console.log("GetThemeObj reply", reply);
|
|
786
|
-
const decoded = dcnet.pb.GetThemeObjReply.decode(reply);
|
|
787
|
-
console.log("GetThemeObj decoded", decoded);
|
|
788
|
-
console.log("GetThemeObj decoded.toJSON()", decoded.toJSON());
|
|
789
|
-
const objsCid = decoded.objsCid
|
|
790
|
-
? uint8ArrayToString(decoded.objsCid)
|
|
791
|
-
: "";
|
|
792
|
-
return objsCid;
|
|
793
|
-
} catch (error: any) {
|
|
794
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
795
|
-
// try to get token
|
|
796
|
-
const token = await this.client.GetToken(
|
|
797
|
-
appId || "",
|
|
798
|
-
this.context.getPublicKey().string(),
|
|
799
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
800
|
-
return this.context.sign(payload);
|
|
801
|
-
}
|
|
802
|
-
);
|
|
803
|
-
if (!token) {
|
|
804
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
805
|
-
}
|
|
806
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
807
|
-
this.client.p2pNode,
|
|
808
|
-
this.client.peerAddr,
|
|
809
|
-
this.client.token,
|
|
810
|
-
this.client.protocol
|
|
811
|
-
);
|
|
812
|
-
const reply = await grpcClient.unaryCall(
|
|
813
|
-
"/dcnet.pb.Service/GetThemeObj",
|
|
814
|
-
messageBytes,
|
|
815
|
-
30000
|
|
816
|
-
);
|
|
817
|
-
console.log("GetThemeObj reply", reply);
|
|
818
|
-
const decoded = dcnet.pb.GetThemeObjReply.decode(reply);
|
|
819
|
-
console.log("GetThemeObj decoded", decoded);
|
|
820
|
-
console.log("GetThemeObj decoded.toJSON()", decoded.toJSON());
|
|
821
|
-
const objsCid = decoded.objsCid
|
|
822
|
-
? uint8ArrayToString(decoded.objsCid)
|
|
823
|
-
: "";
|
|
824
|
-
return objsCid;
|
|
825
|
-
}
|
|
826
|
-
console.error("GetThemeObj error:", error);
|
|
827
|
-
throw error;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
async getThemeComments(
|
|
832
|
-
appId: string,
|
|
833
|
-
theme: string,
|
|
834
|
-
themeAuthor: string,
|
|
835
|
-
startHeight: number,
|
|
836
|
-
direction: number,
|
|
837
|
-
offset: number,
|
|
838
|
-
limit: number,
|
|
839
|
-
seekKey: string,
|
|
840
|
-
aesKey: string,
|
|
841
|
-
vaccount?: string
|
|
842
|
-
): Promise<string> {
|
|
843
|
-
const message = new dcnet.pb.GetThemeCommentsRequest({});
|
|
844
|
-
message.appId = new TextEncoder().encode(appId);
|
|
845
|
-
message.theme = new TextEncoder().encode(theme);
|
|
846
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
847
|
-
message.startHeight = startHeight;
|
|
848
|
-
message.direction = direction;
|
|
849
|
-
message.offset = offset;
|
|
850
|
-
message.limit = limit;
|
|
851
|
-
message.seekKey = new TextEncoder().encode(seekKey);
|
|
852
|
-
message.aesKey = new TextEncoder().encode(aesKey);
|
|
853
|
-
if(vaccount){
|
|
854
|
-
message.vaccount = new TextEncoder().encode(vaccount);
|
|
855
|
-
}
|
|
856
|
-
const messageBytes =
|
|
857
|
-
dcnet.pb.GetThemeCommentsRequest.encode(message).finish();
|
|
858
|
-
try {
|
|
859
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
860
|
-
this.client.p2pNode,
|
|
861
|
-
this.client.peerAddr,
|
|
862
|
-
this.client.token,
|
|
863
|
-
this.client.protocol
|
|
864
|
-
);
|
|
865
|
-
const reply = await grpcClient.unaryCall(
|
|
866
|
-
"/dcnet.pb.Service/GetThemeComments",
|
|
867
|
-
messageBytes,
|
|
868
|
-
30000
|
|
869
|
-
);
|
|
870
|
-
const decoded = dcnet.pb.GetThemeCommentsReply.decode(reply);
|
|
871
|
-
const commentsCid = decoded.commentsCid
|
|
872
|
-
? uint8ArrayToString(decoded.commentsCid)
|
|
873
|
-
: "";
|
|
874
|
-
return commentsCid;
|
|
875
|
-
} catch (error: any) {
|
|
876
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
877
|
-
// try to get token
|
|
878
|
-
const token = await this.client.GetToken(
|
|
879
|
-
appId || "",
|
|
880
|
-
this.context.getPublicKey().string(),
|
|
881
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
882
|
-
return this.context.sign(payload);
|
|
883
|
-
}
|
|
884
|
-
);
|
|
885
|
-
if (!token) {
|
|
886
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
887
|
-
}
|
|
888
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
889
|
-
this.client.p2pNode,
|
|
890
|
-
this.client.peerAddr,
|
|
891
|
-
this.client.token,
|
|
892
|
-
this.client.protocol
|
|
893
|
-
);
|
|
894
|
-
const reply = await grpcClient.unaryCall(
|
|
895
|
-
"/dcnet.pb.Service/GetThemeComments",
|
|
896
|
-
messageBytes,
|
|
897
|
-
30000
|
|
898
|
-
);
|
|
899
|
-
const decoded = dcnet.pb.GetThemeCommentsReply.decode(reply);
|
|
900
|
-
const commentsCid = decoded.commentsCid
|
|
901
|
-
? uint8ArrayToString(decoded.commentsCid)
|
|
902
|
-
: "";
|
|
903
|
-
return commentsCid;
|
|
904
|
-
}
|
|
905
|
-
console.error("GetThemeComments error:", error);
|
|
906
|
-
throw error;
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
async getUserComments(
|
|
911
|
-
appId: string,
|
|
912
|
-
userPubkey: string,
|
|
913
|
-
startHeight: number,
|
|
914
|
-
direction: number,
|
|
915
|
-
offset: number,
|
|
916
|
-
limit: number,
|
|
917
|
-
seekKey: string,
|
|
918
|
-
aesKey: string,
|
|
919
|
-
): Promise<string> {
|
|
920
|
-
const message = new dcnet.pb.GetUserCommentsRequest({});
|
|
921
|
-
message.appId = new TextEncoder().encode(appId);
|
|
922
|
-
message.UserPubkey = new TextEncoder().encode(userPubkey);
|
|
923
|
-
message.startHeight = startHeight;
|
|
924
|
-
message.direction = direction;
|
|
925
|
-
message.offset = offset;
|
|
926
|
-
message.limit = limit;
|
|
927
|
-
message.seekKey = new TextEncoder().encode(seekKey);
|
|
928
|
-
message.aesKey = new TextEncoder().encode(aesKey);
|
|
929
|
-
const messageBytes =
|
|
930
|
-
dcnet.pb.GetUserCommentsRequest.encode(message).finish();
|
|
931
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
932
|
-
this.client.p2pNode,
|
|
933
|
-
this.client.peerAddr,
|
|
934
|
-
this.client.token,
|
|
935
|
-
this.client.protocol
|
|
936
|
-
);
|
|
937
|
-
try {
|
|
938
|
-
const reply = await grpcClient.unaryCall(
|
|
939
|
-
"/dcnet.pb.Service/GetUserComments",
|
|
940
|
-
messageBytes,
|
|
941
|
-
30000
|
|
942
|
-
);
|
|
943
|
-
console.log("GetUserComments reply", reply);
|
|
944
|
-
const decoded = dcnet.pb.GetUserCommentsReply.decode(reply);
|
|
945
|
-
console.log("GetUserComments decoded", decoded);
|
|
946
|
-
console.log("GetUserComments decoded.toJSON()", decoded.toJSON());
|
|
947
|
-
const commentsCid = decoded.commentsCid
|
|
948
|
-
? uint8ArrayToString(decoded.commentsCid)
|
|
949
|
-
: "";
|
|
950
|
-
return commentsCid;
|
|
951
|
-
} catch (error: any) {
|
|
952
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
953
|
-
// try to get token
|
|
954
|
-
const token = await this.client.GetToken(
|
|
955
|
-
this.context.appInfo.appId || "",
|
|
956
|
-
this.context.getPublicKey().string(),
|
|
957
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
958
|
-
return this.context.sign(payload);
|
|
959
|
-
}
|
|
960
|
-
);
|
|
961
|
-
if (!token) {
|
|
962
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
963
|
-
}
|
|
964
|
-
const reply = await grpcClient.unaryCall(
|
|
965
|
-
"/dcnet.pb.Service/GetUserComments",
|
|
966
|
-
messageBytes,
|
|
967
|
-
30000
|
|
968
|
-
);
|
|
969
|
-
console.log("GetUserComments reply", reply);
|
|
970
|
-
const decoded = dcnet.pb.GetUserCommentsReply.decode(reply);
|
|
971
|
-
console.log("GetUserComments decoded", decoded);
|
|
972
|
-
console.log("GetUserComments decoded.toJSON()", decoded.toJSON());
|
|
973
|
-
const commentsCid = decoded.commentsCid
|
|
974
|
-
? uint8ArrayToString(decoded.commentsCid)
|
|
975
|
-
: "";
|
|
976
|
-
return commentsCid;
|
|
977
|
-
}
|
|
978
|
-
console.error("GetUserComments error:", error);
|
|
979
|
-
throw error;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|