fishpi 0.0.41 → 0.0.43

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/lib/article.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ApiResponse, ArticlePost, ArticleListType, ArticleDetail, VoteStatus, ArticleList } from './typing';
1
+ import { ApiResponse, ArticlePost, ArticleListType, ArticleDetail, VoteStatus, ArticleList, ArticleType } from './typing';
2
+ import ReconnectingWebSocket from 'reconnecting-websocket';
2
3
  declare class Article {
3
4
  private _apiKey;
4
5
  constructor(token?: string);
@@ -68,5 +69,16 @@ declare class Article {
68
69
  type?: VoteStatus;
69
70
  }>;
70
71
  thank(id: string): Promise<ApiResponse<undefined>>;
72
+ heat(id: string): Promise<number>;
73
+ /**
74
+ * 添加文章监听器
75
+ * @param id 文章id
76
+ * @param type 文章类型
77
+ * @param callback 监听回调
78
+ */
79
+ addListener({ id, type }: {
80
+ id: string;
81
+ type: ArticleType;
82
+ }, callback: (ev: any) => void): Promise<ReconnectingWebSocket>;
71
83
  }
72
84
  export default Article;
package/lib/article.js CHANGED
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,8 +69,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
69
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
70
  }
48
71
  };
72
+ var __importDefault = (this && this.__importDefault) || function (mod) {
73
+ return (mod && mod.__esModule) ? mod : { "default": mod };
74
+ };
49
75
  Object.defineProperty(exports, "__esModule", { value: true });
50
76
  var utils_1 = require("./utils");
77
+ var reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
51
78
  var Article = /** @class */ (function () {
52
79
  function Article(token) {
53
80
  if (token === void 0) { token = ''; }
@@ -267,6 +294,77 @@ var Article = /** @class */ (function () {
267
294
  });
268
295
  });
269
296
  };
297
+ Article.prototype.heat = function (id) {
298
+ return __awaiter(this, void 0, void 0, function () {
299
+ var rsp, e_8;
300
+ return __generator(this, function (_a) {
301
+ switch (_a.label) {
302
+ case 0:
303
+ _a.trys.push([0, 2, , 3]);
304
+ return [4 /*yield*/, (0, utils_1.request)({
305
+ url: "api/article/heat/".concat(id),
306
+ method: 'post',
307
+ data: {
308
+ apiKey: this._apiKey
309
+ },
310
+ })];
311
+ case 1:
312
+ rsp = _a.sent();
313
+ if (rsp.code !== 0)
314
+ throw new Error(rsp.msg);
315
+ return [2 /*return*/, rsp.articleHeat];
316
+ case 2:
317
+ e_8 = _a.sent();
318
+ throw e_8;
319
+ case 3: return [2 /*return*/];
320
+ }
321
+ });
322
+ });
323
+ };
324
+ /**
325
+ * 添加文章监听器
326
+ * @param id 文章id
327
+ * @param type 文章类型
328
+ * @param callback 监听回调
329
+ */
330
+ Article.prototype.addListener = function (_a, callback) {
331
+ var id = _a.id, _b = _a.type, type = _b === void 0 ? 0 : _b;
332
+ return __awaiter(this, void 0, void 0, function () {
333
+ var rws, _c, _d, _e;
334
+ var _f;
335
+ return __generator(this, function (_g) {
336
+ switch (_g.label) {
337
+ case 0:
338
+ _c = reconnecting_websocket_1.default.bind;
339
+ _d = [void 0, "wss://".concat(utils_1.domain, "//article-channel?articleId=").concat(id, "&articleType=").concat(type), []];
340
+ _f = {};
341
+ if (!utils_1.isBrowse) return [3 /*break*/, 1];
342
+ _e = window.WebSocket;
343
+ return [3 /*break*/, 3];
344
+ case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('ws')); })];
345
+ case 2:
346
+ _e = (_g.sent()).WebSocket;
347
+ _g.label = 3;
348
+ case 3:
349
+ rws = new (_c.apply(reconnecting_websocket_1.default, _d.concat([(
350
+ // eslint-disable-next-line @typescript-eslint/naming-convention
351
+ _f.WebSocket = _e,
352
+ _f.connectionTimeout = 10000,
353
+ _f)])))();
354
+ rws.onopen = function (e) {
355
+ };
356
+ rws.onmessage = callback;
357
+ rws.onerror = (function (e) {
358
+ console.error(e);
359
+ });
360
+ rws.onclose = (function (e) {
361
+ console.log(e);
362
+ });
363
+ return [2 /*return*/, rws];
364
+ }
365
+ });
366
+ });
367
+ };
270
368
  return Article;
271
369
  }());
272
370
  exports.default = Article;
