fishpi 0.0.1 → 0.0.2
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/README.md +37 -3
- package/lib/src/chatroom.d.ts +2 -2
- package/lib/src/chatroom.js +58 -56
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +5 -4
- package/lib/src/notice.d.ts +1 -1
- package/lib/src/utils.d.ts +3 -2
- package/lib/src/utils.js +7 -3
- package/package.json +2 -1
- 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/utils.d.ts +0 -3
- package/lib/utils.js +0 -65
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# 摸鱼派 API Package
|
|
2
|
+
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
## 支援
|
|
5
|
+
- 用户信息;
|
|
6
|
+
- 聊天室;
|
|
7
|
+
- 文件上传;
|
|
8
|
+
- 通知信息;
|
|
6
9
|
|
|
7
10
|
## 安装
|
|
8
11
|
|
|
@@ -15,4 +18,35 @@ npm install fishpi
|
|
|
15
18
|
```ts
|
|
16
19
|
import FishPi from 'fishpi';
|
|
17
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
|
+
|
|
18
52
|
```
|
package/lib/src/chatroom.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResponse, ChatRoomMessage, RedPacket } from '
|
|
1
|
+
import { ApiResponse, ChatRoomMessage, RedPacket } from './typing';
|
|
2
2
|
declare class ChatRoom {
|
|
3
3
|
private _apiKey;
|
|
4
4
|
private _onlines;
|
|
@@ -77,6 +77,6 @@ declare class ChatRoom {
|
|
|
77
77
|
* 添加聊天室消息监听函数
|
|
78
78
|
* @param wsCallback 消息监听函数
|
|
79
79
|
*/
|
|
80
|
-
addListener(wsCallback: Function): void
|
|
80
|
+
addListener(wsCallback: Function): Promise<void>;
|
|
81
81
|
}
|
|
82
82
|
export default ChatRoom;
|
package/lib/src/chatroom.js
CHANGED
|
@@ -283,68 +283,70 @@ class ChatRoom {
|
|
|
283
283
|
* @param wsCallback 消息监听函数
|
|
284
284
|
*/
|
|
285
285
|
addListener(wsCallback) {
|
|
286
|
-
|
|
287
|
-
if (this.
|
|
288
|
-
this._wsCallbacks.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
this._wsCallbacks.push(wsCallback);
|
|
292
|
-
this._rws = new reconnecting_websocket_1.default(`wss://${utils_1.domain}chat-room-channel?apiKey=${this._apiKey}`, [], {
|
|
293
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
294
|
-
WebSocket: window ? window.WebSocket : Promise.resolve().then(() => __importStar(require('ws'))),
|
|
295
|
-
connectionTimeout: 10000
|
|
296
|
-
});
|
|
297
|
-
this._rws.onopen = (e) => {
|
|
298
|
-
if (this._wsTimer) {
|
|
299
|
-
clearInterval(this._wsTimer);
|
|
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;
|
|
300
291
|
}
|
|
301
|
-
this.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
case 'online': {
|
|
311
|
-
data = this._onlines = msg.users;
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
case 'revoke': {
|
|
315
|
-
data = msg.oId;
|
|
316
|
-
break;
|
|
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);
|
|
317
301
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
+
}
|
|
329
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;
|
|
330
340
|
}
|
|
331
|
-
catch (e) { }
|
|
332
|
-
data = { oId, time, userName, userNickname, userAvatarURL, content, md };
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
case 'redPacketStatus': {
|
|
336
|
-
let { oId, count, got, whoGive, whoGot } = msg;
|
|
337
|
-
data = { oId, count, got, whoGive, whoGot };
|
|
338
|
-
break;
|
|
339
341
|
}
|
|
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
|
+
};
|
|
342
349
|
});
|
|
343
|
-
this._rws.onerror = (e) => {
|
|
344
|
-
console.error(e);
|
|
345
|
-
};
|
|
346
|
-
this._rws.onclose = (e) => {
|
|
347
|
-
};
|
|
348
350
|
}
|
|
349
351
|
}
|
|
350
352
|
exports.default = ChatRoom;
|
package/lib/src/index.d.ts
CHANGED
package/lib/src/index.js
CHANGED
|
@@ -100,7 +100,8 @@ class FishPi {
|
|
|
100
100
|
if (rsp.status === 401) {
|
|
101
101
|
return { code: -1, msg: '登录已失效,请重新登录!' };
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
if (rsp.data.data)
|
|
104
|
+
rsp.data.data.sysMetal = (0, utils_1.toMetal)(rsp.data.data.sysMetal);
|
|
104
105
|
return rsp.data;
|
|
105
106
|
}
|
|
106
107
|
catch (e) {
|
|
@@ -267,7 +268,7 @@ class FishPi {
|
|
|
267
268
|
upload(files) {
|
|
268
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
269
270
|
let data;
|
|
270
|
-
if (
|
|
271
|
+
if (utils_1.isBrowse) {
|
|
271
272
|
data = new FormData();
|
|
272
273
|
files.forEach(f => data.append('file[]', f));
|
|
273
274
|
}
|
|
@@ -282,9 +283,9 @@ class FishPi {
|
|
|
282
283
|
url: `upload`,
|
|
283
284
|
method: 'post',
|
|
284
285
|
data,
|
|
285
|
-
headers: data.getHeaders()
|
|
286
|
+
headers: utils_1.isBrowse ? undefined : data.getHeaders()
|
|
286
287
|
});
|
|
287
|
-
return rsp.data
|
|
288
|
+
return rsp.data;
|
|
288
289
|
}
|
|
289
290
|
catch (e) {
|
|
290
291
|
throw e;
|
package/lib/src/notice.d.ts
CHANGED
package/lib/src/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Metal } from '
|
|
1
|
+
import { Metal } from './typing';
|
|
2
2
|
declare const domain = "fishpi.cn/";
|
|
3
3
|
declare function request(opt: any): Promise<any>;
|
|
4
4
|
declare function toMetal(sysMetal: string): Metal;
|
|
5
|
-
|
|
5
|
+
declare const isBrowse: boolean;
|
|
6
|
+
export { request, domain, toMetal, isBrowse };
|
package/lib/src/utils.js
CHANGED
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.toMetal = exports.domain = exports.request = void 0;
|
|
34
|
+
exports.isBrowse = exports.toMetal = exports.domain = exports.request = void 0;
|
|
35
35
|
const axios_1 = __importDefault(require("axios"));
|
|
36
36
|
const https = __importStar(require("https"));
|
|
37
37
|
const domain = 'fishpi.cn/';
|
|
@@ -39,8 +39,10 @@ exports.domain = domain;
|
|
|
39
39
|
function request(opt) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
let { url, method = 'get', headers = {}, data } = opt;
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|
|
44
46
|
let options = {
|
|
45
47
|
method, headers,
|
|
46
48
|
httpsAgent: new https.Agent({
|
|
@@ -81,3 +83,5 @@ function toMetal(sysMetal) {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
exports.toMetal = toMetal;
|
|
86
|
+
const isBrowse = typeof window !== 'undefined';
|
|
87
|
+
exports.isBrowse = isBrowse;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fishpi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A Package to use API of fishpi.",
|
|
5
5
|
"main": "./lib/src/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/**/*"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
+
"prebuild": "rm -rf lib",
|
|
10
11
|
"build": "tsc"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
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;
|
package/lib/utils.d.ts
DELETED
package/lib/utils.js
DELETED
|
@@ -1,65 +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.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
|
-
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`;
|
|
43
|
-
headers['Referer'] = `https://${domain}`;
|
|
44
|
-
let options = {
|
|
45
|
-
method, headers,
|
|
46
|
-
httpsAgent: new https.Agent({
|
|
47
|
-
keepAlive: true,
|
|
48
|
-
rejectUnauthorized: false,
|
|
49
|
-
}),
|
|
50
|
-
data
|
|
51
|
-
};
|
|
52
|
-
let rsp;
|
|
53
|
-
try {
|
|
54
|
-
rsp = yield (0, axios_1.default)(`https://${domain}${url}`, options);
|
|
55
|
-
return rsp;
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
if (err.response.status === 401) {
|
|
59
|
-
return err.response;
|
|
60
|
-
}
|
|
61
|
-
throw (err);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
exports.request = request;
|