fishpi 0.0.23 → 0.0.25

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 CHANGED
@@ -10,6 +10,9 @@
10
10
  - 文件上传;
11
11
  - 通知信息;
12
12
  - 清风明月;
13
+ - 文章读写;
14
+ - 评论点赞;
15
+ - 私聊功能;
13
16
 
14
17
  ## 安装
15
18
 
@@ -53,4 +56,43 @@ await fish.chatroom.redpacket.send({
53
56
  recivers: [];
54
57
  })
55
58
 
59
+ // 私聊历史获取
60
+ let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
61
+ // 监听私聊新消息
62
+ fishpi.chat.addListener(({ msg: any }) => {
63
+ switch (msg.command) {
64
+ // 私聊未读数更新
65
+ case 'chatUnreadCountRefresh':
66
+ if(msg.count > 0) {
67
+ let unreadMsgs = await fishpi.chat.unread();
68
+ }
69
+ else this.users.forEach((u, i) => {
70
+ this.users[i].unread = 0;
71
+ });
72
+ break;
73
+ // 新私聊消息
74
+ case 'newIdleChatMessage':
75
+ // msg 就是新的私聊消息
76
+ console.log(msg.senderUserName, '说:', notice.preview);
77
+ break;
78
+ // 有新的消息通知
79
+ case 'refreshNotification':
80
+ console.log('你有新消息【', await fishpi.notice.count(), '】')
81
+ break;
82
+ }
83
+ });
84
+ // 监听指定用户的私聊消息
85
+ fishpi.chat.addListener(({ msg: ChatData }) => {
86
+ console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
87
+ }, 'username');
88
+ // 给指定用户发私聊消息
89
+ fishpi.chat.send('username', 'Hi~');
56
90
  ```
91
+
92
+ ## 注意事项
93
+
94
+ API 库使用 `fetch` 做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 `node-fetch` 2.x 版本的库。执行如下代码设置 `fetch` 函数:
95
+ ```typescript
96
+ import fetch from 'node-fetch'
97
+ globalThis.fetch = fetch as any;
98
+ ```
package/lib/article.js CHANGED
@@ -194,12 +194,12 @@ var Article = /** @class */ (function () {
194
194
  })];
195
195
  case 1:
196
196
  rsp = _a.sent();
197
- rsp.articleAuthor.sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.data.articleAuthor.sysMetal);
198
- for (i = 0; i < rsp.data.articleComments.length; i++) {
199
- rsp.articleComments[i].sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.data.articleComments[i].sysMetal);
197
+ rsp.article.articleAuthor.sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.article.articleAuthor.sysMetal);
198
+ for (i = 0; i < rsp.article.articleComments.length; i++) {
199
+ rsp.article.articleComments[i].sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.article.articleComments[i].sysMetal);
200
200
  }
201
- for (i = 0; i < rsp.data.articleNiceComments.length; i++) {
202
- rsp.articleNiceComments[i].sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.data.articleNiceComments[i].sysMetal);
201
+ for (i = 0; i < rsp.article.articleNiceComments.length; i++) {
202
+ rsp.article.articleNiceComments[i].sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.article.articleNiceComments[i].sysMetal);
203
203
  }
204
204
  return [2 /*return*/, rsp];
205
205
  case 2:
package/lib/chat.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import ReconnectingWebSocket from 'reconnecting-websocket';
2
- import { ApiResponse, ChatData } from './typing';
2
+ import { ApiResponse, ChatData, NoticeMsg } from './typing';
3
3
  declare class Chat {
4
4
  private _apiKey;
5
5
  private _rwss;
@@ -42,7 +42,9 @@ declare class Chat {
42
42
  * @param user 指定用户消息监听函数,空为新信息监听
43
43
  * @param wsCallback 要移除的函数,若为空,则清空消息监听
44
44
  */
45
- removeListener(user: string | undefined, wsCallback: Function): void;
45
+ removeListener(user: string | undefined, wsCallback: ({ msg }: {
46
+ msg: NoticeMsg;
47
+ }) => void): void;
46
48
  /**
47
49
  * 添加聊天室消息监听函数
48
50
  * @param wsCallback 消息监听函数
package/lib/chatroom.js CHANGED
@@ -130,9 +130,6 @@ var ChatRoom = /** @class */ (function () {
130
130
  })];
131
131
  case 1:
132
132
  rsp_1 = _a.sent();
133
- if (rsp_1.status === 401) {
134
- return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
135
- }
136
133
  if (rsp_1.code != 0) {
137
134
  throw new Error(rsp_1.msg);
138
135
  }
package/lib/index.d.ts CHANGED
@@ -55,7 +55,7 @@ declare class FishPi {
55
55
  * 查询指定用户信息
56
56
  * @param username 用户名
57
57
  */
58
- user(username: string): Promise<ApiResponse<UserInfo>>;
58
+ user(username: string): Promise<UserInfo>;
59
59
  /**
60
60
  * 用户名联想,通常用于 @ 列表
61
61
  * @param username 用户名
package/lib/index.js CHANGED
@@ -164,7 +164,7 @@ var FishPi = /** @class */ (function () {
164
164
  })];
165
165
  case 1:
166
166
  rsp = _a.sent();
167
- this.setToken(rsp.data.Key);
167
+ this.setToken(rsp.Key);
168
168
  return [2 /*return*/, rsp];
169
169
  case 2:
170
170
  e_1 = _a.sent();
@@ -186,15 +186,12 @@ var FishPi = /** @class */ (function () {
186
186
  case 0:
187
187
  _a.trys.push([0, 2, , 3]);
188
188
  return [4 /*yield*/, (0, utils_1.request)({
189
- url: "user/".concat(username, "?apiKey=").concat(this.apiKey)
189
+ url: "user/".concat(username).concat(this.apiKey ? "?apiKey=".concat(this.apiKey) : '')
190
190
  })];
191
191
  case 1:
192
192
  rsp = _a.sent();
193
- if (rsp.status === 401) {
194
- return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
195
- }
196
- rsp.data.sysMetal = (0, utils_1.toMetal)(rsp.data.sysMetal);
197
- rsp.data.allMetalOwned = (0, utils_1.toMetal)(rsp.data.allMetalOwned);
193
+ rsp.sysMetal = (0, utils_1.toMetal)(rsp.sysMetal);
194
+ rsp.allMetalOwned = (0, utils_1.toMetal)(rsp.allMetalOwned);
198
195
  return [2 /*return*/, rsp];
199
196
  case 2:
200
197
  e_2 = _a.sent();
package/lib/typing.d.ts CHANGED
@@ -2071,3 +2071,13 @@ export interface MuteItem {
2071
2071
  */
2072
2072
  userNickname: string;
2073
2073
  }
2074
+ export interface NoticeMsg {
2075
+ command: 'refreshNotification' | 'chatUnreadCountRefresh' | 'newIdleChatMessage' | 'warnBroadcast';
2076
+ userId: string;
2077
+ preview?: string;
2078
+ senderAvatar?: string;
2079
+ senderUserName?: string;
2080
+ count?: number;
2081
+ warnBroadcastText?: string;
2082
+ who?: string;
2083
+ }
package/lib/user.js CHANGED
@@ -70,7 +70,7 @@ var User = /** @class */ (function () {
70
70
  rsp = _a.sent();
71
71
  if (rsp.data)
72
72
  rsp.data.sysMetal = (0, utils_1.toMetal)(rsp.data.sysMetal);
73
- return [2 /*return*/, rsp.data];
73
+ return [2 /*return*/, rsp];
74
74
  case 2:
75
75
  e_1 = _a.sent();
76
76
  throw e_1;
@@ -95,7 +95,7 @@ var User = /** @class */ (function () {
95
95
  case 1:
96
96
  rsp = _a.sent();
97
97
  rsp.data = Object.keys(rsp.data);
98
- return [2 /*return*/, rsp.data];
98
+ return [2 /*return*/, rsp];
99
99
  case 2:
100
100
  e_2 = _a.sent();
101
101
  throw e_2;
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
- {
2
- "name": "fishpi",
3
- "version": "0.0.23",
4
- "description": "A Package to use API of fishpi.",
5
- "main": "./lib/index.js",
6
- "files": [
7
- "lib"
8
- ],
9
- "scripts": {
10
- "prebuild": "rimraf lib",
11
- "build": "tsc",
12
- "prepublish": "npm run build",
13
- "test": "NODE_OPTIONS=\"-r ts-node/register --no-warnings\" node ./test/index.ts",
14
- "publish": "npm publish"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/imlinhanchao/fishpi-api-package.git"
19
- },
20
- "license": "MIT",
21
- "author": {
22
- "name": "Hancel.Lin",
23
- "email": "imlinhanchao@foxmail.com",
24
- "url": "https://github.com/imlinhanchao"
25
- },
26
- "engines": {
27
- "node": ">=12.0"
28
- },
29
- "keywords": [],
30
- "bugs": {
31
- "url": "https://github.com/imlinhanchao/fishpi-api-package/issues"
32
- },
33
- "homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
34
- "dependencies": {
35
- "form-data": "^4.0.0",
36
- "reconnecting-websocket": "^4.4.0",
37
- "ws": "^8.4.2"
38
- },
39
- "devDependencies": {
40
- "@types/node": "^12.20.11",
41
- "@types/node-fetch": "^2.6.3",
42
- "@types/ws": "^8.2.2",
43
- "node-fetch": "2",
44
- "rimraf": "^5.0.0",
45
- "ts-node": "^10.2.1",
46
- "typescript": "^4.2.4"
47
- },
48
- "release": {
49
- "branches": [
50
- "master"
51
- ]
52
- }
53
- }
1
+ {
2
+ "name": "fishpi",
3
+ "version": "0.0.25",
4
+ "description": "A Package to use API of fishpi.",
5
+ "main": "./lib/index.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "scripts": {
10
+ "prebuild": "rimraf lib",
11
+ "build": "tsc",
12
+ "prepublish": "npm run build",
13
+ "test": "NODE_OPTIONS=\"-r ts-node/register --no-warnings\" node ./test/index.ts",
14
+ "publish": "npm publish"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/imlinhanchao/fishpi-api-package.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": {
22
+ "name": "Hancel.Lin",
23
+ "email": "imlinhanchao@foxmail.com",
24
+ "url": "https://github.com/imlinhanchao"
25
+ },
26
+ "engines": {
27
+ "node": ">=12.0"
28
+ },
29
+ "keywords": [],
30
+ "bugs": {
31
+ "url": "https://github.com/imlinhanchao/fishpi-api-package/issues"
32
+ },
33
+ "homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
34
+ "dependencies": {
35
+ "form-data": "^4.0.0",
36
+ "reconnecting-websocket": "^4.4.0",
37
+ "ws": "^8.4.2"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^12.20.11",
41
+ "@types/node-fetch": "^2.6.3",
42
+ "@types/ws": "^8.2.2",
43
+ "node-fetch": "2",
44
+ "rimraf": "^5.0.0",
45
+ "ts-node": "^10.2.1",
46
+ "typescript": "^4.2.4"
47
+ },
48
+ "release": {
49
+ "branches": [
50
+ "master"
51
+ ]
52
+ }
53
+ }