package/lib/chatroom.d.ts CHANGED
@@ -99,10 +99,10 @@ declare class ChatRoom {
99
99
  * @param close 关闭回调
100
100
  * @returns 返回 Open Event
101
101
  */
102
- reconnect({ timeout, error, close }: {
103
- timeout?: number | undefined;
104
- error?: ((ev: any) => void) | undefined;
105
- close?: ((ev: any) => void) | undefined;
102
+ reconnect({ timeout, error, close }?: {
103
+ timeout?: number;
104
+ error?: (ev: any) => void;
105
+ close?: (ev: any) => void;
106
106
  }): Promise<unknown>;
107
107
  /**
108
108
  * 移除聊天室消息监听函数
@@ -118,10 +118,10 @@ declare class ChatRoom {
118
118
  */
119
119
  addListener(wsCallback: (event: {
120
120
  msg: Message;
121
- }) => void, { timeout, error, close }: {
122
- timeout?: number | undefined;
123
- error?: ((ev: any) => void) | undefined;
124
- close?: ((ev: any) => void) | undefined;
121
+ }) => void, { timeout, error, close }?: {
122
+ timeout?: number;
123
+ error?: (ev: any) => void;
124
+ close?: (ev: any) => void;
125
125
  }): Promise<void>;
126
126
  }
127
127
  export default ChatRoom;
package/lib/chatroom.js CHANGED
@@ -463,10 +463,10 @@ var ChatRoom = /** @class */ (function () {
463
463
  * @returns 返回 Open Event
464
464
  */
465
465
  ChatRoom.prototype.reconnect = function (_a) {
466
- var _b = _a.timeout, timeout = _b === void 0 ? 10 : _b, _c = _a.error, error = _c === void 0 ? function (ev) { } : _c, _d = _a.close, close = _d === void 0 ? function (ev) { } : _d;
466
+ var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 10 : _c, _d = _b.error, error = _d === void 0 ? function (ev) { } : _d, _e = _b.close, close = _e === void 0 ? function (ev) { } : _e;
467
467
  return __awaiter(this, void 0, void 0, function () {
468
468
  var _this = this;
469
- return __generator(this, function (_e) {
469
+ return __generator(this, function (_f) {
470
470
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
471
471
  var _a, _b, _c, _d;
472
472
  var _e;
@@ -581,10 +581,10 @@ var ChatRoom = /** @class */ (function () {
581
581
  * @param close 关闭回调
582
582
  */
583
583
  ChatRoom.prototype.addListener = function (wsCallback, _a) {
584
- var _b = _a.timeout, timeout = _b === void 0 ? 10 : _b, _c = _a.error, error = _c === void 0 ? function (ev) { } : _c, _d = _a.close, close = _d === void 0 ? function (ev) { } : _d;
584
+ var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 10 : _c, _d = _b.error, error = _d === void 0 ? function (ev) { } : _d, _e = _b.close, close = _e === void 0 ? function (ev) { } : _e;
585
585
  return __awaiter(this, void 0, void 0, function () {
586
- return __generator(this, function (_e) {
587
- switch (_e.label) {
586
+ return __generator(this, function (_f) {
587
+ switch (_f.label) {
588
588
  case 0:
589
589
  if (this._rws !== null) {
590
590
  if (this._wsCallbacks.indexOf(wsCallback) < 0)
@@ -594,7 +594,7 @@ var ChatRoom = /** @class */ (function () {
594
594
  this._wsCallbacks.push(wsCallback);
595
595
  return [4 /*yield*/, this.reconnect({ timeout: timeout, error: error, close: close })];
596
596
  case 1:
597
- _e.sent();
597
+ _f.sent();
598
598
  return [2 /*return*/];
599
599
  }
600
600
  });
package/lib/finger.d.ts CHANGED
@@ -60,4 +60,13 @@ export declare class Finger {
60
60
  * @param memo: 备注
61
61
  */
62
62
  editUserPoints(userName: string, point: number, memo: string): Promise<any>;
63
+ /**
64
+ * 查询用户积分
65
+ * @param userName: 用户在摸鱼派的用户名
66
+ */
67
+ getLiveness(userName: string): Promise<number>;
68
+ /**
69
+ * 查询用户昨日活跃度
70
+ */
71
+ getYesterDayLivenessReward(userName: string): Promise<number>;
63
72
  }
package/lib/finger.js CHANGED
@@ -319,6 +319,65 @@ var Finger = /** @class */ (function () {
319
319
  });
320
320
  });
321
321
  };
322
+ /**
323
+ * 查询用户积分
324
+ * @param userName: 用户在摸鱼派的用户名
325
+ */
326
+ Finger.prototype.getLiveness = function (userName) {
327
+ return __awaiter(this, void 0, void 0, function () {
328
+ var rsp, e_9;
329
+ return __generator(this, function (_a) {
330
+ switch (_a.label) {
331
+ case 0:
332
+ _a.trys.push([0, 2, , 3]);
333
+ return [4 /*yield*/, (0, utils_1.request)({
334
+ url: "user/liveness",
335
+ method: 'post',
336
+ data: {
337
+ goldFingerKey: this.goldFingerKey,
338
+ userName: userName,
339
+ },
340
+ })];
341
+ case 1:
342
+ rsp = _a.sent();
343
+ return [2 /*return*/, rsp.liveness];
344
+ case 2:
345
+ e_9 = _a.sent();
346
+ throw e_9;
347
+ case 3: return [2 /*return*/];
348
+ }
349
+ });
350
+ });
351
+ };
352
+ /**
353
+ * 查询用户昨日活跃度
354
+ */
355
+ Finger.prototype.getYesterDayLivenessReward = function (userName) {
356
+ return __awaiter(this, void 0, void 0, function () {
357
+ var rsp, e_10;
358
+ return __generator(this, function (_a) {
359
+ switch (_a.label) {
360
+ case 0:
361
+ _a.trys.push([0, 2, , 3]);
362
+ return [4 /*yield*/, (0, utils_1.request)({
363
+ url: "activity/yesterday-liveness-reward-api",
364
+ method: 'post',
365
+ data: {
366
+ goldFingerKey: this.goldFingerKey,
367
+ userName: userName,
368
+ },
369
+ })];
370
+ case 1:
371
+ rsp = _a.sent();
372
+ return [2 /*return*/, rsp.sum];
373
+ case 2:
374
+ e_10 = _a.sent();
375
+ throw e_10;
376
+ case 3: return [2 /*return*/];
377
+ }
378
+ });
379
+ });
380
+ };
322
381
  return Finger;
323
382
  }());
324
383
  exports.Finger = Finger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fishpi",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "A Package to use API of fishpi.",
5
5
  "main": "./lib/index.js",
6
6
  "files": [