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