fishpi 0.0.2 → 0.0.5

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 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,52 +1,56 @@
1
- # 摸鱼派 API Package
2
- 摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
3
-
4
- ## 支援
5
- - 用户信息;
6
- - 聊天室;
7
- - 文件上传;
8
- - 通知信息;
9
-
10
- ## 安装
11
-
12
- ```bash
13
- npm install fishpi
14
- ```
15
-
16
- ## 用例
17
-
18
- ```ts
19
- import FishPi from 'fishpi';
20
-
21
- // 登录获取 apiKey
22
- let apiKey = '';
23
- let fish = new FishPi();
24
- let rsp = await fish.login({
25
- username: 'username',
26
- passwd: 'password123456'
27
- });
28
- if (rsp.code == 0) apiKey = rsp.Key;
29
-
30
- // 通过 apiKey 获取登录用户信息
31
- let fish = new FishPi(apiKey);
32
- console.dir(await fish.info());
33
-
34
- // 获取用户自定义表情包
35
- let emojis = fish.emoji.get();
36
- // 获取默认表情包
37
- let defaultEmoji = fish.emoji.default;
38
-
39
- // 监听聊天室消息
40
- fish.chatroom.addListener((ev:any) => console.dir(ev));
41
- // 向聊天室发送信息(需要登录)
42
- fish.chatroom.send('Hello World!');
43
- // 向聊天室发送红包
44
- fish.chatroom.redpacket.send({
45
- type: 'random';
46
- money: 32;
47
- count: 2;
48
- msg: '摸鱼者,事竟成!';
49
- recivers: [];
50
- })
51
-
52
- ```
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,48 +1,48 @@
1
- {
2
- "name": "fishpi",
3
- "version": "0.0.2",
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
- }
1
+ {
2
+ "name": "fishpi",
3
+ "version": "0.0.5",
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
+ }
@@ -1,82 +0,0 @@
1
- import { ApiResponse, ChatRoomMessage, RedPacket } from './typing';
2
- declare class ChatRoom {
3
- private _apiKey;
4
- private _onlines;
5
- private _rws;
6
- private _wsTimer;
7
- private _wsCallbacks;
8
- constructor(token?: string);
9
- /**
10
- * 当前在线人数列表,需要先调用 addListener 添加聊天室消息监听
11
- */
12
- get onlines(): any[];
13
- /**
14
- * 重新设置请求 Token
15
- * @param apiKey 接口 API Key
16
- */
17
- setToken(apiKey: string): void;
18
- /**
19
- * 查询聊天室历史消息
20
- * @param page 消息页码
21
- */
22
- more(page?: number): Promise<ApiResponse<Array<ChatRoomMessage>>>;
23
- /**
24
- * 撤回消息,普通成员 24 小时内可撤回一条自己的消息,纪律委员/OP/管理员角色可以撤回任意人消息
25
- * @param oId 消息 Id
26
- */
27
- revoke(oId: string): Promise<ApiResponse<undefined>>;
28
- /**
29
- * 发送一条消息
30
- * @param msg 消息内容,支持 Markdown
31
- */
32
- send(msg: string): Promise<{
33
- code: number;
34
- }>;
35
- /**
36
- * 获取消息原文(比如 Markdown)
37
- * @param oId 消息 Id
38
- */
39
- raw(oId: string): Promise<string>;
40
- /**
41
- * 表情包接口对象
42
- */
43
- get emoji(): {
44
- /**
45
- * 获取表情包图像列表
46
- */
47
- get(): Promise<Array<string>>;
48
- /**
49
- * 设置表情包列表
50
- * @param data 所有表情包图像列表
51
- */
52
- set(data: Array<string>): Promise<any>;
53
- };
54
- /**
55
- * 红包接口对象
56
- */
57
- get redpacket(): {
58
- /**
59
- * 打开一个红包
60
- * @param oId 红包消息 Id
61
- */
62
- open(oId: string): Promise<any>;
63
- /**
64
- * 发送一个红包
65
- * @param redpacket 红包对象
66
- */
67
- send(redpacket: RedPacket): Promise<{
68
- code: number;
69
- }>;
70
- };
71
- /**
72
- * 移除聊天室消息监听函数
73
- * @param wsCallback 消息监听函数
74
- */
75
- removeListener(wsCallback: Function): void;
76
- /**
77
- * 添加聊天室消息监听函数
78
- * @param wsCallback 消息监听函数
79
- */
80
- addListener(wsCallback: Function): Promise<void>;
81
- }
82
- export default ChatRoom;
@@ -1,352 +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 reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
35
- const utils_1 = require("./utils");
36
- class ChatRoom {
37
- constructor(token = '') {
38
- this._apiKey = '';
39
- this._onlines = [];
40
- this._rws = null;
41
- this._wsTimer = null;
42
- this._wsCallbacks = [];
43
- if (!token) {
44
- return;
45
- }
46
- this._apiKey = token;
47
- }
48
- /**
49
- * 当前在线人数列表,需要先调用 addListener 添加聊天室消息监听
50
- */
51
- get onlines() {
52
- return this._onlines;
53
- }
54
- /**
55
- * 重新设置请求 Token
56
- * @param apiKey 接口 API Key
57
- */
58
- setToken(apiKey) {
59
- this._apiKey = apiKey;
60
- }
61
- /**
62
- * 查询聊天室历史消息
63
- * @param page 消息页码
64
- */
65
- more(page = 1) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- try {
68
- let rsp = yield (0, utils_1.request)({
69
- url: `chat-room/more?page=${page}&apiKey=${this._apiKey}`
70
- });
71
- if (rsp.status === 401) {
72
- throw new Error('登录已失效,请重新登录!');
73
- }
74
- if (rsp.code != 0) {
75
- throw new Error(rsp.msg);
76
- }
77
- rsp = rsp.data;
78
- if (!rsp.data)
79
- return rsp;
80
- let redpacket;
81
- rsp.data.forEach((d, i, data) => {
82
- try {
83
- data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
84
- redpacket = JSON.parse(d.content);
85
- if (redpacket.msgType !== 'msgType')
86
- return rsp;
87
- redpacket.recivers = JSON.parse(redpacket.recivers);
88
- data[i].content = redpacket;
89
- }
90
- catch (e) { }
91
- });
92
- return rsp;
93
- }
94
- catch (e) {
95
- throw e;
96
- }
97
- });
98
- }
99
- /**
100
- * 撤回消息,普通成员 24 小时内可撤回一条自己的消息,纪律委员/OP/管理员角色可以撤回任意人消息
101
- * @param oId 消息 Id
102
- */
103
- revoke(oId) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- let rsp;
106
- try {
107
- rsp = yield (0, utils_1.request)({
108
- url: `chat-room/revoke/${oId}`,
109
- method: 'delete',
110
- data: {
111
- apiKey: this._apiKey
112
- },
113
- });
114
- if (rsp.status === 401) {
115
- throw new Error('登录已失效,请重新登录!');
116
- }
117
- return rsp.data;
118
- }
119
- catch (e) {
120
- throw e;
121
- }
122
- });
123
- }
124
- /**
125
- * 发送一条消息
126
- * @param msg 消息内容,支持 Markdown
127
- */
128
- send(msg) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- let rsp;
131
- try {
132
- rsp = yield (0, utils_1.request)({
133
- url: `chat-room/send`,
134
- method: 'post',
135
- data: {
136
- content: msg,
137
- apiKey: this._apiKey
138
- },
139
- });
140
- if (rsp.status === 401) {
141
- throw new Error('登录已失效,请重新登录!');
142
- }
143
- return rsp.data;
144
- }
145
- catch (e) {
146
- throw e;
147
- }
148
- });
149
- }
150
- /**
151
- * 获取消息原文(比如 Markdown)
152
- * @param oId 消息 Id
153
- */
154
- raw(oId) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- let rsp;
157
- try {
158
- rsp = yield (0, utils_1.request)({
159
- url: `cr/raw/${oId}`,
160
- });
161
- return rsp.data.replace(/<!--.*?-->/g, '');
162
- }
163
- catch (e) {
164
- throw e;
165
- }
166
- });
167
- }
168
- /**
169
- * 表情包接口对象
170
- */
171
- get emoji() {
172
- let apiKey = this._apiKey;
173
- return {
174
- /**
175
- * 获取表情包图像列表
176
- */
177
- get() {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- let rsp;
180
- try {
181
- rsp = yield (0, utils_1.request)({
182
- url: `api/cloud/get`,
183
- method: 'post',
184
- data: {
185
- gameId: 'emojis',
186
- apiKey
187
- },
188
- });
189
- if (rsp.status === 401) {
190
- throw new Error('登录已失效,请重新登录!');
191
- }
192
- return JSON.parse(rsp.data.data);
193
- }
194
- catch (e) {
195
- throw e;
196
- }
197
- });
198
- },
199
- /**
200
- * 设置表情包列表
201
- * @param data 所有表情包图像列表
202
- */
203
- set(data) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- let rsp;
206
- try {
207
- rsp = yield (0, utils_1.request)({
208
- url: `api/cloud/sync`,
209
- method: 'post',
210
- data: {
211
- gameId: 'emojis',
212
- data: JSON.stringify(data),
213
- apiKey
214
- },
215
- });
216
- if (rsp.status === 401) {
217
- throw new Error('登录已失效,请重新登录!');
218
- }
219
- return rsp.data;
220
- }
221
- catch (e) {
222
- throw e;
223
- }
224
- });
225
- }
226
- };
227
- }
228
- /**
229
- * 红包接口对象
230
- */
231
- get redpacket() {
232
- let apiKey = this._apiKey;
233
- let that = this;
234
- return {
235
- /**
236
- * 打开一个红包
237
- * @param oId 红包消息 Id
238
- */
239
- open(oId) {
240
- return __awaiter(this, void 0, void 0, function* () {
241
- let rsp;
242
- try {
243
- rsp = yield (0, utils_1.request)({
244
- url: `chat-room/red-packet/open`,
245
- method: 'post',
246
- data: {
247
- oId,
248
- apiKey
249
- },
250
- });
251
- if (rsp.status === 401) {
252
- throw new Error('登录已失效,请重新登录!');
253
- }
254
- return rsp.data;
255
- }
256
- catch (e) {
257
- throw e;
258
- }
259
- });
260
- },
261
- /**
262
- * 发送一个红包
263
- * @param redpacket 红包对象
264
- */
265
- send(redpacket) {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- return yield that.send(`[redpacket]${JSON.stringify(redpacket)}[/redpacket]`);
268
- });
269
- }
270
- };
271
- }
272
- /**
273
- * 移除聊天室消息监听函数
274
- * @param wsCallback 消息监听函数
275
- */
276
- removeListener(wsCallback) {
277
- if (this._wsCallbacks.indexOf(wsCallback) < 0)
278
- return;
279
- this._wsCallbacks.splice(this._wsCallbacks.indexOf(wsCallback), 1);
280
- }
281
- /**
282
- * 添加聊天室消息监听函数
283
- * @param wsCallback 消息监听函数
284
- */
285
- addListener(wsCallback) {
286
- return __awaiter(this, void 0, void 0, function* () {
287
- if (this._rws !== null) {
288
- if (this._wsCallbacks.indexOf(wsCallback) < 0)
289
- this._wsCallbacks.push(wsCallback);
290
- return;
291
- }
292
- this._wsCallbacks.push(wsCallback);
293
- this._rws = new reconnecting_websocket_1.default(`wss://${utils_1.domain}chat-room-channel?apiKey=${this._apiKey}`, [], {
294
- // eslint-disable-next-line @typescript-eslint/naming-convention
295
- WebSocket: utils_1.isBrowse ? window.WebSocket : (yield Promise.resolve().then(() => __importStar(require('ws')))).WebSocket,
296
- connectionTimeout: 10000
297
- });
298
- this._rws.onopen = (e) => {
299
- if (this._wsTimer) {
300
- clearInterval(this._wsTimer);
301
- }
302
- this._wsTimer = setInterval(() => {
303
- var _a;
304
- (_a = this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-');
305
- }, 1000 * 60 * 3);
306
- };
307
- this._rws.onmessage = (e) => __awaiter(this, void 0, void 0, function* () {
308
- let msg = JSON.parse(e.data);
309
- let data = null;
310
- switch (msg.type) {
311
- case 'online': {
312
- data = this._onlines = msg.users;
313
- break;
314
- }
315
- case 'revoke': {
316
- data = msg.oId;
317
- break;
318
- }
319
- case 'msg': {
320
- let { oId, time, userName, userNickname, userAvatarURL, content, md } = msg;
321
- try {
322
- let { msg, recivers, money, count, type, got, who, msgType } = JSON.parse(content);
323
- if (msgType === 'redPacket') {
324
- data = {
325
- oId, time, userName, userNickname, userAvatarURL,
326
- redpacket: { msg, recivers, money, count, type, got, who }
327
- };
328
- msg.type = 'redPacket';
329
- break;
330
- }
331
- }
332
- catch (e) { }
333
- data = { oId, time, userName, userNickname, userAvatarURL, content, md };
334
- break;
335
- }
336
- case 'redPacketStatus': {
337
- let { oId, count, got, whoGive, whoGot } = msg;
338
- data = { oId, count, got, whoGive, whoGot };
339
- break;
340
- }
341
- }
342
- this._wsCallbacks.forEach(call => call(Object.assign({ msg: { type: msg.type, data } }, e)));
343
- });
344
- this._rws.onerror = (e) => {
345
- console.error(e);
346
- };
347
- this._rws.onclose = (e) => {
348
- };
349
- });
350
- }
351
- }
352
- exports.default = ChatRoom;
@@ -1,67 +0,0 @@
1
- import { ApiResponse, Account, UserInfo, AtUserList, UploadInfo } from './typing';
2
- import ChatRoom from './chatroom';
3
- import Notice from './notice';
4
- declare class FishPi {
5
- /**
6
- * 请求 API 的 API Key
7
- */
8
- apiKey: string;
9
- /**
10
- * 聊天室接口对象
11
- */
12
- chatroom: ChatRoom;
13
- /**
14
- * 通知接口对象
15
- */
16
- notice: Notice;
17
- /**
18
- * 构造一个 API 请求对象
19
- * @param token 接口 API Key,没有可以传空
20
- */
21
- constructor(token?: string);
22
- /**
23
- * 登录账号返回 API Key
24
- * @param data 用户账密
25
- */
26
- login(data: Account): Promise<ApiResponse<string>>;
27
- /**
28
- * 返回登录账户信息,需要先登录或设置有效的 api key
29
- */
30
- info(): Promise<ApiResponse<UserInfo>>;
31
- /**
32
- * 查询指定用户信息
33
- * @param username 用户名
34
- */
35
- user(username: string): Promise<ApiResponse<UserInfo>>;
36
- /**
37
- * 用户名联想,通常用于 @ 列表
38
- * @param username 用户名
39
- */
40
- names(name: string): Promise<AtUserList>;
41
- /**
42
- * 查询登录用户常用表情
43
- */
44
- emotions(): Promise<ApiResponse<Array<string>>>;
45
- /**
46
- * 查询登录用户当前活跃度,请求频率请控制在 30 ~ 60 秒一次
47
- */
48
- liveness(): Promise<number>;
49
- /**
50
- * 检查登录用户是否已经签到
51
- */
52
- isCheckIn(): Promise<boolean>;
53
- /**
54
- * 检查登录用户是否已经领取昨日活跃奖励
55
- */
56
- isCollectedLiveness(): Promise<boolean>;
57
- /**
58
- * 领取昨日活跃度奖励
59
- */
60
- rewardLiveness(): Promise<number>;
61
- /**
62
- * 上传文件
63
- * @param files 要上传的文件,如果是在 Node 使用,则传入文件路径数组,若是在浏览器使用,则传入文件对象数组。
64
- */
65
- upload(files: Array<File | string>): Promise<UploadInfo>;
66
- }
67
- export default FishPi;
package/lib/src/index.js DELETED
@@ -1,296 +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 utils_1 = require("./utils");
38
- const chatroom_1 = __importDefault(require("./chatroom"));
39
- const notice_1 = __importDefault(require("./notice"));
40
- class FishPi {
41
- /**
42
- * 构造一个 API 请求对象
43
- * @param token 接口 API Key,没有可以传空
44
- */
45
- constructor(token = '') {
46
- /**
47
- * 请求 API 的 API Key
48
- */
49
- this.apiKey = '';
50
- /**
51
- * 聊天室接口对象
52
- */
53
- this.chatroom = new chatroom_1.default();
54
- /**
55
- * 通知接口对象
56
- */
57
- this.notice = new notice_1.default();
58
- if (!token) {
59
- return;
60
- }
61
- this.apiKey = token;
62
- this.chatroom.setToken(this.apiKey);
63
- this.notice.setToken(this.apiKey);
64
- }
65
- /**
66
- * 登录账号返回 API Key
67
- * @param data 用户账密
68
- */
69
- login(data) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- try {
72
- let md5 = crypto.createHash('md5');
73
- let rsp = yield (0, utils_1.request)({
74
- url: 'api/getKey',
75
- method: 'post',
76
- data: {
77
- nameOrEmail: data.username,
78
- userPassword: md5.update(data.passwd).digest('hex')
79
- },
80
- });
81
- this.apiKey = rsp.data.Key;
82
- this.chatroom.setToken(this.apiKey);
83
- this.notice.setToken(this.apiKey);
84
- return rsp.data;
85
- }
86
- catch (e) {
87
- throw e;
88
- }
89
- });
90
- }
91
- /**
92
- * 返回登录账户信息,需要先登录或设置有效的 api key
93
- */
94
- info() {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- try {
97
- let rsp = yield (0, utils_1.request)({
98
- url: `api/user?apiKey=${this.apiKey}`
99
- });
100
- if (rsp.status === 401) {
101
- return { code: -1, msg: '登录已失效,请重新登录!' };
102
- }
103
- if (rsp.data.data)
104
- rsp.data.data.sysMetal = (0, utils_1.toMetal)(rsp.data.data.sysMetal);
105
- return rsp.data;
106
- }
107
- catch (e) {
108
- throw e;
109
- }
110
- });
111
- }
112
- /**
113
- * 查询指定用户信息
114
- * @param username 用户名
115
- */
116
- user(username) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- try {
119
- let rsp = yield (0, utils_1.request)({
120
- url: `user/${username}?apiKey=${this.apiKey}`
121
- });
122
- if (rsp.status === 401) {
123
- return { code: -1, msg: '登录已失效,请重新登录!' };
124
- }
125
- rsp.data.data.sysMetal = (0, utils_1.toMetal)(rsp.data.data.sysMetal);
126
- return rsp.data;
127
- }
128
- catch (e) {
129
- throw e;
130
- }
131
- });
132
- }
133
- /**
134
- * 用户名联想,通常用于 @ 列表
135
- * @param username 用户名
136
- */
137
- names(name) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- let rsp;
140
- try {
141
- rsp = yield (0, utils_1.request)({
142
- url: `users/names`,
143
- method: 'post',
144
- data: {
145
- name
146
- },
147
- });
148
- return rsp.data.data;
149
- }
150
- catch (e) {
151
- throw e;
152
- }
153
- });
154
- }
155
- /**
156
- * 查询登录用户常用表情
157
- */
158
- emotions() {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- let rsp;
161
- try {
162
- rsp = yield (0, utils_1.request)({
163
- url: `users/emotions?apiKey=${this.apiKey}`,
164
- });
165
- if (rsp.status === 401) {
166
- return { code: -1, msg: '登录已失效,请重新登录!' };
167
- }
168
- rsp.data.data = Object.keys(rsp.data.data);
169
- return rsp.data;
170
- }
171
- catch (e) {
172
- throw e;
173
- }
174
- });
175
- }
176
- /**
177
- * 查询登录用户当前活跃度,请求频率请控制在 30 ~ 60 秒一次
178
- */
179
- liveness() {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- if (!this.apiKey) {
182
- return 0;
183
- }
184
- try {
185
- let rsp = yield (0, utils_1.request)({
186
- url: `user/liveness?apiKey=${this.apiKey}`
187
- });
188
- if (rsp.status === 401) {
189
- return -1;
190
- }
191
- return rsp.data.liveness || 0;
192
- }
193
- catch (e) {
194
- throw e;
195
- }
196
- });
197
- }
198
- /**
199
- * 检查登录用户是否已经签到
200
- */
201
- isCheckIn() {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- if (!this.apiKey) {
204
- return false;
205
- }
206
- try {
207
- let rsp = yield (0, utils_1.request)({
208
- url: `user/checkedIn?apiKey=${this.apiKey}`
209
- });
210
- if (rsp.status === 401) {
211
- return false;
212
- }
213
- return rsp.data.checkedIn || false;
214
- }
215
- catch (e) {
216
- throw e;
217
- }
218
- });
219
- }
220
- /**
221
- * 检查登录用户是否已经领取昨日活跃奖励
222
- */
223
- isCollectedLiveness() {
224
- return __awaiter(this, void 0, void 0, function* () {
225
- if (!this.apiKey) {
226
- return false;
227
- }
228
- try {
229
- let rsp = yield (0, utils_1.request)({
230
- url: `api/activity/is-collected-liveness?apiKey=${this.apiKey}`
231
- });
232
- if (rsp.status === 401) {
233
- return false;
234
- }
235
- return rsp.data.isCollectedYesterdayLivenessReward || false;
236
- }
237
- catch (e) {
238
- throw e;
239
- }
240
- });
241
- }
242
- /**
243
- * 领取昨日活跃度奖励
244
- */
245
- rewardLiveness() {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- if (!this.apiKey) {
248
- return 0;
249
- }
250
- try {
251
- let rsp = yield (0, utils_1.request)({
252
- url: `api/activity/yesterday-liveness-reward-api?apiKey=${this.apiKey}`
253
- });
254
- if (rsp.status === 401) {
255
- return 0;
256
- }
257
- return rsp.data.sum || 0;
258
- }
259
- catch (e) {
260
- throw e;
261
- }
262
- });
263
- }
264
- /**
265
- * 上传文件
266
- * @param files 要上传的文件,如果是在 Node 使用,则传入文件路径数组,若是在浏览器使用,则传入文件对象数组。
267
- */
268
- upload(files) {
269
- return __awaiter(this, void 0, void 0, function* () {
270
- let data;
271
- if (utils_1.isBrowse) {
272
- data = new FormData();
273
- files.forEach(f => data.append('file[]', f));
274
- }
275
- else {
276
- let FormData = (yield Promise.resolve().then(() => __importStar(require('form-data')))).default;
277
- data = new FormData();
278
- files.forEach(f => data.append('file[]', fs.readFileSync(f.toString()), path.basename(f.toString())));
279
- }
280
- let rsp;
281
- try {
282
- rsp = yield (0, utils_1.request)({
283
- url: `upload`,
284
- method: 'post',
285
- data,
286
- headers: utils_1.isBrowse ? undefined : data.getHeaders()
287
- });
288
- return rsp.data;
289
- }
290
- catch (e) {
291
- throw e;
292
- }
293
- });
294
- }
295
- }
296
- exports.default = FishPi;
@@ -1,33 +0,0 @@
1
- import { ApiResponse, NoticeCount, NoticeList } from './typing';
2
- declare class Notice {
3
- private _apiKey;
4
- constructor(token?: string);
5
- /**
6
- * 重新设置请求 Token
7
- * @param apiKey 接口 API Key
8
- */
9
- setToken(token: string): void;
10
- /**
11
- * 获取未读消息数
12
- */
13
- count(): Promise<NoticeCount>;
14
- /**
15
- * 获取消息列表
16
- * @param type 消息类型
17
- */
18
- list(type: string): Promise<ApiResponse<NoticeList>>;
19
- /**
20
- * 已读指定类型消息
21
- * @param type 消息类型
22
- */
23
- makeRead(type: string): Promise<{
24
- code: number;
25
- }>;
26
- /**
27
- * 已读所有消息
28
- */
29
- readAll(): Promise<{
30
- code: number;
31
- }>;
32
- }
33
- export default Notice;
package/lib/src/notice.js DELETED
@@ -1,100 +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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const utils_1 = require("./utils");
13
- class Notice {
14
- constructor(token = '') {
15
- this._apiKey = '';
16
- if (!token) {
17
- return;
18
- }
19
- this._apiKey = token;
20
- }
21
- /**
22
- * 重新设置请求 Token
23
- * @param apiKey 接口 API Key
24
- */
25
- setToken(token) {
26
- this._apiKey = token;
27
- }
28
- /**
29
- * 获取未读消息数
30
- */
31
- count() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- let rsp;
34
- try {
35
- rsp = yield (0, utils_1.request)({
36
- url: `notifications/unread/count?apiKey=${this._apiKey}`,
37
- });
38
- rsp.data.userNotifyStatus = rsp.data.userNotifyStatus != 0;
39
- return rsp.data;
40
- }
41
- catch (e) {
42
- throw e;
43
- }
44
- });
45
- }
46
- /**
47
- * 获取消息列表
48
- * @param type 消息类型
49
- */
50
- list(type) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- let rsp;
53
- try {
54
- rsp = yield (0, utils_1.request)({
55
- url: `api/getNotifications?apiKey=${this._apiKey}&type=${type}`,
56
- });
57
- return rsp.data;
58
- }
59
- catch (e) {
60
- throw e;
61
- }
62
- });
63
- }
64
- /**
65
- * 已读指定类型消息
66
- * @param type 消息类型
67
- */
68
- makeRead(type) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- let rsp;
71
- try {
72
- rsp = yield (0, utils_1.request)({
73
- url: `notifications/make-read/${type}?apiKey=${this._apiKey}`,
74
- });
75
- return rsp.data;
76
- }
77
- catch (e) {
78
- throw e;
79
- }
80
- });
81
- }
82
- /**
83
- * 已读所有消息
84
- */
85
- readAll() {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- let rsp;
88
- try {
89
- rsp = yield (0, utils_1.request)({
90
- url: `notifications/all-read?apiKey=${this._apiKey}`,
91
- });
92
- return rsp.data;
93
- }
94
- catch (e) {
95
- throw e;
96
- }
97
- });
98
- }
99
- }
100
- exports.default = Notice;
@@ -1,6 +0,0 @@
1
- import { Metal } from './typing';
2
- declare const domain = "fishpi.cn/";
3
- declare function request(opt: any): Promise<any>;
4
- declare function toMetal(sysMetal: string): Metal;
5
- declare const isBrowse: boolean;
6
- export { request, domain, toMetal, isBrowse };
package/lib/src/utils.js DELETED
@@ -1,87 +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
- exports.isBrowse = exports.toMetal = exports.domain = exports.request = void 0;
35
- const axios_1 = __importDefault(require("axios"));
36
- const https = __importStar(require("https"));
37
- const domain = 'fishpi.cn/';
38
- exports.domain = domain;
39
- function request(opt) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- let { url, method = 'get', headers = {}, data } = opt;
42
- if (!isBrowse) {
43
- headers['User-Agent'] = `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36`;
44
- headers['Referer'] = `https://${domain}`;
45
- }
46
- let options = {
47
- method, headers,
48
- httpsAgent: new https.Agent({
49
- keepAlive: true,
50
- rejectUnauthorized: false,
51
- }),
52
- data
53
- };
54
- let rsp;
55
- try {
56
- rsp = yield (0, axios_1.default)(`https://${domain}${url}`, options);
57
- return rsp;
58
- }
59
- catch (err) {
60
- if (err.response.status === 401) {
61
- return err.response;
62
- }
63
- throw (err);
64
- }
65
- });
66
- }
67
- exports.request = request;
68
- function toMetal(sysMetal) {
69
- try {
70
- let metal = JSON.parse(sysMetal);
71
- metal.list.forEach((m, i, list) => {
72
- let attr = m.attr.split('&');
73
- m.attr = {};
74
- attr.forEach((a) => m.attr[a.split('=')[0]] = a.split('=')[1]);
75
- list[i] = m;
76
- });
77
- return metal;
78
- }
79
- catch (error) {
80
- return {
81
- list: []
82
- };
83
- }
84
- }
85
- exports.toMetal = toMetal;
86
- const isBrowse = typeof window !== 'undefined';
87
- exports.isBrowse = isBrowse;
@@ -1 +0,0 @@
1
- export {};
package/lib/test/index.js DELETED
@@ -1,27 +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 src_1 = __importDefault(require("../src"));
16
- function test(account) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- let fish = new src_1.default();
19
- console.dir(yield fish.login(account));
20
- console.dir(yield fish.info());
21
- fish.chatroom.addListener((ev) => console.dir(ev));
22
- });
23
- }
24
- test({
25
- username: '',
26
- passwd: ''
27
- });