web-dc-api 0.1.4 → 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,99 +0,0 @@
|
|
|
1
|
-
// modules/keyvalue-module.ts
|
|
2
|
-
// 键值存储功能模块
|
|
3
|
-
|
|
4
|
-
import { ICacheOperations } from "../interfaces/cache-interface";
|
|
5
|
-
import { DCContext } from "../../lib/interfaces/DCContext";
|
|
6
|
-
import { DCModule, CoreModuleName } from "../common/module-system";
|
|
7
|
-
import { CacheManager } from "../implements/cache/manager";
|
|
8
|
-
import { keyExpire } from "../common/define";
|
|
9
|
-
import { createLogger } from "../util/logger";
|
|
10
|
-
|
|
11
|
-
const logger = createLogger('CacheModule');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 键值存储模块
|
|
15
|
-
* 提供键值存储功能
|
|
16
|
-
*/
|
|
17
|
-
export class CacheModule implements DCModule, ICacheOperations {
|
|
18
|
-
readonly moduleName = CoreModuleName.CACHE;
|
|
19
|
-
private cacheManager!: CacheManager;
|
|
20
|
-
private initialized: boolean = false;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 初始化键值存储模块
|
|
24
|
-
* @param context DC上下文
|
|
25
|
-
* @returns 是否初始化成功
|
|
26
|
-
*/
|
|
27
|
-
async initialize(context: DCContext): Promise<boolean> {
|
|
28
|
-
try {
|
|
29
|
-
this.cacheManager = new CacheManager(
|
|
30
|
-
context.dcutil,
|
|
31
|
-
context.dcChain,
|
|
32
|
-
context
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
this.initialized = true;
|
|
36
|
-
return true;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
logger.error("键值存储模块初始化失败:", error);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 关闭键值存储模块
|
|
45
|
-
*/
|
|
46
|
-
async shutdown(): Promise<void> {
|
|
47
|
-
this.initialized = false;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* 从dc网络获取缓存值
|
|
51
|
-
* @param key 缓存键
|
|
52
|
-
* @returns 缓存值
|
|
53
|
-
*/
|
|
54
|
-
async getCacheValue(key: string): Promise<[string | null, Error | null]>{
|
|
55
|
-
try {
|
|
56
|
-
this.assertInitialized();
|
|
57
|
-
const res = await this.cacheManager.getCacheValue(key);
|
|
58
|
-
if (res[0]) {
|
|
59
|
-
logger.info(`获取缓存键 ${key} 成功`);
|
|
60
|
-
return [res[0], null];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
logger.info(`缓存键 ${key} 不存在`);
|
|
64
|
-
return [null, null];
|
|
65
|
-
} catch (error) {
|
|
66
|
-
logger.error(`获取缓存键 ${key} 失败:`, error);
|
|
67
|
-
return [null, error instanceof Error ? error : new Error(String(error))];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 设置缓存值
|
|
73
|
-
* @param value 缓存值
|
|
74
|
-
* @param expire 过期时间
|
|
75
|
-
* @returns 设置结果
|
|
76
|
-
*/
|
|
77
|
-
async setCacheKey(value: string, expire?: number): Promise<[string | null, Error | null]> {
|
|
78
|
-
try {
|
|
79
|
-
this.assertInitialized();
|
|
80
|
-
const expireNumber = expire ? expire : keyExpire; // 默认一天
|
|
81
|
-
const res = await this.cacheManager.setCacheKey(value, expireNumber);
|
|
82
|
-
|
|
83
|
-
logger.info(`设置缓存值成功,过期时间: ${expireNumber}秒`);
|
|
84
|
-
return res;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
logger.error(`设置缓存值失败:`, error);
|
|
87
|
-
return [null, error instanceof Error ? error : new Error(String(error))];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 断言模块已初始化
|
|
93
|
-
*/
|
|
94
|
-
private assertInitialized(): void {
|
|
95
|
-
if (!this.initialized) {
|
|
96
|
-
throw new Error("键值存储模块未初始化");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// modules/client-module.ts
|
|
2
|
-
// 消息功能模块
|
|
3
|
-
|
|
4
|
-
import { IClientOperations } from "../interfaces/client-interface";
|
|
5
|
-
import { DCContext } from "../../lib/interfaces/DCContext";
|
|
6
|
-
import { DCModule, CoreModuleName } from "../common/module-system";
|
|
7
|
-
import { DCManager } from "../implements/dc/manager";
|
|
8
|
-
import { createLogger } from "../util/logger";
|
|
9
|
-
|
|
10
|
-
const logger = createLogger('ClientModule');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 消息模块
|
|
14
|
-
* 提供消息收发功能
|
|
15
|
-
*/
|
|
16
|
-
export class ClientModule implements DCModule, IClientOperations {
|
|
17
|
-
readonly moduleName = CoreModuleName.CLIENT;
|
|
18
|
-
private clientManager!: DCManager;
|
|
19
|
-
private initialized: boolean = false;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 初始化消息模块
|
|
23
|
-
* @param context DC上下文
|
|
24
|
-
* @returns 是否初始化成功
|
|
25
|
-
*/
|
|
26
|
-
async initialize(context: DCContext): Promise<boolean> {
|
|
27
|
-
try {
|
|
28
|
-
this.clientManager = new DCManager(
|
|
29
|
-
context.connectedDc,
|
|
30
|
-
);
|
|
31
|
-
this.initialized = true;
|
|
32
|
-
return true;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
logger.error("消息模块初始化失败:", error);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 关闭消息模块
|
|
41
|
-
*/
|
|
42
|
-
async shutdown(): Promise<void> {
|
|
43
|
-
this.initialized = false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getHostID(): Promise<[{ peerID: string; reqAddr: string } | null, Error | null]> {
|
|
47
|
-
try {
|
|
48
|
-
this.assertInitialized();
|
|
49
|
-
const res = await this.clientManager.getHostID();
|
|
50
|
-
if (res[0]) {
|
|
51
|
-
logger.info(`获取hostID成功: ${res[0].peerID}, 公网地址: ${res[0].reqAddr}`);
|
|
52
|
-
} else {
|
|
53
|
-
logger.error("获取hostID失败:", res[1]);
|
|
54
|
-
}
|
|
55
|
-
return res;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
logger.error("获取hostID时发生错误:", error);
|
|
58
|
-
return [null, error as Error];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 断言模块已初始化
|
|
65
|
-
*/
|
|
66
|
-
private assertInitialized(): void {
|
|
67
|
-
if (!this.initialized) {
|
|
68
|
-
throw new Error("消息模块未初始化");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
// modules/comment-module.ts
|
|
2
|
-
// 评论功能模块
|
|
3
|
-
|
|
4
|
-
import { ICommentOperations } from "../interfaces/comment-interface";
|
|
5
|
-
import { DCContext } from "../../lib/interfaces/DCContext";
|
|
6
|
-
import { DCModule, CoreModuleName } from "../common/module-system";
|
|
7
|
-
import { CommentManager } from "../implements/comment/manager";
|
|
8
|
-
import { createLogger } from "../util/logger";
|
|
9
|
-
import { ThemePermission } from "../common/constants";
|
|
10
|
-
import { ThemeAuthInfo, ThemeComment, ThemeObj } from "../common/types/types";
|
|
11
|
-
|
|
12
|
-
const logger = createLogger('CommentModule');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 评论模块
|
|
16
|
-
* 处理评论相关功能
|
|
17
|
-
*/
|
|
18
|
-
export class CommentModule implements DCModule, ICommentOperations {
|
|
19
|
-
readonly moduleName = CoreModuleName.COMMENT;
|
|
20
|
-
private context!: DCContext;
|
|
21
|
-
private commentManager!: CommentManager;
|
|
22
|
-
private initialized: boolean = false;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 初始化评论模块
|
|
26
|
-
* @param context DC上下文
|
|
27
|
-
* @returns 是否初始化成功
|
|
28
|
-
*/
|
|
29
|
-
async initialize(context: DCContext): Promise<boolean> {
|
|
30
|
-
try {
|
|
31
|
-
this.context = context;
|
|
32
|
-
this.commentManager = new CommentManager(
|
|
33
|
-
context
|
|
34
|
-
);
|
|
35
|
-
this.initialized = true;
|
|
36
|
-
return true;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
logger.error("评论模块初始化失败:", error);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 关闭评论模块
|
|
45
|
-
*/
|
|
46
|
-
async shutdown(): Promise<void> {
|
|
47
|
-
this.initialized = false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 添加用户评论空间
|
|
52
|
-
*/
|
|
53
|
-
async addUserOffChainSpace(): Promise<[boolean | null, Error | null]> {
|
|
54
|
-
try {
|
|
55
|
-
this.assertInitialized();
|
|
56
|
-
const res = await this.commentManager.addUserOffChainSpace();
|
|
57
|
-
if(!res[1]){
|
|
58
|
-
logger.info("添加用户评论空间成功");
|
|
59
|
-
}
|
|
60
|
-
return res;
|
|
61
|
-
} catch (error) {
|
|
62
|
-
logger.error("添加用户评论空间失败:", error);
|
|
63
|
-
return [null, error as Error];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 添加用户链下操作次数
|
|
69
|
-
*/
|
|
70
|
-
async addUserOffChainOpTimes(
|
|
71
|
-
times: number,
|
|
72
|
-
vaccount?: string
|
|
73
|
-
): Promise<[boolean | null, Error | null]> {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
this.assertInitialized();
|
|
78
|
-
const res = await this.commentManager.addUserOffChainOpTimes(times, vaccount);
|
|
79
|
-
if(!res[1]){
|
|
80
|
-
logger.info("添加用户操作次数成功");
|
|
81
|
-
}
|
|
82
|
-
return res;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
logger.error("添加用户操作次数失败:", error);
|
|
85
|
-
return [null, error as Error];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 为指定对象开通评论功能
|
|
92
|
-
* @param theme 主题
|
|
93
|
-
* @param openFlag 开放标志
|
|
94
|
-
* @param commentSpace 评论空间大小
|
|
95
|
-
*/
|
|
96
|
-
async addThemeObj(theme: string, openFlag: number, commentSpace?: number): Promise<[number | null, Error | null]> {
|
|
97
|
-
try {
|
|
98
|
-
this.assertInitialized();
|
|
99
|
-
const res = await this.commentManager.addThemeObj(
|
|
100
|
-
this.context.appInfo?.appId || "",
|
|
101
|
-
theme,
|
|
102
|
-
openFlag,
|
|
103
|
-
commentSpace || 50 * 1024 * 1024 // 50M
|
|
104
|
-
);
|
|
105
|
-
if(!res[1]){
|
|
106
|
-
logger.info(`为主题 ${theme} 开通评论功能成功`);
|
|
107
|
-
}
|
|
108
|
-
return res;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
logger.error(`为主题 ${theme} 开通评论功能失败:`, error);
|
|
111
|
-
return [null, error as Error];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async isThemeExist(
|
|
116
|
-
appId: string,
|
|
117
|
-
theme: string,
|
|
118
|
-
themeAuthor: string,
|
|
119
|
-
): Promise<[boolean | null, Error | null]> {
|
|
120
|
-
try {
|
|
121
|
-
this.assertInitialized();
|
|
122
|
-
const res = await this.commentManager.isThemeExist(
|
|
123
|
-
appId,
|
|
124
|
-
theme,
|
|
125
|
-
themeAuthor
|
|
126
|
-
);
|
|
127
|
-
return res;
|
|
128
|
-
} catch (error) {
|
|
129
|
-
logger.error(`判断主题 ${theme} 是否存在失败:`, error);
|
|
130
|
-
return [null, error as Error];
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 为开通评论的对象增加评论空间
|
|
139
|
-
* @param theme 主题
|
|
140
|
-
* @param addSpace 增加的空间大小
|
|
141
|
-
*/
|
|
142
|
-
async addThemeSpace(theme: string, addSpace: number): Promise<[number | null, Error | null]> {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
this.assertInitialized();
|
|
147
|
-
const res = await this.commentManager.addThemeSpace(
|
|
148
|
-
this.context.appInfo?.appId || "",
|
|
149
|
-
theme,
|
|
150
|
-
addSpace
|
|
151
|
-
);
|
|
152
|
-
if(!res[1]){
|
|
153
|
-
logger.info(`为主题 ${theme} 增加 ${addSpace} 字节评论空间成功`);
|
|
154
|
-
}
|
|
155
|
-
return res;
|
|
156
|
-
} catch (error) {
|
|
157
|
-
logger.error(`为主题 ${theme} 增加评论空间失败:`, error);
|
|
158
|
-
return [null, error as Error];
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 发布评论
|
|
164
|
-
* @param theme 主题
|
|
165
|
-
* @param themeAuthor 主题作者 base32编码格式
|
|
166
|
-
* @param commentType 评论类型
|
|
167
|
-
* @param comment 评论内容
|
|
168
|
-
* @param refercommentkey 引用评论的键
|
|
169
|
-
* @param openFlag 开放标志
|
|
170
|
-
*/
|
|
171
|
-
async publishCommentToTheme(
|
|
172
|
-
theme: string,
|
|
173
|
-
themeAuthor: string,
|
|
174
|
-
commentType: number,
|
|
175
|
-
comment: string,
|
|
176
|
-
openFlag?: number,
|
|
177
|
-
refercommentkey?: string
|
|
178
|
-
): Promise<[string | null, Error | null]> {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
this.assertInitialized();
|
|
183
|
-
const res = await this.commentManager.publishCommentToTheme(
|
|
184
|
-
this.context.appInfo?.appId || "",
|
|
185
|
-
theme,
|
|
186
|
-
themeAuthor,
|
|
187
|
-
commentType,
|
|
188
|
-
comment,
|
|
189
|
-
refercommentkey || "",
|
|
190
|
-
openFlag
|
|
191
|
-
);
|
|
192
|
-
if(!res[1]){
|
|
193
|
-
logger.info(`发布评论到主题 ${theme} 成功`);
|
|
194
|
-
}
|
|
195
|
-
return res;
|
|
196
|
-
} catch (error) {
|
|
197
|
-
logger.error(`发布评论到主题 ${theme} 失败:`, error);
|
|
198
|
-
return [null, error as Error];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* 删除评论
|
|
204
|
-
* @param theme 主题
|
|
205
|
-
* @param themeAuthor 主题作者
|
|
206
|
-
* @param commentKey 评论键
|
|
207
|
-
*/
|
|
208
|
-
async deleteSelfComment(
|
|
209
|
-
theme: string,
|
|
210
|
-
themeAuthor: string,
|
|
211
|
-
commentKey: string
|
|
212
|
-
): Promise<[number | null, Error | null]> {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
try {
|
|
216
|
-
this.assertInitialized();
|
|
217
|
-
const res = await this.commentManager.deleteSelfComment(
|
|
218
|
-
this.context.appInfo?.appId || "",
|
|
219
|
-
theme,
|
|
220
|
-
themeAuthor,
|
|
221
|
-
commentKey
|
|
222
|
-
);
|
|
223
|
-
if(!res[1]){
|
|
224
|
-
logger.info(`删除评论 ${commentKey} 成功`);
|
|
225
|
-
}
|
|
226
|
-
return res;
|
|
227
|
-
} catch (error) {
|
|
228
|
-
logger.error(`删除评论 ${commentKey} 失败:`, error);
|
|
229
|
-
return [null, error as Error];
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 获取评论对象列表
|
|
235
|
-
* @param themeAuthor 主题作者
|
|
236
|
-
* @param startHeight 起始高度
|
|
237
|
-
* @param direction 方向
|
|
238
|
-
* @param offset 偏移量
|
|
239
|
-
* @param limit 限制数量
|
|
240
|
-
* @param seekKey 搜索键
|
|
241
|
-
*/
|
|
242
|
-
async getThemeObj(
|
|
243
|
-
themeAuthor: string,
|
|
244
|
-
startHeight?: number,
|
|
245
|
-
direction?: number,
|
|
246
|
-
offset?: number,
|
|
247
|
-
limit?: number,
|
|
248
|
-
seekKey?: string
|
|
249
|
-
): Promise<[ThemeObj[] | null, Error | null]> {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
this.assertInitialized();
|
|
254
|
-
const res = await this.commentManager.getThemeObj(
|
|
255
|
-
this.context.appInfo?.appId || "",
|
|
256
|
-
themeAuthor,
|
|
257
|
-
startHeight || 0,
|
|
258
|
-
direction || 0,
|
|
259
|
-
offset || 0,
|
|
260
|
-
limit || 100,
|
|
261
|
-
seekKey || ""
|
|
262
|
-
);
|
|
263
|
-
if(!res[1]){
|
|
264
|
-
logger.info(`获取作者 ${themeAuthor} 的主题对象列表成功`);
|
|
265
|
-
}
|
|
266
|
-
return res;
|
|
267
|
-
} catch (error) {
|
|
268
|
-
logger.error(`获取作者 ${themeAuthor} 的主题对象列表失败:`, error);
|
|
269
|
-
return [null, error as Error];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 获取主题评论列表
|
|
275
|
-
* @param theme 主题
|
|
276
|
-
* @param themeAuthor 主题作者
|
|
277
|
-
* @param startHeight 起始高度
|
|
278
|
-
* @param direction 方向
|
|
279
|
-
* @param offset 偏移量
|
|
280
|
-
* @param limit 限制数量
|
|
281
|
-
* @param seekKey 搜索键
|
|
282
|
-
*/
|
|
283
|
-
async getThemeComments(
|
|
284
|
-
theme: string,
|
|
285
|
-
themeAuthor: string,
|
|
286
|
-
startHeight?: number,
|
|
287
|
-
direction?: number,
|
|
288
|
-
offset?: number,
|
|
289
|
-
limit?: number,
|
|
290
|
-
seekKey?: string
|
|
291
|
-
): Promise<[ThemeComment[] | null, Error | null]> {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
this.assertInitialized();
|
|
296
|
-
const res = await this.commentManager.getThemeComments(
|
|
297
|
-
this.context.appInfo?.appId || "",
|
|
298
|
-
theme,
|
|
299
|
-
themeAuthor,
|
|
300
|
-
startHeight || 0,
|
|
301
|
-
direction || 0,
|
|
302
|
-
offset || 0,
|
|
303
|
-
limit || 100,
|
|
304
|
-
seekKey || ""
|
|
305
|
-
);
|
|
306
|
-
if(!res[1]){
|
|
307
|
-
logger.info(`获取主题 ${theme} 的评论列表成功`);
|
|
308
|
-
}
|
|
309
|
-
return res;
|
|
310
|
-
} catch (error) {
|
|
311
|
-
logger.error(`获取主题 ${theme} 的评论列表失败:`, error);
|
|
312
|
-
return [null, error as Error];
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* 配置主题的授权信息
|
|
318
|
-
* @param themeAuthor 主题作者的公钥
|
|
319
|
-
* @param theme 主题名称
|
|
320
|
-
* @param authPubkey 被授权者的公钥
|
|
321
|
-
* @param permission 权限级别
|
|
322
|
-
* @param remark 备注信息
|
|
323
|
-
* @param vaccount 可选的虚拟账户
|
|
324
|
-
* @returns [授权状态码, 错误信息]
|
|
325
|
-
*/
|
|
326
|
-
async configAuth(
|
|
327
|
-
themeAuthor: string,
|
|
328
|
-
theme: string,
|
|
329
|
-
authPubkey: string,
|
|
330
|
-
permission: ThemePermission,
|
|
331
|
-
remark: string,
|
|
332
|
-
vaccount?: string
|
|
333
|
-
): Promise<[number | null, Error | null]> {
|
|
334
|
-
try{
|
|
335
|
-
this.assertInitialized();
|
|
336
|
-
return await this.commentManager.configAuth(
|
|
337
|
-
this.context.appInfo?.appId || "",
|
|
338
|
-
themeAuthor,
|
|
339
|
-
theme,
|
|
340
|
-
authPubkey,
|
|
341
|
-
permission,
|
|
342
|
-
remark,
|
|
343
|
-
vaccount
|
|
344
|
-
);
|
|
345
|
-
}catch(error){
|
|
346
|
-
logger.error(`配置主题 ${theme} 的授权信息失败:`, error);
|
|
347
|
-
return [null, error as Error];
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* 获取指定主题的授权列表,
|
|
355
|
-
* @param themeAuthor 主题作者的公钥
|
|
356
|
-
* @param theme 主题/对象标识符
|
|
357
|
-
* @param vaccount 可选,虚拟账户
|
|
358
|
-
* @returns [授权列表, 评论列表, 错误信息]
|
|
359
|
-
*/
|
|
360
|
-
async getAuthList(
|
|
361
|
-
themeAuthor: string,
|
|
362
|
-
theme: string,
|
|
363
|
-
vaccount?: string
|
|
364
|
-
): Promise<[ThemeAuthInfo[]|null,ThemeComment[] | null, Error | null]> {
|
|
365
|
-
try{
|
|
366
|
-
this.assertInitialized();
|
|
367
|
-
return await this.commentManager.getAuthList(
|
|
368
|
-
this.context.appInfo?.appId || "",
|
|
369
|
-
themeAuthor,
|
|
370
|
-
theme,
|
|
371
|
-
vaccount
|
|
372
|
-
);
|
|
373
|
-
} catch (error) {
|
|
374
|
-
logger.error(`获取主题 ${theme} 的授权列表失败:`, error);
|
|
375
|
-
return [null, null, error as Error];
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* 获取用户评论列表
|
|
383
|
-
* @param userPubkey 用户公钥
|
|
384
|
-
* @param startHeight 起始高度
|
|
385
|
-
* @param direction 方向
|
|
386
|
-
* @param offset 偏移量
|
|
387
|
-
* @param limit 限制数量
|
|
388
|
-
* @param seekKey 搜索键
|
|
389
|
-
*/
|
|
390
|
-
async getUserComments(
|
|
391
|
-
userPubkey: string,
|
|
392
|
-
startHeight?: number,
|
|
393
|
-
direction?: number,
|
|
394
|
-
offset?: number,
|
|
395
|
-
limit?: number,
|
|
396
|
-
seekKey?: string
|
|
397
|
-
): Promise<[ThemeComment[] | null, Error | null]> {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
try {
|
|
401
|
-
this.assertInitialized();
|
|
402
|
-
const res = await this.commentManager.getUserComments(
|
|
403
|
-
this.context.appInfo?.appId || "",
|
|
404
|
-
userPubkey,
|
|
405
|
-
startHeight || 0,
|
|
406
|
-
direction || 0,
|
|
407
|
-
offset || 0,
|
|
408
|
-
limit || 100,
|
|
409
|
-
seekKey || ""
|
|
410
|
-
);
|
|
411
|
-
if(!res[1]){
|
|
412
|
-
logger.info(`获取用户 ${userPubkey} 的评论列表成功`);
|
|
413
|
-
}
|
|
414
|
-
return res;
|
|
415
|
-
} catch (error) {
|
|
416
|
-
logger.error(`获取用户 ${userPubkey} 的评论列表失败:`, error);
|
|
417
|
-
return [null, error as Error];
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* 断言模块已初始化
|
|
423
|
-
*/
|
|
424
|
-
private assertInitialized(): void {
|
|
425
|
-
if (!this.initialized) {
|
|
426
|
-
throw new Error("评论模块未初始化");
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|