fishpi 0.0.1 → 0.0.4
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 +56 -18
- package/package.json +48 -47
- package/lib/chatroom.d.ts +0 -27
- package/lib/chatroom.js +0 -271
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -150
- package/lib/src/chatroom.d.ts +0 -82
- package/lib/src/chatroom.js +0 -350
- package/lib/src/index.d.ts +0 -67
- package/lib/src/index.js +0 -295
- package/lib/src/notice.d.ts +0 -33
- package/lib/src/notice.js +0 -100
- package/lib/src/utils.d.ts +0 -5
- package/lib/src/utils.js +0 -83
- package/lib/test/index.d.ts +0 -1
- package/lib/test/index.js +0 -27
- package/lib/utils.d.ts +0 -3
- package/lib/utils.js +0 -65
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,18 +1,56 @@
|
|
|
1
|
-
# 摸鱼派 API Package
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
```
|
|
1
|
+
# 摸鱼派 API Package
|
|
2
|
+
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
|
|
3
|
+
|
|
4
|
+
## 支援
|
|
5
|
+
- 用户信息;
|
|
6
|
+
- 聊天室;
|
|
7
|
+
- 话题编辑;
|
|
8
|
+
- 红包收发;
|
|
9
|
+
- 自定义表情包;
|
|
10
|
+
- 文件上传;
|
|
11
|
+
- 通知信息;
|
|
12
|
+
- 清风明月;
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install fishpi
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 用例
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import FishPi from 'fishpi';
|
|
24
|
+
|
|
25
|
+
// 登录获取 apiKey
|
|
26
|
+
let apiKey = '';
|
|
27
|
+
let fish = new FishPi();
|
|
28
|
+
let rsp = await fish.login({
|
|
29
|
+
username: 'username',
|
|
30
|
+
passwd: 'password123456'
|
|
31
|
+
});
|
|
32
|
+
if (rsp.code == 0) apiKey = rsp.Key;
|
|
33
|
+
|
|
34
|
+
// 通过 apiKey 获取登录用户信息
|
|
35
|
+
let fish = new FishPi(apiKey);
|
|
36
|
+
console.dir(await fish.account.info());
|
|
37
|
+
|
|
38
|
+
// 获取用户自定义表情包
|
|
39
|
+
let emojis = await fish.emoji.get();
|
|
40
|
+
// 获取默认表情包
|
|
41
|
+
let defaultEmoji = fish.emoji.default;
|
|
42
|
+
|
|
43
|
+
// 监听聊天室消息
|
|
44
|
+
fish.chatroom.addListener((ev:any) => console.dir(ev));
|
|
45
|
+
// 向聊天室发送信息(需要登录)
|
|
46
|
+
await fish.chatroom.send('Hello World!');
|
|
47
|
+
// 向聊天室发送红包
|
|
48
|
+
await fish.chatroom.redpacket.send({
|
|
49
|
+
type: 'random';
|
|
50
|
+
money: 32;
|
|
51
|
+
count: 2;
|
|
52
|
+
msg: '摸鱼者,事竟成!';
|
|
53
|
+
recivers: [];
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
```
|
package/package.json
CHANGED
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "fishpi",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A Package to use API of fishpi.",
|
|
5
|
-
"main": "./lib/src/index.js",
|
|
6
|
-
"files": [
|
|
7
|
-
"lib/**/*"
|
|
8
|
-
],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"@types/
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "fishpi",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "A Package to use API of fishpi.",
|
|
5
|
+
"main": "./lib/src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/**/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prebuild": "rm -rf lib",
|
|
11
|
+
"build": "tsc"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/imlinhanchao/fishpi-api-package.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Hancel.Lin",
|
|
20
|
+
"email": "imlinhanchao@foxmail.com",
|
|
21
|
+
"url": "https://github.com/imlinhanchao"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=12.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [],
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/imlinhanchao/fishpi-api-package/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"axios": "^0.25.0",
|
|
33
|
+
"form-data": "^4.0.0",
|
|
34
|
+
"reconnecting-websocket": "^4.4.0",
|
|
35
|
+
"ws": "^8.4.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^12.20.11",
|
|
39
|
+
"@types/ws": "^8.2.2",
|
|
40
|
+
"ts-node": "^10.2.1",
|
|
41
|
+
"typescript": "^4.2.4"
|
|
42
|
+
},
|
|
43
|
+
"release": {
|
|
44
|
+
"branches": [
|
|
45
|
+
"master"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
}
|
package/lib/chatroom.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, ChatRoomMessage } from '..';
|
|
2
|
-
declare class ChatRoom {
|
|
3
|
-
private _token;
|
|
4
|
-
private _onlines;
|
|
5
|
-
private _rws;
|
|
6
|
-
private _wsTimer;
|
|
7
|
-
private _wsCallbacks;
|
|
8
|
-
constructor(token?: string);
|
|
9
|
-
get onlines(): any[];
|
|
10
|
-
setToken(token: string): void;
|
|
11
|
-
more(page?: number): Promise<ApiResponse<Array<ChatRoomMessage>>>;
|
|
12
|
-
revoke(oId: string): Promise<ApiResponse<undefined>>;
|
|
13
|
-
push(msg: string): Promise<{
|
|
14
|
-
code: number;
|
|
15
|
-
}>;
|
|
16
|
-
raw(oId: string): Promise<string>;
|
|
17
|
-
get emoji(): {
|
|
18
|
-
get(): Promise<Array<string>>;
|
|
19
|
-
set(data: Array<string>): Promise<any>;
|
|
20
|
-
};
|
|
21
|
-
get redpacket(): {
|
|
22
|
-
open(oId: string): Promise<any>;
|
|
23
|
-
};
|
|
24
|
-
removeListener(wsCallback: Function): void;
|
|
25
|
-
addListener(wsCallback: Function): void;
|
|
26
|
-
}
|
|
27
|
-
export default ChatRoom;
|
package/lib/chatroom.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
|
|
16
|
-
const ws_1 = __importDefault(require("ws"));
|
|
17
|
-
const utils_1 = require("./utils");
|
|
18
|
-
class ChatRoom {
|
|
19
|
-
constructor(token = '') {
|
|
20
|
-
this._token = '';
|
|
21
|
-
this._onlines = [];
|
|
22
|
-
this._rws = null;
|
|
23
|
-
this._wsTimer = null;
|
|
24
|
-
this._wsCallbacks = [];
|
|
25
|
-
if (!token) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
this._token = token;
|
|
29
|
-
}
|
|
30
|
-
get onlines() {
|
|
31
|
-
return this._onlines;
|
|
32
|
-
}
|
|
33
|
-
setToken(token) {
|
|
34
|
-
this._token = token;
|
|
35
|
-
}
|
|
36
|
-
more(page = 1) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
try {
|
|
39
|
-
let rsp = yield (0, utils_1.request)({
|
|
40
|
-
url: `chat-room/more?page=${page}&apiKey=${this._token}`
|
|
41
|
-
});
|
|
42
|
-
if (rsp.status === 401) {
|
|
43
|
-
throw new Error('登录已失效,请重新登录!');
|
|
44
|
-
}
|
|
45
|
-
if (rsp.code != 0) {
|
|
46
|
-
throw new Error(rsp.msg);
|
|
47
|
-
}
|
|
48
|
-
rsp = rsp.data;
|
|
49
|
-
if (!rsp.data)
|
|
50
|
-
return rsp;
|
|
51
|
-
let redpacket;
|
|
52
|
-
rsp.data.forEach((d, i, data) => {
|
|
53
|
-
try {
|
|
54
|
-
redpacket = JSON.parse(d.content);
|
|
55
|
-
if (redpacket.msgType !== 'msgType')
|
|
56
|
-
return rsp;
|
|
57
|
-
redpacket.recivers = JSON.parse(redpacket.recivers);
|
|
58
|
-
data[i].content = redpacket;
|
|
59
|
-
}
|
|
60
|
-
catch (e) { }
|
|
61
|
-
});
|
|
62
|
-
return rsp;
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
throw e;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
revoke(oId) {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
let rsp;
|
|
72
|
-
try {
|
|
73
|
-
rsp = yield (0, utils_1.request)({
|
|
74
|
-
url: `chat-room/revoke/${oId}`,
|
|
75
|
-
method: 'delete',
|
|
76
|
-
data: {
|
|
77
|
-
apiKey: this._token
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
if (rsp.status === 401) {
|
|
81
|
-
throw new Error('登录已失效,请重新登录!');
|
|
82
|
-
}
|
|
83
|
-
return rsp.data;
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
throw e;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
push(msg) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
let rsp;
|
|
93
|
-
try {
|
|
94
|
-
rsp = yield (0, utils_1.request)({
|
|
95
|
-
url: `chat-room/send`,
|
|
96
|
-
method: 'post',
|
|
97
|
-
data: {
|
|
98
|
-
content: msg,
|
|
99
|
-
apiKey: this._token
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
if (rsp.status === 401) {
|
|
103
|
-
throw new Error('登录已失效,请重新登录!');
|
|
104
|
-
}
|
|
105
|
-
return rsp.data;
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
throw e;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
raw(oId) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
let rsp;
|
|
115
|
-
try {
|
|
116
|
-
rsp = yield (0, utils_1.request)({
|
|
117
|
-
url: `cr/raw/${oId}`,
|
|
118
|
-
});
|
|
119
|
-
return rsp.data.replace(/<!--.*?-->/g, '');
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
get emoji() {
|
|
127
|
-
let apiKey = this._token;
|
|
128
|
-
return {
|
|
129
|
-
get() {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
let rsp;
|
|
132
|
-
try {
|
|
133
|
-
rsp = yield (0, utils_1.request)({
|
|
134
|
-
url: `api/cloud/get`,
|
|
135
|
-
method: 'post',
|
|
136
|
-
data: {
|
|
137
|
-
gameId: 'emojis',
|
|
138
|
-
apiKey
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
if (rsp.status === 401) {
|
|
142
|
-
throw new Error('登录已失效,请重新登录!');
|
|
143
|
-
}
|
|
144
|
-
return JSON.parse(rsp.data.data);
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
throw e;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
set(data) {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
let rsp;
|
|
154
|
-
try {
|
|
155
|
-
rsp = yield (0, utils_1.request)({
|
|
156
|
-
url: `api/cloud/sync`,
|
|
157
|
-
method: 'post',
|
|
158
|
-
data: {
|
|
159
|
-
gameId: 'emojis',
|
|
160
|
-
data: JSON.stringify(data),
|
|
161
|
-
apiKey
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
if (rsp.status === 401) {
|
|
165
|
-
throw new Error('登录已失效,请重新登录!');
|
|
166
|
-
}
|
|
167
|
-
return rsp.data;
|
|
168
|
-
}
|
|
169
|
-
catch (e) {
|
|
170
|
-
throw e;
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
get redpacket() {
|
|
177
|
-
let apiKey = this._token;
|
|
178
|
-
return {
|
|
179
|
-
open(oId) {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
let rsp;
|
|
182
|
-
try {
|
|
183
|
-
rsp = yield (0, utils_1.request)({
|
|
184
|
-
url: `chat-room/red-packet/open`,
|
|
185
|
-
method: 'post',
|
|
186
|
-
data: {
|
|
187
|
-
oId,
|
|
188
|
-
apiKey
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
if (rsp.status === 401) {
|
|
192
|
-
throw new Error('登录已失效,请重新登录!');
|
|
193
|
-
}
|
|
194
|
-
return rsp.data;
|
|
195
|
-
}
|
|
196
|
-
catch (e) {
|
|
197
|
-
throw e;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
removeListener(wsCallback) {
|
|
204
|
-
if (this._wsCallbacks.indexOf(wsCallback) < 0)
|
|
205
|
-
return;
|
|
206
|
-
this._wsCallbacks.splice(this._wsCallbacks.indexOf(wsCallback), 1);
|
|
207
|
-
}
|
|
208
|
-
addListener(wsCallback) {
|
|
209
|
-
if (this._rws !== null) {
|
|
210
|
-
if (this._wsCallbacks.indexOf(wsCallback) < 0)
|
|
211
|
-
this._wsCallbacks.push(wsCallback);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
this._rws = new reconnecting_websocket_1.default(`wss://${utils_1.domain}/chat-room-channel?apiKey=${this._token}`, [], {
|
|
215
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
216
|
-
WebSocket: ws_1.default,
|
|
217
|
-
connectionTimeout: 10000
|
|
218
|
-
});
|
|
219
|
-
this._rws.onopen = (e) => {
|
|
220
|
-
if (this._wsTimer) {
|
|
221
|
-
clearInterval(this._wsTimer);
|
|
222
|
-
}
|
|
223
|
-
this._wsTimer = setInterval(() => {
|
|
224
|
-
var _a;
|
|
225
|
-
(_a = this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
|
|
226
|
-
}, 1000 * 60 * 3);
|
|
227
|
-
};
|
|
228
|
-
this._rws.onmessage = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
229
|
-
let msg = JSON.parse(e.data);
|
|
230
|
-
let data = null;
|
|
231
|
-
switch (msg.type) {
|
|
232
|
-
case 'online': {
|
|
233
|
-
data = this._onlines = msg.users;
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
case 'revoke': {
|
|
237
|
-
data = msg.oId;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case 'msg': {
|
|
241
|
-
let { oId, time, userName, userNickname, userAvatarURL, content, md } = msg;
|
|
242
|
-
try {
|
|
243
|
-
let { msg, recivers, money, count, type, got, who, msgType } = JSON.parse(content);
|
|
244
|
-
if (msgType === 'redPacket') {
|
|
245
|
-
data = {
|
|
246
|
-
oId, time, userName, userNickname, userAvatarURL,
|
|
247
|
-
redpacket: { msg, recivers, money, count, type, got, who }
|
|
248
|
-
};
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (e) { }
|
|
253
|
-
data = { oId, time, userName, userNickname, userAvatarURL, content, md };
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
case 'redPacketStatus': {
|
|
257
|
-
let { oId, count, got, whoGive, whoGot } = msg;
|
|
258
|
-
data = { oId, count, got, whoGive, whoGot };
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
this._wsCallbacks.forEach(call => call(Object.assign({ msg: { type: msg.type, data } }, e)));
|
|
263
|
-
});
|
|
264
|
-
this._rws.onerror = (e) => {
|
|
265
|
-
console.error(e);
|
|
266
|
-
};
|
|
267
|
-
this._rws.onclose = (e) => {
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
exports.default = ChatRoom;
|
package/lib/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, Account, UserInfo, AtUserList } from '..';
|
|
2
|
-
import ChatRoom from './chatroom';
|
|
3
|
-
declare class FishPi {
|
|
4
|
-
token: string;
|
|
5
|
-
chat: ChatRoom;
|
|
6
|
-
constructor(token: string);
|
|
7
|
-
login(data: Account): Promise<ApiResponse<string>>;
|
|
8
|
-
info(): Promise<ApiResponse<UserInfo>>;
|
|
9
|
-
atlist(name: string): Promise<AtUserList>;
|
|
10
|
-
upload(files: Array<string>): Promise<any>;
|
|
11
|
-
liveness(): Promise<any>;
|
|
12
|
-
}
|
|
13
|
-
export default FishPi;
|
package/lib/index.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
const crypto = __importStar(require("crypto"));
|
|
35
|
-
const fs = __importStar(require("fs"));
|
|
36
|
-
const path = __importStar(require("path"));
|
|
37
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
38
|
-
const utils_1 = require("./utils");
|
|
39
|
-
const chatroom_1 = __importDefault(require("./chatroom"));
|
|
40
|
-
class FishPi {
|
|
41
|
-
constructor(token) {
|
|
42
|
-
this.token = '';
|
|
43
|
-
this.chat = new chatroom_1.default();
|
|
44
|
-
if (!token) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this.token = token;
|
|
48
|
-
this.chat.setToken(this.token);
|
|
49
|
-
}
|
|
50
|
-
login(data) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
try {
|
|
53
|
-
let md5 = crypto.createHash('md5');
|
|
54
|
-
let rsp = yield (0, utils_1.request)({
|
|
55
|
-
url: 'api/getKey',
|
|
56
|
-
method: 'post',
|
|
57
|
-
data: {
|
|
58
|
-
nameOrEmail: data.username,
|
|
59
|
-
userPassword: md5.update(data.passwd).digest('hex')
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
this.token = rsp.data.Key;
|
|
63
|
-
this.chat.setToken(this.token);
|
|
64
|
-
return rsp.data;
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
throw e;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
info() {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
try {
|
|
74
|
-
let rsp = yield (0, utils_1.request)({
|
|
75
|
-
url: `api/user?apiKey=${this.token}`
|
|
76
|
-
});
|
|
77
|
-
if (rsp.status === 401) {
|
|
78
|
-
throw new Error('登录已失效,请重新登录!');
|
|
79
|
-
}
|
|
80
|
-
return rsp.data;
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
throw e;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
atlist(name) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
let rsp;
|
|
90
|
-
try {
|
|
91
|
-
rsp = yield (0, utils_1.request)({
|
|
92
|
-
url: `users/names`,
|
|
93
|
-
method: 'post',
|
|
94
|
-
data: {
|
|
95
|
-
name
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
if (rsp.status === 401) {
|
|
99
|
-
throw new Error('登录已失效,请重新登录!');
|
|
100
|
-
}
|
|
101
|
-
return rsp.data.data;
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
throw e;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
upload(files) {
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
let data = new form_data_1.default();
|
|
111
|
-
files.forEach(f => data.append('file[]', fs.readFileSync(f), path.basename(f)));
|
|
112
|
-
let rsp;
|
|
113
|
-
try {
|
|
114
|
-
rsp = yield (0, utils_1.request)({
|
|
115
|
-
url: `upload`,
|
|
116
|
-
method: 'post',
|
|
117
|
-
data,
|
|
118
|
-
headers: data.getHeaders()
|
|
119
|
-
});
|
|
120
|
-
if (rsp.status === 401) {
|
|
121
|
-
throw new Error('登录已失效,请重新登录!');
|
|
122
|
-
}
|
|
123
|
-
return rsp.data;
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
throw e;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
liveness() {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
if (!this.token) {
|
|
133
|
-
return 0;
|
|
134
|
-
}
|
|
135
|
-
try {
|
|
136
|
-
let rsp = yield (0, utils_1.request)({
|
|
137
|
-
url: `user/liveness?apiKey=${this.token}`
|
|
138
|
-
});
|
|
139
|
-
if (rsp.status === 401) {
|
|
140
|
-
throw new Error('登录已失效,请重新登录!');
|
|
141
|
-
}
|
|
142
|
-
return rsp.data.liveness;
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
throw e;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.default = FishPi;
|