fishpi 0.0.58 → 0.0.60
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/LICENSE +21 -21
- package/README.md +105 -105
- package/lib/article.d.ts +1 -11
- package/lib/article.js +25 -52
- package/lib/chatroom.d.ts +2 -2
- package/lib/chatroom.js +23 -9
- package/lib/typing.d.ts +9 -0
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Ryan Sonshine
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Ryan Sonshine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
# 摸鱼派 API Package
|
|
2
|
-
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
|
|
3
|
-
|
|
4
|
-
## 支援
|
|
5
|
-
- 用户信息;
|
|
6
|
-
- 聊天室;
|
|
7
|
-
- 话题编辑;
|
|
8
|
-
- 红包收发;
|
|
9
|
-
- 自定义表情包;
|
|
10
|
-
- 文件上传;
|
|
11
|
-
- 通知信息;
|
|
12
|
-
- 清风明月;
|
|
13
|
-
- 文章读写;
|
|
14
|
-
- 评论点赞;
|
|
15
|
-
- 私聊功能;
|
|
16
|
-
|
|
17
|
-
## 安装
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install fishpi
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## 用例
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import FishPi from 'fishpi';
|
|
27
|
-
|
|
28
|
-
// 登录获取 apiKey
|
|
29
|
-
let apiKey = '';
|
|
30
|
-
let fish = new FishPi();
|
|
31
|
-
let rsp = await fish.login({
|
|
32
|
-
username: 'username',
|
|
33
|
-
passwd: 'password123456'
|
|
34
|
-
});
|
|
35
|
-
if (rsp.code == 0) apiKey = rsp.Key;
|
|
36
|
-
|
|
37
|
-
// 通过 apiKey 获取登录用户信息
|
|
38
|
-
let fish = new FishPi(apiKey);
|
|
39
|
-
console.dir(await fish.account.info());
|
|
40
|
-
|
|
41
|
-
// 获取用户自定义表情包
|
|
42
|
-
let emojis = await fish.emoji.get();
|
|
43
|
-
// 获取默认表情包
|
|
44
|
-
let defaultEmoji = fish.emoji.default;
|
|
45
|
-
|
|
46
|
-
// 监听聊天室消息
|
|
47
|
-
fish.chatroom.addListener(({ msg }) => console.dir(msg));
|
|
48
|
-
// 向聊天室发送信息(需要登录)
|
|
49
|
-
await fish.chatroom.send('Hello World!');
|
|
50
|
-
// 向聊天室发送红包
|
|
51
|
-
await fish.chatroom.redpacket.send({
|
|
52
|
-
type: 'random';
|
|
53
|
-
money: 32;
|
|
54
|
-
count: 2;
|
|
55
|
-
msg: '摸鱼者,事竟成!';
|
|
56
|
-
recivers: [];
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
// 私聊历史获取
|
|
60
|
-
let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
|
|
61
|
-
// 监听私聊新消息
|
|
62
|
-
fishpi.chat.addListener(async ({ msg }: { msg: NoticeMsg }) => {
|
|
63
|
-
switch (msg.command) {
|
|
64
|
-
// 私聊未读数更新
|
|
65
|
-
case 'chatUnreadCountRefresh':
|
|
66
|
-
if(msg.count! > 0) {
|
|
67
|
-
let unreadMsgs = await fishpi.chat.unread();
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
// 新私聊消息
|
|
71
|
-
case 'newIdleChatMessage':
|
|
72
|
-
// msg 就是新的私聊消息
|
|
73
|
-
console.log(msg.senderUserName, '说:', msg.preview);
|
|
74
|
-
break;
|
|
75
|
-
// 有新的消息通知
|
|
76
|
-
case 'refreshNotification':
|
|
77
|
-
console.log('你有新消息【', await fishpi.notice.count(), '】')
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
// 监听指定用户的私聊消息
|
|
82
|
-
fishpi.chat.addListener(({ msg }: { msg: ChatData }) => {
|
|
83
|
-
console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
|
|
84
|
-
}, 'username');
|
|
85
|
-
// 给指定用户发私聊消息
|
|
86
|
-
fishpi.chat.send('username', 'Hi~');
|
|
87
|
-
|
|
88
|
-
// 金手指
|
|
89
|
-
import { Finger, FingerTo } from 'fishpi';
|
|
90
|
-
|
|
91
|
-
// 一次性金手指
|
|
92
|
-
await FingerTo('GoldenFingerKey').queryLatestLoginIP('username')
|
|
93
|
-
|
|
94
|
-
// 金手指实例
|
|
95
|
-
const finger = new Finger(apiKey);
|
|
96
|
-
await finger.queryLatestLoginIP('username');
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## 注意事项
|
|
101
|
-
|
|
102
|
-
API 库使用 `fetch` 做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 `node-fetch` 2.x 版本的库。执行如下代码设置 `fetch` 函数:
|
|
103
|
-
```typescript
|
|
104
|
-
import fetch from 'node-fetch'
|
|
105
|
-
globalThis.fetch = fetch as any;
|
|
1
|
+
# 摸鱼派 API Package
|
|
2
|
+
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
|
|
3
|
+
|
|
4
|
+
## 支援
|
|
5
|
+
- 用户信息;
|
|
6
|
+
- 聊天室;
|
|
7
|
+
- 话题编辑;
|
|
8
|
+
- 红包收发;
|
|
9
|
+
- 自定义表情包;
|
|
10
|
+
- 文件上传;
|
|
11
|
+
- 通知信息;
|
|
12
|
+
- 清风明月;
|
|
13
|
+
- 文章读写;
|
|
14
|
+
- 评论点赞;
|
|
15
|
+
- 私聊功能;
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install fishpi
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 用例
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import FishPi from 'fishpi';
|
|
27
|
+
|
|
28
|
+
// 登录获取 apiKey
|
|
29
|
+
let apiKey = '';
|
|
30
|
+
let fish = new FishPi();
|
|
31
|
+
let rsp = await fish.login({
|
|
32
|
+
username: 'username',
|
|
33
|
+
passwd: 'password123456'
|
|
34
|
+
});
|
|
35
|
+
if (rsp.code == 0) apiKey = rsp.Key;
|
|
36
|
+
|
|
37
|
+
// 通过 apiKey 获取登录用户信息
|
|
38
|
+
let fish = new FishPi(apiKey);
|
|
39
|
+
console.dir(await fish.account.info());
|
|
40
|
+
|
|
41
|
+
// 获取用户自定义表情包
|
|
42
|
+
let emojis = await fish.emoji.get();
|
|
43
|
+
// 获取默认表情包
|
|
44
|
+
let defaultEmoji = fish.emoji.default;
|
|
45
|
+
|
|
46
|
+
// 监听聊天室消息
|
|
47
|
+
fish.chatroom.addListener(({ msg }) => console.dir(msg));
|
|
48
|
+
// 向聊天室发送信息(需要登录)
|
|
49
|
+
await fish.chatroom.send('Hello World!');
|
|
50
|
+
// 向聊天室发送红包
|
|
51
|
+
await fish.chatroom.redpacket.send({
|
|
52
|
+
type: 'random';
|
|
53
|
+
money: 32;
|
|
54
|
+
count: 2;
|
|
55
|
+
msg: '摸鱼者,事竟成!';
|
|
56
|
+
recivers: [];
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// 私聊历史获取
|
|
60
|
+
let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
|
|
61
|
+
// 监听私聊新消息
|
|
62
|
+
fishpi.chat.addListener(async ({ msg }: { msg: NoticeMsg }) => {
|
|
63
|
+
switch (msg.command) {
|
|
64
|
+
// 私聊未读数更新
|
|
65
|
+
case 'chatUnreadCountRefresh':
|
|
66
|
+
if(msg.count! > 0) {
|
|
67
|
+
let unreadMsgs = await fishpi.chat.unread();
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
// 新私聊消息
|
|
71
|
+
case 'newIdleChatMessage':
|
|
72
|
+
// msg 就是新的私聊消息
|
|
73
|
+
console.log(msg.senderUserName, '说:', msg.preview);
|
|
74
|
+
break;
|
|
75
|
+
// 有新的消息通知
|
|
76
|
+
case 'refreshNotification':
|
|
77
|
+
console.log('你有新消息【', await fishpi.notice.count(), '】')
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// 监听指定用户的私聊消息
|
|
82
|
+
fishpi.chat.addListener(({ msg }: { msg: ChatData }) => {
|
|
83
|
+
console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
|
|
84
|
+
}, 'username');
|
|
85
|
+
// 给指定用户发私聊消息
|
|
86
|
+
fishpi.chat.send('username', 'Hi~');
|
|
87
|
+
|
|
88
|
+
// 金手指
|
|
89
|
+
import { Finger, FingerTo } from 'fishpi';
|
|
90
|
+
|
|
91
|
+
// 一次性金手指
|
|
92
|
+
await FingerTo('GoldenFingerKey').queryLatestLoginIP('username')
|
|
93
|
+
|
|
94
|
+
// 金手指实例
|
|
95
|
+
const finger = new Finger(apiKey);
|
|
96
|
+
await finger.queryLatestLoginIP('username');
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 注意事项
|
|
101
|
+
|
|
102
|
+
API 库使用 `fetch` 做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 `node-fetch` 2.x 版本的库。执行如下代码设置 `fetch` 函数:
|
|
103
|
+
```typescript
|
|
104
|
+
import fetch from 'node-fetch'
|
|
105
|
+
globalThis.fetch = fetch as any;
|
|
106
106
|
```
|
package/lib/article.d.ts
CHANGED
|
@@ -41,20 +41,10 @@ declare class Article {
|
|
|
41
41
|
size?: number;
|
|
42
42
|
tag?: string;
|
|
43
43
|
}): Promise<ApiResponse<ArticleList>>;
|
|
44
|
-
/**
|
|
45
|
-
* 查询文章列表
|
|
46
|
-
* @param type 查询类型
|
|
47
|
-
* @param tag 指定查询标签,可选
|
|
48
|
-
* @returns 文章列表
|
|
49
|
-
*/
|
|
50
|
-
listByUser({ user, page, size }: {
|
|
51
|
-
user: string;
|
|
52
|
-
page?: number;
|
|
53
|
-
size?: number;
|
|
54
|
-
}): Promise<ApiResponse<ArticleList>>;
|
|
55
44
|
/**
|
|
56
45
|
* 查询用户文章列表
|
|
57
46
|
* @param userName 用户名
|
|
47
|
+
* @param page 页码
|
|
58
48
|
* @returns 文章列表
|
|
59
49
|
*/
|
|
60
50
|
userArticles({ userName, page }: {
|
package/lib/article.js
CHANGED
|
@@ -176,43 +176,16 @@ var Article = /** @class */ (function () {
|
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
};
|
|
179
|
-
/**
|
|
180
|
-
* 查询文章列表
|
|
181
|
-
* @param type 查询类型
|
|
182
|
-
* @param tag 指定查询标签,可选
|
|
183
|
-
* @returns 文章列表
|
|
184
|
-
*/
|
|
185
|
-
Article.prototype.listByUser = function (_a) {
|
|
186
|
-
var user = _a.user, _b = _a.page, page = _b === void 0 ? 1 : _b, _c = _a.size, size = _c === void 0 ? 20 : _c;
|
|
187
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
-
var rsp, e_4;
|
|
189
|
-
return __generator(this, function (_d) {
|
|
190
|
-
switch (_d.label) {
|
|
191
|
-
case 0:
|
|
192
|
-
_d.trys.push([0, 2, , 3]);
|
|
193
|
-
return [4 /*yield*/, (0, utils_1.request)({
|
|
194
|
-
url: "api/user/".concat(user, "articles?p=").concat(page, "&size=").concat(size, "&").concat(this._apiKey ? "apiKey=".concat(this._apiKey) : ''),
|
|
195
|
-
})];
|
|
196
|
-
case 1:
|
|
197
|
-
rsp = _d.sent();
|
|
198
|
-
return [2 /*return*/, rsp];
|
|
199
|
-
case 2:
|
|
200
|
-
e_4 = _d.sent();
|
|
201
|
-
throw e_4;
|
|
202
|
-
case 3: return [2 /*return*/];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
179
|
/**
|
|
208
180
|
* 查询用户文章列表
|
|
209
181
|
* @param userName 用户名
|
|
182
|
+
* @param page 页码
|
|
210
183
|
* @returns 文章列表
|
|
211
184
|
*/
|
|
212
185
|
Article.prototype.userArticles = function (_a) {
|
|
213
186
|
var userName = _a.userName, _b = _a.page, page = _b === void 0 ? 1 : _b;
|
|
214
187
|
return __awaiter(this, void 0, void 0, function () {
|
|
215
|
-
var rsp,
|
|
188
|
+
var rsp, e_4;
|
|
216
189
|
return __generator(this, function (_c) {
|
|
217
190
|
switch (_c.label) {
|
|
218
191
|
case 0:
|
|
@@ -224,8 +197,8 @@ var Article = /** @class */ (function () {
|
|
|
224
197
|
rsp = _c.sent();
|
|
225
198
|
return [2 /*return*/, rsp];
|
|
226
199
|
case 2:
|
|
227
|
-
|
|
228
|
-
throw
|
|
200
|
+
e_4 = _c.sent();
|
|
201
|
+
throw e_4;
|
|
229
202
|
case 3: return [2 /*return*/];
|
|
230
203
|
}
|
|
231
204
|
});
|
|
@@ -239,7 +212,7 @@ var Article = /** @class */ (function () {
|
|
|
239
212
|
Article.prototype.detail = function (id, p) {
|
|
240
213
|
if (p === void 0) { p = 1; }
|
|
241
214
|
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
-
var rsp, i, i,
|
|
215
|
+
var rsp, i, i, e_5;
|
|
243
216
|
return __generator(this, function (_a) {
|
|
244
217
|
switch (_a.label) {
|
|
245
218
|
case 0:
|
|
@@ -258,8 +231,8 @@ var Article = /** @class */ (function () {
|
|
|
258
231
|
}
|
|
259
232
|
return [2 /*return*/, rsp];
|
|
260
233
|
case 2:
|
|
261
|
-
|
|
262
|
-
throw
|
|
234
|
+
e_5 = _a.sent();
|
|
235
|
+
throw e_5;
|
|
263
236
|
case 3: return [2 /*return*/];
|
|
264
237
|
}
|
|
265
238
|
});
|
|
@@ -273,7 +246,7 @@ var Article = /** @class */ (function () {
|
|
|
273
246
|
*/
|
|
274
247
|
Article.prototype.vote = function (id, type) {
|
|
275
248
|
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var rsp,
|
|
249
|
+
var rsp, e_6;
|
|
277
250
|
return __generator(this, function (_a) {
|
|
278
251
|
switch (_a.label) {
|
|
279
252
|
case 0:
|
|
@@ -290,8 +263,8 @@ var Article = /** @class */ (function () {
|
|
|
290
263
|
rsp = _a.sent();
|
|
291
264
|
return [2 /*return*/, rsp];
|
|
292
265
|
case 2:
|
|
293
|
-
|
|
294
|
-
throw
|
|
266
|
+
e_6 = _a.sent();
|
|
267
|
+
throw e_6;
|
|
295
268
|
case 3: return [2 /*return*/];
|
|
296
269
|
}
|
|
297
270
|
});
|
|
@@ -303,7 +276,7 @@ var Article = /** @class */ (function () {
|
|
|
303
276
|
*/
|
|
304
277
|
Article.prototype.thank = function (id) {
|
|
305
278
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var rsp,
|
|
279
|
+
var rsp, e_7;
|
|
307
280
|
return __generator(this, function (_a) {
|
|
308
281
|
switch (_a.label) {
|
|
309
282
|
case 0:
|
|
@@ -319,8 +292,8 @@ var Article = /** @class */ (function () {
|
|
|
319
292
|
rsp = _a.sent();
|
|
320
293
|
return [2 /*return*/, rsp];
|
|
321
294
|
case 2:
|
|
322
|
-
|
|
323
|
-
throw
|
|
295
|
+
e_7 = _a.sent();
|
|
296
|
+
throw e_7;
|
|
324
297
|
case 3: return [2 /*return*/];
|
|
325
298
|
}
|
|
326
299
|
});
|
|
@@ -332,7 +305,7 @@ var Article = /** @class */ (function () {
|
|
|
332
305
|
*/
|
|
333
306
|
Article.prototype.follow = function (followingId) {
|
|
334
307
|
return __awaiter(this, void 0, void 0, function () {
|
|
335
|
-
var rsp,
|
|
308
|
+
var rsp, e_8;
|
|
336
309
|
return __generator(this, function (_a) {
|
|
337
310
|
switch (_a.label) {
|
|
338
311
|
case 0:
|
|
@@ -349,8 +322,8 @@ var Article = /** @class */ (function () {
|
|
|
349
322
|
rsp = _a.sent();
|
|
350
323
|
return [2 /*return*/, rsp];
|
|
351
324
|
case 2:
|
|
352
|
-
|
|
353
|
-
throw
|
|
325
|
+
e_8 = _a.sent();
|
|
326
|
+
throw e_8;
|
|
354
327
|
case 3: return [2 /*return*/];
|
|
355
328
|
}
|
|
356
329
|
});
|
|
@@ -362,7 +335,7 @@ var Article = /** @class */ (function () {
|
|
|
362
335
|
*/
|
|
363
336
|
Article.prototype.watch = function (followingId) {
|
|
364
337
|
return __awaiter(this, void 0, void 0, function () {
|
|
365
|
-
var rsp,
|
|
338
|
+
var rsp, e_9;
|
|
366
339
|
return __generator(this, function (_a) {
|
|
367
340
|
switch (_a.label) {
|
|
368
341
|
case 0:
|
|
@@ -379,8 +352,8 @@ var Article = /** @class */ (function () {
|
|
|
379
352
|
rsp = _a.sent();
|
|
380
353
|
return [2 /*return*/, rsp];
|
|
381
354
|
case 2:
|
|
382
|
-
|
|
383
|
-
throw
|
|
355
|
+
e_9 = _a.sent();
|
|
356
|
+
throw e_9;
|
|
384
357
|
case 3: return [2 /*return*/];
|
|
385
358
|
}
|
|
386
359
|
});
|
|
@@ -392,7 +365,7 @@ var Article = /** @class */ (function () {
|
|
|
392
365
|
*/
|
|
393
366
|
Article.prototype.reward = function (id) {
|
|
394
367
|
return __awaiter(this, void 0, void 0, function () {
|
|
395
|
-
var rsp,
|
|
368
|
+
var rsp, e_10;
|
|
396
369
|
return __generator(this, function (_a) {
|
|
397
370
|
switch (_a.label) {
|
|
398
371
|
case 0:
|
|
@@ -408,8 +381,8 @@ var Article = /** @class */ (function () {
|
|
|
408
381
|
rsp = _a.sent();
|
|
409
382
|
return [2 /*return*/, rsp];
|
|
410
383
|
case 2:
|
|
411
|
-
|
|
412
|
-
throw
|
|
384
|
+
e_10 = _a.sent();
|
|
385
|
+
throw e_10;
|
|
413
386
|
case 3: return [2 /*return*/];
|
|
414
387
|
}
|
|
415
388
|
});
|
|
@@ -421,7 +394,7 @@ var Article = /** @class */ (function () {
|
|
|
421
394
|
*/
|
|
422
395
|
Article.prototype.heat = function (id) {
|
|
423
396
|
return __awaiter(this, void 0, void 0, function () {
|
|
424
|
-
var rsp,
|
|
397
|
+
var rsp, e_11;
|
|
425
398
|
return __generator(this, function (_a) {
|
|
426
399
|
switch (_a.label) {
|
|
427
400
|
case 0:
|
|
@@ -436,8 +409,8 @@ var Article = /** @class */ (function () {
|
|
|
436
409
|
throw new Error(rsp.msg);
|
|
437
410
|
return [2 /*return*/, rsp.articleHeat];
|
|
438
411
|
case 2:
|
|
439
|
-
|
|
440
|
-
throw
|
|
412
|
+
e_11 = _a.sent();
|
|
413
|
+
throw e_11;
|
|
441
414
|
case 3: return [2 /*return*/];
|
|
442
415
|
}
|
|
443
416
|
});
|
package/lib/chatroom.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResponse, ChatContentType, ChatMessageType, ClientType, ChatRoomMessage, GestureType, Message, MuteItem, RedPacket, RedPacketInfo } from './typing';
|
|
1
|
+
import { ApiResponse, ChatContentType, ChatMessageType, ClientType, ChatRoomMessage, GestureType, Message, MuteItem, RedPacket, RedPacketInfo, IChatRoomNodeInfo } from './typing';
|
|
2
2
|
declare class ChatRoom {
|
|
3
3
|
private _apiKey;
|
|
4
4
|
private _discusse;
|
|
@@ -96,7 +96,7 @@ declare class ChatRoom {
|
|
|
96
96
|
* 获取聊天室节点
|
|
97
97
|
* @returns 返回节点地址
|
|
98
98
|
*/
|
|
99
|
-
getNode(): Promise<
|
|
99
|
+
getNode(): Promise<IChatRoomNodeInfo>;
|
|
100
100
|
/**
|
|
101
101
|
* 重连聊天室
|
|
102
102
|
* @param timeout 超时时间
|
package/lib/chatroom.js
CHANGED
|
@@ -457,21 +457,31 @@ var ChatRoom = /** @class */ (function () {
|
|
|
457
457
|
* @returns 返回节点地址
|
|
458
458
|
*/
|
|
459
459
|
ChatRoom.prototype.getNode = function () {
|
|
460
|
+
var _a;
|
|
460
461
|
return __awaiter(this, void 0, void 0, function () {
|
|
461
462
|
var rsp, e_10;
|
|
462
|
-
return __generator(this, function (
|
|
463
|
-
switch (
|
|
463
|
+
return __generator(this, function (_b) {
|
|
464
|
+
switch (_b.label) {
|
|
464
465
|
case 0:
|
|
465
|
-
|
|
466
|
+
_b.trys.push([0, 2, , 3]);
|
|
466
467
|
return [4 /*yield*/, (0, utils_1.request)({
|
|
467
|
-
url: "chat-room/node/get",
|
|
468
|
+
url: "chat-room/node/get?apiKey=".concat(this._apiKey),
|
|
468
469
|
method: 'get',
|
|
469
470
|
})];
|
|
470
471
|
case 1:
|
|
471
|
-
rsp =
|
|
472
|
-
|
|
472
|
+
rsp = _b.sent();
|
|
473
|
+
if (rsp.code != 0)
|
|
474
|
+
throw new Error("获取节点失败");
|
|
475
|
+
return [2 /*return*/, {
|
|
476
|
+
recommend: {
|
|
477
|
+
node: rsp.data,
|
|
478
|
+
name: rsp.msg,
|
|
479
|
+
online: ((_a = rsp.avaliable.find(function (n) { return n.node === rsp.data; })) === null || _a === void 0 ? void 0 : _a.online) || 0
|
|
480
|
+
},
|
|
481
|
+
avaliable: rsp.avaliable,
|
|
482
|
+
}];
|
|
473
483
|
case 2:
|
|
474
|
-
e_10 =
|
|
484
|
+
e_10 = _b.sent();
|
|
475
485
|
throw e_10;
|
|
476
486
|
case 3: return [2 /*return*/];
|
|
477
487
|
}
|
|
@@ -493,7 +503,7 @@ var ChatRoom = /** @class */ (function () {
|
|
|
493
503
|
switch (_g.label) {
|
|
494
504
|
case 0:
|
|
495
505
|
if (!!url) return [3 /*break*/, 2];
|
|
496
|
-
return [4 /*yield*/, this.getNode()];
|
|
506
|
+
return [4 /*yield*/, this.getNode().then(function (rsp) { return rsp.recommend.node; }).catch(function () { return "wss://".concat(utils_1.domain, "/chat-room-channel?apiKey=").concat(_this._apiKey); })];
|
|
497
507
|
case 1:
|
|
498
508
|
url = _g.sent();
|
|
499
509
|
_g.label = 2;
|
|
@@ -504,11 +514,15 @@ var ChatRoom = /** @class */ (function () {
|
|
|
504
514
|
return __generator(this, function (_f) {
|
|
505
515
|
switch (_f.label) {
|
|
506
516
|
case 0:
|
|
517
|
+
if (this._rws && url !== this._rws.url) {
|
|
518
|
+
this._rws.close();
|
|
519
|
+
this._rws = null;
|
|
520
|
+
}
|
|
507
521
|
if (this._rws)
|
|
508
522
|
return [2 /*return*/, resolve(this._rws.reconnect())];
|
|
509
523
|
_a = this;
|
|
510
524
|
_b = reconnecting_websocket_1.default.bind;
|
|
511
|
-
_c = [void 0, "".concat(url
|
|
525
|
+
_c = [void 0, "".concat(url), []];
|
|
512
526
|
_e = {};
|
|
513
527
|
if (!utils_1.isBrowse) return [3 /*break*/, 1];
|
|
514
528
|
_d = window.WebSocket;
|
package/lib/typing.d.ts
CHANGED
|
@@ -2467,3 +2467,12 @@ export interface Log {
|
|
|
2467
2467
|
*/
|
|
2468
2468
|
type: string;
|
|
2469
2469
|
}
|
|
2470
|
+
export interface IChatRoomNode {
|
|
2471
|
+
node: string;
|
|
2472
|
+
name: string;
|
|
2473
|
+
online?: number;
|
|
2474
|
+
}
|
|
2475
|
+
export interface IChatRoomNodeInfo {
|
|
2476
|
+
recommend: IChatRoomNode;
|
|
2477
|
+
avaliable: IChatRoomNode[];
|
|
2478
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fishpi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "A Package to use API of fishpi.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/FishPiOffical/fishpi.js.git"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"keywords": [],
|
|
31
31
|
"bugs": {
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/FishPiOffical/fishpi.js/issues"
|
|
33
33
|
},
|
|
34
|
-
"homepage": "https://github.com/
|
|
34
|
+
"homepage": "https://github.com/FishPiOffical/fishpi.js#readme",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@types/js-md5": "^0.7.0",
|
|
37
37
|
"form-data": "^4.0.0",
|