fishpi 0.0.3 → 0.0.7
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 -52
- package/lib/src/article.d.ts +60 -0
- package/lib/src/article.js +254 -0
- package/lib/src/breezemoon.d.ts +20 -0
- package/lib/src/breezemoon.js +114 -0
- package/lib/src/chat.d.ts +66 -0
- package/lib/src/chat.js +315 -0
- package/lib/src/chatroom.d.ts +21 -23
- package/lib/src/chatroom.js +377 -262
- package/lib/src/comment.d.ts +31 -0
- package/lib/src/comment.js +207 -0
- package/lib/src/emoji.d.ts +197 -0
- package/lib/src/emoji.js +308 -0
- package/lib/src/index.d.ts +23 -26
- package/lib/src/index.js +179 -218
- package/lib/src/notice.d.ts +1 -3
- package/lib/src/notice.js +116 -59
- package/lib/src/typing.d.ts +1901 -0
- package/lib/src/typing.js +411 -0
- package/lib/src/user.d.ts +35 -0
- package/lib/src/user.js +243 -0
- package/lib/src/utils.d.ts +4 -3
- package/lib/src/utils.js +84 -39
- package/package.json +48 -48
- package/lib/test/index.d.ts +0 -1
- package/lib/test/index.js +0 -27
package/lib/src/index.js
CHANGED
|
@@ -27,22 +27,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
30
57
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
58
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
59
|
};
|
|
33
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
var crypto = __importStar(require("crypto"));
|
|
62
|
+
var fs = __importStar(require("fs"));
|
|
63
|
+
var path = __importStar(require("path"));
|
|
64
|
+
var utils_1 = require("./utils");
|
|
65
|
+
var chatroom_1 = __importDefault(require("./chatroom"));
|
|
66
|
+
var notice_1 = __importDefault(require("./notice"));
|
|
67
|
+
var emoji_1 = __importDefault(require("./emoji"));
|
|
68
|
+
var user_1 = __importDefault(require("./user"));
|
|
69
|
+
var article_1 = __importDefault(require("./article"));
|
|
70
|
+
var chat_1 = __importDefault(require("./chat"));
|
|
71
|
+
var FishPi = /** @class */ (function () {
|
|
41
72
|
/**
|
|
42
73
|
* 构造一个 API 请求对象
|
|
43
74
|
* @param token 接口 API Key,没有可以传空
|
|
44
75
|
*/
|
|
45
|
-
|
|
76
|
+
function FishPi(token) {
|
|
77
|
+
if (token === void 0) { token = ''; }
|
|
46
78
|
/**
|
|
47
79
|
* 请求 API 的 API Key
|
|
48
80
|
*/
|
|
@@ -55,242 +87,171 @@ class FishPi {
|
|
|
55
87
|
* 通知接口对象
|
|
56
88
|
*/
|
|
57
89
|
this.notice = new notice_1.default();
|
|
90
|
+
/**
|
|
91
|
+
* 表情包接口对象
|
|
92
|
+
*/
|
|
93
|
+
this.emoji = new emoji_1.default();
|
|
94
|
+
/**
|
|
95
|
+
* 用户接口对象
|
|
96
|
+
*/
|
|
97
|
+
this.account = new user_1.default();
|
|
98
|
+
/**
|
|
99
|
+
* 文章接口对象
|
|
100
|
+
*/
|
|
101
|
+
this.article = new article_1.default();
|
|
102
|
+
/**
|
|
103
|
+
* 私聊接口对象
|
|
104
|
+
*/
|
|
105
|
+
this.chat = new chat_1.default();
|
|
58
106
|
if (!token) {
|
|
59
107
|
return;
|
|
60
108
|
}
|
|
61
|
-
this.
|
|
62
|
-
this.chatroom.setToken(this.apiKey);
|
|
63
|
-
this.notice.setToken(this.apiKey);
|
|
109
|
+
this.setToken(token);
|
|
64
110
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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;
|
|
111
|
+
FishPi.prototype.setToken = function (apiKey) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
this.apiKey = apiKey;
|
|
82
115
|
this.chatroom.setToken(this.apiKey);
|
|
83
116
|
this.notice.setToken(this.apiKey);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
117
|
+
this.emoji.setToken(this.apiKey);
|
|
118
|
+
this.account.setToken(this.apiKey);
|
|
119
|
+
this.article.setToken(this.apiKey);
|
|
120
|
+
this.chat.setToken(this.apiKey);
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
});
|
|
89
123
|
});
|
|
90
|
-
}
|
|
124
|
+
};
|
|
91
125
|
/**
|
|
92
|
-
*
|
|
126
|
+
* 登录账号返回 API Key
|
|
127
|
+
* @param data 用户账密
|
|
93
128
|
*/
|
|
94
|
-
|
|
95
|
-
return __awaiter(this, void 0, void 0, function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
129
|
+
FishPi.prototype.login = function (data) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var md5, rsp, e_1;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
_a.trys.push([0, 2, , 3]);
|
|
136
|
+
md5 = crypto.createHash('md5');
|
|
137
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
138
|
+
url: 'api/getKey',
|
|
139
|
+
method: 'post',
|
|
140
|
+
data: {
|
|
141
|
+
nameOrEmail: data.username,
|
|
142
|
+
userPassword: md5.update(data.passwd).digest('hex'),
|
|
143
|
+
mfaCode: data.mfaCode
|
|
144
|
+
},
|
|
145
|
+
})];
|
|
146
|
+
case 1:
|
|
147
|
+
rsp = _a.sent();
|
|
148
|
+
this.setToken(rsp.data.Key);
|
|
149
|
+
return [2 /*return*/, rsp.data];
|
|
150
|
+
case 2:
|
|
151
|
+
e_1 = _a.sent();
|
|
152
|
+
throw e_1;
|
|
153
|
+
case 3: return [2 /*return*/];
|
|
102
154
|
}
|
|
103
|
-
|
|
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
|
-
}
|
|
155
|
+
});
|
|
110
156
|
});
|
|
111
|
-
}
|
|
157
|
+
};
|
|
112
158
|
/**
|
|
113
159
|
* 查询指定用户信息
|
|
114
160
|
* @param username 用户名
|
|
115
161
|
*/
|
|
116
|
-
user(username) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
162
|
+
FishPi.prototype.user = function (username) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var rsp, e_2;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
167
|
+
case 0:
|
|
168
|
+
_a.trys.push([0, 2, , 3]);
|
|
169
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
170
|
+
url: "user/".concat(username, "?apiKey=").concat(this.apiKey)
|
|
171
|
+
})];
|
|
172
|
+
case 1:
|
|
173
|
+
rsp = _a.sent();
|
|
174
|
+
if (rsp.status === 401) {
|
|
175
|
+
return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
|
|
176
|
+
}
|
|
177
|
+
rsp.data.data.sysMetal = (0, utils_1.toMetal)(rsp.data.data.sysMetal);
|
|
178
|
+
return [2 /*return*/, rsp.data];
|
|
179
|
+
case 2:
|
|
180
|
+
e_2 = _a.sent();
|
|
181
|
+
throw e_2;
|
|
182
|
+
case 3: return [2 /*return*/];
|
|
124
183
|
}
|
|
125
|
-
|
|
126
|
-
return rsp.data;
|
|
127
|
-
}
|
|
128
|
-
catch (e) {
|
|
129
|
-
throw e;
|
|
130
|
-
}
|
|
184
|
+
});
|
|
131
185
|
});
|
|
132
|
-
}
|
|
186
|
+
};
|
|
133
187
|
/**
|
|
134
188
|
* 用户名联想,通常用于 @ 列表
|
|
135
189
|
* @param username 用户名
|
|
136
190
|
*/
|
|
137
|
-
names(name) {
|
|
138
|
-
return __awaiter(this, void 0, void 0, function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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: '登录已失效,请重新登录!' };
|
|
191
|
+
FishPi.prototype.names = function (name) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var rsp, e_3;
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
_a.trys.push([0, 2, , 3]);
|
|
198
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
199
|
+
url: "users/names",
|
|
200
|
+
method: 'post',
|
|
201
|
+
data: {
|
|
202
|
+
name: name
|
|
203
|
+
},
|
|
204
|
+
})];
|
|
205
|
+
case 1:
|
|
206
|
+
rsp = _a.sent();
|
|
207
|
+
return [2 /*return*/, rsp.data.data];
|
|
208
|
+
case 2:
|
|
209
|
+
e_3 = _a.sent();
|
|
210
|
+
throw e_3;
|
|
211
|
+
case 3: return [2 /*return*/];
|
|
167
212
|
}
|
|
168
|
-
|
|
169
|
-
return rsp.data;
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
throw e;
|
|
173
|
-
}
|
|
213
|
+
});
|
|
174
214
|
});
|
|
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
|
-
}
|
|
215
|
+
};
|
|
264
216
|
/**
|
|
265
217
|
* 上传文件
|
|
266
218
|
* @param files 要上传的文件,如果是在 Node 使用,则传入文件路径数组,若是在浏览器使用,则传入文件对象数组。
|
|
267
219
|
*/
|
|
268
|
-
upload(files) {
|
|
269
|
-
return __awaiter(this, void 0, void 0, function
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
220
|
+
FishPi.prototype.upload = function (files) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
+
var data, FormData_1, rsp, e_4;
|
|
223
|
+
return __generator(this, function (_a) {
|
|
224
|
+
switch (_a.label) {
|
|
225
|
+
case 0:
|
|
226
|
+
if (!utils_1.isBrowse) return [3 /*break*/, 1];
|
|
227
|
+
data = new FormData();
|
|
228
|
+
files.forEach(function (f) { return data.append('file[]', f); });
|
|
229
|
+
return [3 /*break*/, 3];
|
|
230
|
+
case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('form-data')); })];
|
|
231
|
+
case 2:
|
|
232
|
+
FormData_1 = (_a.sent()).default;
|
|
233
|
+
data = new FormData_1();
|
|
234
|
+
files.forEach(function (f) { return data.append('file[]', fs.readFileSync(f.toString()), path.basename(f.toString())); });
|
|
235
|
+
_a.label = 3;
|
|
236
|
+
case 3:
|
|
237
|
+
_a.trys.push([3, 5, , 6]);
|
|
238
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
239
|
+
url: "upload",
|
|
240
|
+
method: 'post',
|
|
241
|
+
data: data,
|
|
242
|
+
headers: utils_1.isBrowse ? undefined : data.getHeaders()
|
|
243
|
+
})];
|
|
244
|
+
case 4:
|
|
245
|
+
rsp = _a.sent();
|
|
246
|
+
return [2 /*return*/, rsp.data];
|
|
247
|
+
case 5:
|
|
248
|
+
e_4 = _a.sent();
|
|
249
|
+
throw e_4;
|
|
250
|
+
case 6: return [2 /*return*/];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
293
253
|
});
|
|
294
|
-
}
|
|
295
|
-
|
|
254
|
+
};
|
|
255
|
+
return FishPi;
|
|
256
|
+
}());
|
|
296
257
|
exports.default = FishPi;
|
package/lib/src/notice.d.ts
CHANGED
package/lib/src/notice.js
CHANGED
|
@@ -8,10 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
11
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
39
|
+
var utils_1 = require("./utils");
|
|
40
|
+
var Notice = /** @class */ (function () {
|
|
41
|
+
function Notice(token) {
|
|
42
|
+
if (token === void 0) { token = ''; }
|
|
15
43
|
this._apiKey = '';
|
|
16
44
|
if (!token) {
|
|
17
45
|
return;
|
|
@@ -22,79 +50,108 @@ class Notice {
|
|
|
22
50
|
* 重新设置请求 Token
|
|
23
51
|
* @param apiKey 接口 API Key
|
|
24
52
|
*/
|
|
25
|
-
setToken(token) {
|
|
53
|
+
Notice.prototype.setToken = function (token) {
|
|
26
54
|
this._apiKey = token;
|
|
27
|
-
}
|
|
55
|
+
};
|
|
28
56
|
/**
|
|
29
57
|
* 获取未读消息数
|
|
30
58
|
*/
|
|
31
|
-
count() {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
Notice.prototype.count = function () {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var rsp, e_1;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
_a.trys.push([0, 2, , 3]);
|
|
66
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
67
|
+
url: "notifications/unread/count?apiKey=".concat(this._apiKey),
|
|
68
|
+
})];
|
|
69
|
+
case 1:
|
|
70
|
+
rsp = _a.sent();
|
|
71
|
+
rsp.data.userNotifyStatus = rsp.data.userNotifyStatus != 0;
|
|
72
|
+
return [2 /*return*/, rsp.data];
|
|
73
|
+
case 2:
|
|
74
|
+
e_1 = _a.sent();
|
|
75
|
+
throw e_1;
|
|
76
|
+
case 3: return [2 /*return*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
44
79
|
});
|
|
45
|
-
}
|
|
80
|
+
};
|
|
46
81
|
/**
|
|
47
82
|
* 获取消息列表
|
|
48
83
|
* @param type 消息类型
|
|
49
84
|
*/
|
|
50
|
-
list(type) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
Notice.prototype.list = function (type) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var rsp, e_2;
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
_a.trys.push([0, 2, , 3]);
|
|
92
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
93
|
+
url: "api/getNotifications?apiKey=".concat(this._apiKey, "&type=").concat(type),
|
|
94
|
+
})];
|
|
95
|
+
case 1:
|
|
96
|
+
rsp = _a.sent();
|
|
97
|
+
return [2 /*return*/, rsp.data];
|
|
98
|
+
case 2:
|
|
99
|
+
e_2 = _a.sent();
|
|
100
|
+
throw e_2;
|
|
101
|
+
case 3: return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
62
104
|
});
|
|
63
|
-
}
|
|
105
|
+
};
|
|
64
106
|
/**
|
|
65
107
|
* 已读指定类型消息
|
|
66
108
|
* @param type 消息类型
|
|
67
109
|
*/
|
|
68
|
-
makeRead(type) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
110
|
+
Notice.prototype.makeRead = function (type) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var rsp, e_3;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
switch (_a.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
_a.trys.push([0, 2, , 3]);
|
|
117
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
118
|
+
url: "notifications/make-read/".concat(type, "?apiKey=").concat(this._apiKey),
|
|
119
|
+
})];
|
|
120
|
+
case 1:
|
|
121
|
+
rsp = _a.sent();
|
|
122
|
+
return [2 /*return*/, rsp.data];
|
|
123
|
+
case 2:
|
|
124
|
+
e_3 = _a.sent();
|
|
125
|
+
throw e_3;
|
|
126
|
+
case 3: return [2 /*return*/];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
80
129
|
});
|
|
81
|
-
}
|
|
130
|
+
};
|
|
82
131
|
/**
|
|
83
132
|
* 已读所有消息
|
|
84
133
|
*/
|
|
85
|
-
readAll() {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
134
|
+
Notice.prototype.readAll = function () {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var rsp, e_4;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
switch (_a.label) {
|
|
139
|
+
case 0:
|
|
140
|
+
_a.trys.push([0, 2, , 3]);
|
|
141
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
142
|
+
url: "notifications/all-read?apiKey=".concat(this._apiKey),
|
|
143
|
+
})];
|
|
144
|
+
case 1:
|
|
145
|
+
rsp = _a.sent();
|
|
146
|
+
return [2 /*return*/, rsp.data];
|
|
147
|
+
case 2:
|
|
148
|
+
e_4 = _a.sent();
|
|
149
|
+
throw e_4;
|
|
150
|
+
case 3: return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
97
153
|
});
|
|
98
|
-
}
|
|
99
|
-
|
|
154
|
+
};
|
|
155
|
+
return Notice;
|
|
156
|
+
}());
|
|
100
157
|
exports.default = Notice;
|