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/article.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ApiResponse, ArticlePost, ArticleListType, ArticleDetail, VoteStatus, ArticleList } from './typing';
|
|
2
|
+
declare class Article {
|
|
3
|
+
private _apiKey;
|
|
4
|
+
constructor(token?: string);
|
|
5
|
+
/**
|
|
6
|
+
* 重新设置请求 Token
|
|
7
|
+
* @param apiKey 接口 API Key
|
|
8
|
+
*/
|
|
9
|
+
setToken(token: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* 发布文章
|
|
12
|
+
* @param data 文章信息
|
|
13
|
+
* @returns 发布成功返回文章Id (articleId)
|
|
14
|
+
*/
|
|
15
|
+
post(data: ArticlePost): Promise<{
|
|
16
|
+
code: number;
|
|
17
|
+
msg?: string;
|
|
18
|
+
articleId?: string;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* 更新文章
|
|
22
|
+
* @param id 文章 Id
|
|
23
|
+
* @param data 文章信息
|
|
24
|
+
* @returns 更新成功返回文章Id (articleId)
|
|
25
|
+
*/
|
|
26
|
+
update(id: string, data: ArticlePost): Promise<{
|
|
27
|
+
code: number;
|
|
28
|
+
msg?: string;
|
|
29
|
+
articleId?: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* 查询文章列表
|
|
33
|
+
* @param type 查询类型
|
|
34
|
+
* @param tag 指定查询标签,可选
|
|
35
|
+
* @returns 文章列表
|
|
36
|
+
*/
|
|
37
|
+
list({ type, page, tag }: {
|
|
38
|
+
type: ArticleListType;
|
|
39
|
+
page?: number;
|
|
40
|
+
tag?: string;
|
|
41
|
+
}): Promise<ApiResponse<ArticleList>>;
|
|
42
|
+
/**
|
|
43
|
+
* 查询用户文章列表
|
|
44
|
+
* @param userName 用户名
|
|
45
|
+
* @returns 文章列表
|
|
46
|
+
*/
|
|
47
|
+
userArticles({ userName, page }: {
|
|
48
|
+
userName: string;
|
|
49
|
+
page: number;
|
|
50
|
+
}): Promise<ApiResponse<ArticleList>>;
|
|
51
|
+
/**
|
|
52
|
+
* 获取文章详情
|
|
53
|
+
* @param id 文章id
|
|
54
|
+
* @returns 文章详情
|
|
55
|
+
*/
|
|
56
|
+
detail(id: string, p?: number): Promise<ApiResponse<{
|
|
57
|
+
article: ArticleDetail;
|
|
58
|
+
}>>;
|
|
59
|
+
/**
|
|
60
|
+
* 点赞/取消点赞文章
|
|
61
|
+
* @param id 文章id
|
|
62
|
+
* @returns 文章点赞状态
|
|
63
|
+
*/
|
|
64
|
+
vote(id: string): Promise<{
|
|
65
|
+
code: number;
|
|
66
|
+
msg?: string;
|
|
67
|
+
type?: VoteStatus;
|
|
68
|
+
}>;
|
|
69
|
+
thank(id: string): Promise<ApiResponse<undefined>>;
|
|
70
|
+
}
|
|
71
|
+
export default Article;
|
package/lib/article.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var utils_1 = require("./utils");
|
|
51
|
+
var Article = /** @class */ (function () {
|
|
52
|
+
function Article(token) {
|
|
53
|
+
if (token === void 0) { token = ''; }
|
|
54
|
+
this._apiKey = '';
|
|
55
|
+
if (!token) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this._apiKey = token;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 重新设置请求 Token
|
|
62
|
+
* @param apiKey 接口 API Key
|
|
63
|
+
*/
|
|
64
|
+
Article.prototype.setToken = function (token) {
|
|
65
|
+
this._apiKey = token;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 发布文章
|
|
69
|
+
* @param data 文章信息
|
|
70
|
+
* @returns 发布成功返回文章Id (articleId)
|
|
71
|
+
*/
|
|
72
|
+
Article.prototype.post = function (data) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
var rsp, e_1;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
_a.trys.push([0, 2, , 3]);
|
|
79
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
80
|
+
url: "article",
|
|
81
|
+
method: 'post',
|
|
82
|
+
data: __assign(__assign({}, data), { apiKey: this._apiKey }),
|
|
83
|
+
})];
|
|
84
|
+
case 1:
|
|
85
|
+
rsp = _a.sent();
|
|
86
|
+
return [2 /*return*/, rsp];
|
|
87
|
+
case 2:
|
|
88
|
+
e_1 = _a.sent();
|
|
89
|
+
throw e_1;
|
|
90
|
+
case 3: return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* 更新文章
|
|
97
|
+
* @param id 文章 Id
|
|
98
|
+
* @param data 文章信息
|
|
99
|
+
* @returns 更新成功返回文章Id (articleId)
|
|
100
|
+
*/
|
|
101
|
+
Article.prototype.update = function (id, data) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var rsp, e_2;
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
_a.trys.push([0, 2, , 3]);
|
|
108
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
109
|
+
url: "article/".concat(id),
|
|
110
|
+
method: 'put',
|
|
111
|
+
data: __assign(__assign({}, data), { apiKey: this._apiKey }),
|
|
112
|
+
})];
|
|
113
|
+
case 1:
|
|
114
|
+
rsp = _a.sent();
|
|
115
|
+
return [2 /*return*/, rsp];
|
|
116
|
+
case 2:
|
|
117
|
+
e_2 = _a.sent();
|
|
118
|
+
throw e_2;
|
|
119
|
+
case 3: return [2 /*return*/];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* 查询文章列表
|
|
126
|
+
* @param type 查询类型
|
|
127
|
+
* @param tag 指定查询标签,可选
|
|
128
|
+
* @returns 文章列表
|
|
129
|
+
*/
|
|
130
|
+
Article.prototype.list = function (_a) {
|
|
131
|
+
var type = _a.type, _b = _a.page, page = _b === void 0 ? 1 : _b, tag = _a.tag;
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var rsp, e_3;
|
|
134
|
+
return __generator(this, function (_c) {
|
|
135
|
+
switch (_c.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
_c.trys.push([0, 2, , 3]);
|
|
138
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
139
|
+
url: "api/articles/".concat(tag !== undefined ? "tag/".concat(tag) : 'recent').concat(type, "?p=").concat(page, "&").concat(this._apiKey ? "apiKey=".concat(this._apiKey) : ''),
|
|
140
|
+
})];
|
|
141
|
+
case 1:
|
|
142
|
+
rsp = _c.sent();
|
|
143
|
+
return [2 /*return*/, rsp];
|
|
144
|
+
case 2:
|
|
145
|
+
e_3 = _c.sent();
|
|
146
|
+
throw e_3;
|
|
147
|
+
case 3: return [2 /*return*/];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* 查询用户文章列表
|
|
154
|
+
* @param userName 用户名
|
|
155
|
+
* @returns 文章列表
|
|
156
|
+
*/
|
|
157
|
+
Article.prototype.userArticles = function (_a) {
|
|
158
|
+
var userName = _a.userName, _b = _a.page, page = _b === void 0 ? 1 : _b;
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var rsp, e_4;
|
|
161
|
+
return __generator(this, function (_c) {
|
|
162
|
+
switch (_c.label) {
|
|
163
|
+
case 0:
|
|
164
|
+
_c.trys.push([0, 2, , 3]);
|
|
165
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
166
|
+
url: "api/articles/".concat(userName, "/articles?p=").concat(page, "&").concat(this._apiKey ? "apiKey=".concat(this._apiKey) : ''),
|
|
167
|
+
})];
|
|
168
|
+
case 1:
|
|
169
|
+
rsp = _c.sent();
|
|
170
|
+
return [2 /*return*/, rsp];
|
|
171
|
+
case 2:
|
|
172
|
+
e_4 = _c.sent();
|
|
173
|
+
throw e_4;
|
|
174
|
+
case 3: return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* 获取文章详情
|
|
181
|
+
* @param id 文章id
|
|
182
|
+
* @returns 文章详情
|
|
183
|
+
*/
|
|
184
|
+
Article.prototype.detail = function (id, p) {
|
|
185
|
+
if (p === void 0) { p = 1; }
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
var rsp, i, i, e_5;
|
|
188
|
+
return __generator(this, function (_a) {
|
|
189
|
+
switch (_a.label) {
|
|
190
|
+
case 0:
|
|
191
|
+
_a.trys.push([0, 2, , 3]);
|
|
192
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
193
|
+
url: "api/article/".concat(id, "?apiKey=").concat(this._apiKey, "&p=").concat(p),
|
|
194
|
+
})];
|
|
195
|
+
case 1:
|
|
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);
|
|
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);
|
|
203
|
+
}
|
|
204
|
+
return [2 /*return*/, rsp];
|
|
205
|
+
case 2:
|
|
206
|
+
e_5 = _a.sent();
|
|
207
|
+
throw e_5;
|
|
208
|
+
case 3: return [2 /*return*/];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* 点赞/取消点赞文章
|
|
215
|
+
* @param id 文章id
|
|
216
|
+
* @returns 文章点赞状态
|
|
217
|
+
*/
|
|
218
|
+
Article.prototype.vote = function (id) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
+
var rsp, e_6;
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
switch (_a.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
_a.trys.push([0, 2, , 3]);
|
|
225
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
226
|
+
url: "/vote/up/article",
|
|
227
|
+
method: 'post',
|
|
228
|
+
data: {
|
|
229
|
+
dataId: id,
|
|
230
|
+
apiKey: this._apiKey
|
|
231
|
+
},
|
|
232
|
+
})];
|
|
233
|
+
case 1:
|
|
234
|
+
rsp = _a.sent();
|
|
235
|
+
return [2 /*return*/, rsp];
|
|
236
|
+
case 2:
|
|
237
|
+
e_6 = _a.sent();
|
|
238
|
+
throw e_6;
|
|
239
|
+
case 3: return [2 /*return*/];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
Article.prototype.thank = function (id) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
+
var rsp, e_7;
|
|
247
|
+
return __generator(this, function (_a) {
|
|
248
|
+
switch (_a.label) {
|
|
249
|
+
case 0:
|
|
250
|
+
_a.trys.push([0, 2, , 3]);
|
|
251
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
252
|
+
url: "/article/thank?articleId=".concat(id),
|
|
253
|
+
method: 'post',
|
|
254
|
+
data: {
|
|
255
|
+
apiKey: this._apiKey
|
|
256
|
+
},
|
|
257
|
+
})];
|
|
258
|
+
case 1:
|
|
259
|
+
rsp = _a.sent();
|
|
260
|
+
return [2 /*return*/, rsp.data];
|
|
261
|
+
case 2:
|
|
262
|
+
e_7 = _a.sent();
|
|
263
|
+
throw e_7;
|
|
264
|
+
case 3: return [2 /*return*/];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
return Article;
|
|
270
|
+
}());
|
|
271
|
+
exports.default = Article;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ApiResponse, BreezemoonContent } from './typing';
|
|
2
|
+
declare class Breezemoon {
|
|
3
|
+
private _apiKey;
|
|
4
|
+
constructor(token?: string);
|
|
5
|
+
/**
|
|
6
|
+
* 重新设置请求 Token
|
|
7
|
+
* @param apiKey 接口 API Key
|
|
8
|
+
*/
|
|
9
|
+
setToken(token: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* 获取清风明月列表
|
|
12
|
+
* @param page 消息页码
|
|
13
|
+
* @param size 每页个数
|
|
14
|
+
*/
|
|
15
|
+
list(page?: number, size?: number): Promise<{
|
|
16
|
+
code: number;
|
|
17
|
+
breezemoons: Array<BreezemoonContent>;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* 发送清风明月
|
|
21
|
+
* @param content 内容
|
|
22
|
+
*/
|
|
23
|
+
send(content: string): Promise<ApiResponse<undefined>>;
|
|
24
|
+
}
|
|
25
|
+
export default Breezemoon;
|
|
@@ -0,0 +1,116 @@
|
|
|
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 Breezemoon = /** @class */ (function () {
|
|
41
|
+
function Breezemoon(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
|
+
Breezemoon.prototype.setToken = function (token) {
|
|
54
|
+
this._apiKey = token;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 获取清风明月列表
|
|
58
|
+
* @param page 消息页码
|
|
59
|
+
* @param size 每页个数
|
|
60
|
+
*/
|
|
61
|
+
Breezemoon.prototype.list = function (page, size) {
|
|
62
|
+
if (page === void 0) { page = 1; }
|
|
63
|
+
if (size === void 0) { size = 20; }
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var rsp, e_1;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
_a.trys.push([0, 2, , 3]);
|
|
70
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
71
|
+
url: "api/breezemoons?p=".concat(page, "&size=").concat(size)
|
|
72
|
+
})];
|
|
73
|
+
case 1:
|
|
74
|
+
rsp = _a.sent();
|
|
75
|
+
return [2 /*return*/, rsp];
|
|
76
|
+
case 2:
|
|
77
|
+
e_1 = _a.sent();
|
|
78
|
+
throw e_1;
|
|
79
|
+
case 3: return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* 发送清风明月
|
|
86
|
+
* @param content 内容
|
|
87
|
+
*/
|
|
88
|
+
Breezemoon.prototype.send = function (content) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var rsp, e_2;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
_a.trys.push([0, 2, , 3]);
|
|
95
|
+
return [4 /*yield*/, (0, utils_1.request)({
|
|
96
|
+
url: "breezemoon",
|
|
97
|
+
method: 'post',
|
|
98
|
+
data: {
|
|
99
|
+
apiKey: this._apiKey,
|
|
100
|
+
breezemoonContent: content
|
|
101
|
+
},
|
|
102
|
+
})];
|
|
103
|
+
case 1:
|
|
104
|
+
rsp = _a.sent();
|
|
105
|
+
return [2 /*return*/, rsp];
|
|
106
|
+
case 2:
|
|
107
|
+
e_2 = _a.sent();
|
|
108
|
+
throw e_2;
|
|
109
|
+
case 3: return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
return Breezemoon;
|
|
115
|
+
}());
|
|
116
|
+
exports.default = Breezemoon;
|
package/lib/chat.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import ReconnectingWebSocket from 'reconnecting-websocket';
|
|
2
|
+
import { ApiResponse, ChatData } from './typing';
|
|
3
|
+
declare class Chat {
|
|
4
|
+
private _apiKey;
|
|
5
|
+
private _rwss;
|
|
6
|
+
private _wsCallbacks;
|
|
7
|
+
constructor(token?: string);
|
|
8
|
+
/**
|
|
9
|
+
* 重新设置请求 Token
|
|
10
|
+
* @param apiKey 接口 API Key
|
|
11
|
+
*/
|
|
12
|
+
setToken(apiKey: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* 获取有私聊用户列表第一条消息
|
|
15
|
+
* @returns 私聊消息列表
|
|
16
|
+
*/
|
|
17
|
+
list(): Promise<ApiResponse<Array<ChatData>>>;
|
|
18
|
+
/**
|
|
19
|
+
* 获取用户私聊历史消息
|
|
20
|
+
* @param param 消息参数
|
|
21
|
+
* @returns 私聊消息列表
|
|
22
|
+
*/
|
|
23
|
+
get(param: {
|
|
24
|
+
user: string;
|
|
25
|
+
page: 1;
|
|
26
|
+
size: 20;
|
|
27
|
+
autoRead: true;
|
|
28
|
+
}): Promise<ApiResponse<Array<ChatData>>>;
|
|
29
|
+
/**
|
|
30
|
+
* 标记用户消息已读
|
|
31
|
+
* @param user 用户名
|
|
32
|
+
* @returns 执行结果
|
|
33
|
+
*/
|
|
34
|
+
markRead(user: string): Promise<ApiResponse<undefined>>;
|
|
35
|
+
/**
|
|
36
|
+
* 获取未读消息
|
|
37
|
+
* @returns 未读消息列表
|
|
38
|
+
*/
|
|
39
|
+
unread(): Promise<ApiResponse<ChatData>>;
|
|
40
|
+
/**
|
|
41
|
+
* 移除聊天室消息监听函数
|
|
42
|
+
* @param user 指定用户消息监听函数,空为新信息监听
|
|
43
|
+
* @param wsCallback 要移除的函数,若为空,则清空消息监听
|
|
44
|
+
*/
|
|
45
|
+
removeListener(user: string | undefined, wsCallback: Function): void;
|
|
46
|
+
/**
|
|
47
|
+
* 添加聊天室消息监听函数
|
|
48
|
+
* @param wsCallback 消息监听函数
|
|
49
|
+
* @param user 指定为用户消息监听函数,空为新信息监听
|
|
50
|
+
*/
|
|
51
|
+
addListener(wsCallback: Function, user?: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* 连接用户私聊频道
|
|
54
|
+
* @param user 私聊用户名
|
|
55
|
+
* @returns Websocket 连接对象
|
|
56
|
+
*/
|
|
57
|
+
connect(user: string): Promise<ReconnectingWebSocket>;
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param user 私聊用户名
|
|
61
|
+
* @param content 私聊内容
|
|
62
|
+
* @returns Websocket 连接对象
|
|
63
|
+
*/
|
|
64
|
+
send(user: string, content: string): Promise<ReconnectingWebSocket>;
|
|
65
|
+
}
|
|
66
|
+
export default Chat;
|