fishpi 0.0.4 → 0.0.8

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.
@@ -0,0 +1,308 @@
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 (_) 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 Emoji = /** @class */ (function () {
41
+ function Emoji(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
+ Emoji.prototype.setToken = function (token) {
54
+ this._apiKey = token;
55
+ };
56
+ Object.defineProperty(Emoji.prototype, "default", {
57
+ get: function () {
58
+ return {
59
+ "doge": "https://cdn.jsdelivr.net/npm/vditor@3.8.7/dist/images/emoji/doge.png",
60
+ "trollface": "https://cdn.jsdelivr.net/npm/vditor@3.8.7/dist/images/emoji/trollface.png",
61
+ "huaji": "https://cdn.jsdelivr.net/npm/vditor@3.8.7/dist/images/emoji/huaji.gif",
62
+ "octocat": "https://cdn.jsdelivr.net/npm/vditor@3.8.7/dist/images/emoji/octocat.png",
63
+ "wulian": "https://cdn.jsdelivr.net/npm/vditor@3.8.7/dist/images/emoji/wulian.png",
64
+ "smile": "https://".concat(utils_1.domain, "/emoji/graphics/smile.png"),
65
+ "laughing": "https://".concat(utils_1.domain, "/emoji/graphics/laughing.png"),
66
+ "blush": "https://".concat(utils_1.domain, "/emoji/graphics/blush.png"),
67
+ "smiley": "https://".concat(utils_1.domain, "/emoji/graphics/smiley.png"),
68
+ "relaxed": "https://".concat(utils_1.domain, "/emoji/graphics/relaxed.png"),
69
+ "smirk": "https://".concat(utils_1.domain, "/emoji/graphics/smirk.png"),
70
+ "heart_eyes": "https://".concat(utils_1.domain, "/emoji/graphics/heart_eyes.png"),
71
+ "kissing_heart": "https://".concat(utils_1.domain, "/emoji/graphics/kissing_heart.png"),
72
+ "kissing_closed_eyes": "https://".concat(utils_1.domain, "/emoji/graphics/kissing_closed_eyes.png"),
73
+ "flushed": "https://".concat(utils_1.domain, "/emoji/graphics/flushed.png"),
74
+ "relieved": "https://".concat(utils_1.domain, "/emoji/graphics/relieved.png"),
75
+ "satisfied": "https://".concat(utils_1.domain, "/emoji/graphics/satisfied.png"),
76
+ "grin": "https://".concat(utils_1.domain, "/emoji/graphics/grin.png"),
77
+ "wink": "https://".concat(utils_1.domain, "/emoji/graphics/wink.png"),
78
+ "stuck_out_tongue_winking_eye": "https://".concat(utils_1.domain, "/emoji/graphics/stuck_out_tongue_winking_eye.png"),
79
+ "stuck_out_tongue_closed_eyes": "https://".concat(utils_1.domain, "/emoji/graphics/stuck_out_tongue_closed_eyes.png"),
80
+ "grinning": "https://".concat(utils_1.domain, "/emoji/graphics/grinning.png"),
81
+ "kissing": "https://".concat(utils_1.domain, "/emoji/graphics/kissing.png"),
82
+ "kissing_smiling_eyes": "https://".concat(utils_1.domain, "/emoji/graphics/kissing_smiling_eyes.png"),
83
+ "stuck_out_tongue": "https://".concat(utils_1.domain, "/emoji/graphics/stuck_out_tongue.png"),
84
+ "sleeping": "https://".concat(utils_1.domain, "/emoji/graphics/sleeping.png"),
85
+ "worried": "https://".concat(utils_1.domain, "/emoji/graphics/worried.png"),
86
+ "frowning": "https://".concat(utils_1.domain, "/emoji/graphics/frowning.png"),
87
+ "anguished": "https://".concat(utils_1.domain, "/emoji/graphics/anguished.png"),
88
+ "open_mouth": "https://".concat(utils_1.domain, "/emoji/graphics/open_mouth.png"),
89
+ "grimacing": "https://".concat(utils_1.domain, "/emoji/graphics/grimacing.png"),
90
+ "confused": "https://".concat(utils_1.domain, "/emoji/graphics/confused.png"),
91
+ "hushed": "https://".concat(utils_1.domain, "/emoji/graphics/hushed.png"),
92
+ "expressionless": "https://".concat(utils_1.domain, "/emoji/graphics/expressionless.png"),
93
+ "unamused": "https://".concat(utils_1.domain, "/emoji/graphics/unamused.png"),
94
+ "sweat_smile": "https://".concat(utils_1.domain, "/emoji/graphics/sweat_smile.png"),
95
+ "sweat": "https://".concat(utils_1.domain, "/emoji/graphics/sweat.png"),
96
+ "disappointed_relieved": "https://".concat(utils_1.domain, "/emoji/graphics/disappointed_relieved.png"),
97
+ "weary": "https://".concat(utils_1.domain, "/emoji/graphics/weary.png"),
98
+ "pensive": "https://".concat(utils_1.domain, "/emoji/graphics/pensive.png"),
99
+ "disappointed": "https://".concat(utils_1.domain, "/emoji/graphics/disappointed.png"),
100
+ "confounded": "https://".concat(utils_1.domain, "/emoji/graphics/confounded.png"),
101
+ "fearful": "https://".concat(utils_1.domain, "/emoji/graphics/fearful.png"),
102
+ "cold_sweat": "https://".concat(utils_1.domain, "/emoji/graphics/cold_sweat.png"),
103
+ "persevere": "https://".concat(utils_1.domain, "/emoji/graphics/persevere.png"),
104
+ "cry": "https://".concat(utils_1.domain, "/emoji/graphics/cry.png"),
105
+ "sob": "https://".concat(utils_1.domain, "/emoji/graphics/sob.png"),
106
+ "joy": "https://".concat(utils_1.domain, "/emoji/graphics/joy.png"),
107
+ "astonished": "https://".concat(utils_1.domain, "/emoji/graphics/astonished.png"),
108
+ "scream": "https://".concat(utils_1.domain, "/emoji/graphics/scream.png"),
109
+ "tired_face": "https://".concat(utils_1.domain, "/emoji/graphics/tired_face.png"),
110
+ "angry": "https://".concat(utils_1.domain, "/emoji/graphics/angry.png"),
111
+ "rage": "https://".concat(utils_1.domain, "/emoji/graphics/rage.png"),
112
+ "triumph": "https://".concat(utils_1.domain, "/emoji/graphics/triumph.png"),
113
+ "sleepy": "https://".concat(utils_1.domain, "/emoji/graphics/sleepy.png"),
114
+ "yum": "https://".concat(utils_1.domain, "/emoji/graphics/yum.png"),
115
+ "mask": "https://".concat(utils_1.domain, "/emoji/graphics/mask.png"),
116
+ "sunglasses": "https://".concat(utils_1.domain, "/emoji/graphics/sunglasses.png"),
117
+ "dizzy_face": "https://".concat(utils_1.domain, "/emoji/graphics/dizzy_face.png"),
118
+ "imp": "https://".concat(utils_1.domain, "/emoji/graphics/imp.png"),
119
+ "smiling_imp": "https://".concat(utils_1.domain, "/emoji/graphics/smiling_imp.png"),
120
+ "neutral_face": "https://".concat(utils_1.domain, "/emoji/graphics/neutral_face.png"),
121
+ "no_mouth": "https://".concat(utils_1.domain, "/emoji/graphics/no_mouth.png"),
122
+ "innocent": "https://".concat(utils_1.domain, "/emoji/graphics/innocent.png"),
123
+ "alien": "https://".concat(utils_1.domain, "/emoji/graphics/alien.png"),
124
+ "yellow_heart": "https://".concat(utils_1.domain, "/emoji/graphics/yellow_heart.png"),
125
+ "blue_heart": "https://".concat(utils_1.domain, "/emoji/graphics/blue_heart.png"),
126
+ "purple_heart": "https://".concat(utils_1.domain, "/emoji/graphics/purple_heart.png"),
127
+ "heart": "https://".concat(utils_1.domain, "/emoji/graphics/heart.png"),
128
+ "green_heart": "https://".concat(utils_1.domain, "/emoji/graphics/green_heart.png"),
129
+ "broken_heart": "https://".concat(utils_1.domain, "/emoji/graphics/broken_heart.png"),
130
+ "heartbeat": "https://".concat(utils_1.domain, "/emoji/graphics/heartbeat.png"),
131
+ "heartpulse": "https://".concat(utils_1.domain, "/emoji/graphics/heartpulse.png"),
132
+ "two_hearts": "https://".concat(utils_1.domain, "/emoji/graphics/two_hearts.png"),
133
+ "revolving_hearts": "https://".concat(utils_1.domain, "/emoji/graphics/revolving_hearts.png"),
134
+ "cupid": "https://".concat(utils_1.domain, "/emoji/graphics/cupid.png"),
135
+ "sparkling_heart": "https://".concat(utils_1.domain, "/emoji/graphics/sparkling_heart.png"),
136
+ "sparkles": "https://".concat(utils_1.domain, "/emoji/graphics/sparkles.png"),
137
+ "star": "https://".concat(utils_1.domain, "/emoji/graphics/star.png"),
138
+ "star2": "https://".concat(utils_1.domain, "/emoji/graphics/star2.png"),
139
+ "dizzy": "https://".concat(utils_1.domain, "/emoji/graphics/dizzy.png"),
140
+ "boom": "https://".concat(utils_1.domain, "/emoji/graphics/boom.png"),
141
+ "collision": "https://".concat(utils_1.domain, "/emoji/graphics/collision.png"),
142
+ "anger": "https://".concat(utils_1.domain, "/emoji/graphics/anger.png"),
143
+ "exclamation": "https://".concat(utils_1.domain, "/emoji/graphics/exclamation.png"),
144
+ "question": "https://".concat(utils_1.domain, "/emoji/graphics/question.png"),
145
+ "grey_exclamation": "https://".concat(utils_1.domain, "/emoji/graphics/grey_exclamation.png"),
146
+ "grey_question": "https://".concat(utils_1.domain, "/emoji/graphics/grey_question.png"),
147
+ "zzz": "https://".concat(utils_1.domain, "/emoji/graphics/zzz.png"),
148
+ "dash": "https://".concat(utils_1.domain, "/emoji/graphics/dash.png"),
149
+ "sweat_drops": "https://".concat(utils_1.domain, "/emoji/graphics/sweat_drops.png"),
150
+ "notes": "https://".concat(utils_1.domain, "/emoji/graphics/notes.png"),
151
+ "musical_note": "https://".concat(utils_1.domain, "/emoji/graphics/musical_note.png"),
152
+ "fire": "https://".concat(utils_1.domain, "/emoji/graphics/fire.png"),
153
+ "poop": "https://".concat(utils_1.domain, "/emoji/graphics/poop.png"),
154
+ "+1": "https://".concat(utils_1.domain, "/emoji/graphics/%2B1.png"),
155
+ "thumbsup": "https://".concat(utils_1.domain, "/emoji/graphics/thumbsup.png"),
156
+ "-1": "https://".concat(utils_1.domain, "/emoji/graphics/-1.png"),
157
+ "thumbsdown": "https://".concat(utils_1.domain, "/emoji/graphics/thumbsdown.png"),
158
+ "ok_hand": "https://".concat(utils_1.domain, "/emoji/graphics/ok_hand.png"),
159
+ "punch": "https://".concat(utils_1.domain, "/emoji/graphics/punch.png"),
160
+ "facepunch": "https://".concat(utils_1.domain, "/emoji/graphics/facepunch.png"),
161
+ "fist": "https://".concat(utils_1.domain, "/emoji/graphics/fist.png"),
162
+ "v": "https://".concat(utils_1.domain, "/emoji/graphics/v.png"),
163
+ "wave": "https://".concat(utils_1.domain, "/emoji/graphics/wave.png"),
164
+ "hand": "https://".concat(utils_1.domain, "/emoji/graphics/hand.png"),
165
+ "raised_hand": "https://".concat(utils_1.domain, "/emoji/graphics/raised_hand.png"),
166
+ "open_hands": "https://".concat(utils_1.domain, "/emoji/graphics/open_hands.png"),
167
+ "point_up": "https://".concat(utils_1.domain, "/emoji/graphics/point_up.png"),
168
+ "point_down": "https://".concat(utils_1.domain, "/emoji/graphics/point_down.png"),
169
+ "point_left": "https://".concat(utils_1.domain, "/emoji/graphics/point_left.png"),
170
+ "point_right": "https://".concat(utils_1.domain, "/emoji/graphics/point_right.png"),
171
+ "raised_hands": "https://".concat(utils_1.domain, "/emoji/graphics/raised_hands.png"),
172
+ "pray": "https://".concat(utils_1.domain, "/emoji/graphics/pray.png"),
173
+ "point_up_2": "https://".concat(utils_1.domain, "/emoji/graphics/point_up_2.png"),
174
+ "clap": "https://".concat(utils_1.domain, "/emoji/graphics/clap.png"),
175
+ "muscle": "https://".concat(utils_1.domain, "/emoji/graphics/muscle.png"),
176
+ "couple": "https://".concat(utils_1.domain, "/emoji/graphics/couple.png"),
177
+ "family": "https://".concat(utils_1.domain, "/emoji/graphics/family.png"),
178
+ "two_men_holding_hands": "https://".concat(utils_1.domain, "/emoji/graphics/two_men_holding_hands.png"),
179
+ "two_women_holding_hands": "https://".concat(utils_1.domain, "/emoji/graphics/two_women_holding_hands.png"),
180
+ "dancer": "https://".concat(utils_1.domain, "/emoji/graphics/dancer.png"),
181
+ "dancers": "https://".concat(utils_1.domain, "/emoji/graphics/dancers.png"),
182
+ "ok_woman": "https://".concat(utils_1.domain, "/emoji/graphics/ok_woman.png"),
183
+ "no_good": "https://".concat(utils_1.domain, "/emoji/graphics/no_good.png"),
184
+ "information_desk_person": "https://".concat(utils_1.domain, "/emoji/graphics/information_desk_person.png"),
185
+ "raising_hand": "https://".concat(utils_1.domain, "/emoji/graphics/raising_hand.png"),
186
+ "bride_with_veil": "https://".concat(utils_1.domain, "/emoji/graphics/bride_with_veil.png"),
187
+ "person_with_pouting_face": "https://".concat(utils_1.domain, "/emoji/graphics/person_with_pouting_face.png"),
188
+ "person_frowning": "https://".concat(utils_1.domain, "/emoji/graphics/person_frowning.png"),
189
+ "bow": "https://".concat(utils_1.domain, "/emoji/graphics/bow.png"),
190
+ "couplekiss": "https://".concat(utils_1.domain, "/emoji/graphics/couplekiss.png"),
191
+ "couple_with_heart": "https://".concat(utils_1.domain, "/emoji/graphics/couple_with_heart.png"),
192
+ "massage": "https://".concat(utils_1.domain, "/emoji/graphics/massage.png"),
193
+ "haircut": "https://".concat(utils_1.domain, "/emoji/graphics/haircut.png"),
194
+ "nail_care": "https://".concat(utils_1.domain, "/emoji/graphics/nail_care.png"),
195
+ "boy": "https://".concat(utils_1.domain, "/emoji/graphics/boy.png"),
196
+ "girl": "https://".concat(utils_1.domain, "/emoji/graphics/girl.png"),
197
+ "woman": "https://".concat(utils_1.domain, "/emoji/graphics/woman.png"),
198
+ "man": "https://".concat(utils_1.domain, "/emoji/graphics/man.png"),
199
+ "baby": "https://".concat(utils_1.domain, "/emoji/graphics/baby.png"),
200
+ "older_woman": "https://".concat(utils_1.domain, "/emoji/graphics/older_woman.png"),
201
+ "older_man": "https://".concat(utils_1.domain, "/emoji/graphics/older_man.png"),
202
+ "person_with_blond_hair": "https://".concat(utils_1.domain, "/emoji/graphics/person_with_blond_hair.png"),
203
+ "man_with_gua_pi_mao": "https://".concat(utils_1.domain, "/emoji/graphics/man_with_gua_pi_mao.png"),
204
+ "man_with_turban": "https://".concat(utils_1.domain, "/emoji/graphics/man_with_turban.png"),
205
+ "construction_worker": "https://".concat(utils_1.domain, "/emoji/graphics/construction_worker.png"),
206
+ "cop": "https://".concat(utils_1.domain, "/emoji/graphics/cop.png"),
207
+ "angel": "https://".concat(utils_1.domain, "/emoji/graphics/angel.png"),
208
+ "princess": "https://".concat(utils_1.domain, "/emoji/graphics/princess.png"),
209
+ "smiley_cat": "https://".concat(utils_1.domain, "/emoji/graphics/smiley_cat.png"),
210
+ "smile_cat": "https://".concat(utils_1.domain, "/emoji/graphics/smile_cat.png"),
211
+ "heart_eyes_cat": "https://".concat(utils_1.domain, "/emoji/graphics/heart_eyes_cat.png"),
212
+ "kissing_cat": "https://".concat(utils_1.domain, "/emoji/graphics/kissing_cat.png"),
213
+ "smirk_cat": "https://".concat(utils_1.domain, "/emoji/graphics/smirk_cat.png"),
214
+ "scream_cat": "https://".concat(utils_1.domain, "/emoji/graphics/scream_cat.png"),
215
+ "crying_cat_face": "https://".concat(utils_1.domain, "/emoji/graphics/crying_cat_face.png"),
216
+ "joy_cat": "https://".concat(utils_1.domain, "/emoji/graphics/joy_cat.png"),
217
+ "pouting_cat": "https://".concat(utils_1.domain, "/emoji/graphics/pouting_cat.png"),
218
+ "japanese_ogre": "https://".concat(utils_1.domain, "/emoji/graphics/japanese_ogre.png"),
219
+ "japanese_goblin": "https://".concat(utils_1.domain, "/emoji/graphics/japanese_goblin.png"),
220
+ "see_no_evil": "https://".concat(utils_1.domain, "/emoji/graphics/see_no_evil.png"),
221
+ "hear_no_evil": "https://".concat(utils_1.domain, "/emoji/graphics/hear_no_evil.png"),
222
+ "speak_no_evil": "https://".concat(utils_1.domain, "/emoji/graphics/speak_no_evil.png"),
223
+ "guardsman": "https://".concat(utils_1.domain, "/emoji/graphics/guardsman.png"),
224
+ "skull": "https://".concat(utils_1.domain, "/emoji/graphics/skull.png"),
225
+ "feet": "https://".concat(utils_1.domain, "/emoji/graphics/feet.png"),
226
+ "lips": "https://".concat(utils_1.domain, "/emoji/graphics/lips.png"),
227
+ "kiss": "https://".concat(utils_1.domain, "/emoji/graphics/kiss.png"),
228
+ "droplet": "https://".concat(utils_1.domain, "/emoji/graphics/droplet.png"),
229
+ "ear": "https://".concat(utils_1.domain, "/emoji/graphics/ear.png"),
230
+ "eyes": "https://".concat(utils_1.domain, "/emoji/graphics/eyes.png"),
231
+ "nose": "https://".concat(utils_1.domain, "/emoji/graphics/nose.png"),
232
+ "tongue": "https://".concat(utils_1.domain, "/emoji/graphics/tongue.png"),
233
+ "love_letter": "https://".concat(utils_1.domain, "/emoji/graphics/love_letter.png"),
234
+ "bust_in_silhouette": "https://".concat(utils_1.domain, "/emoji/graphics/bust_in_silhouette.png"),
235
+ "busts_in_silhouette": "https://".concat(utils_1.domain, "/emoji/graphics/busts_in_silhouette.png"),
236
+ "speech_balloon": "https://".concat(utils_1.domain, "/emoji/graphics/speech_balloon.png"),
237
+ "thought_balloon": "https://".concat(utils_1.domain, "/emoji/graphics/thought_balloon.png")
238
+ };
239
+ },
240
+ enumerable: false,
241
+ configurable: true
242
+ });
243
+ Emoji.prototype.get = function () {
244
+ return __awaiter(this, void 0, void 0, function () {
245
+ var rsp, e_1;
246
+ return __generator(this, function (_a) {
247
+ switch (_a.label) {
248
+ case 0:
249
+ _a.trys.push([0, 2, , 3]);
250
+ return [4 /*yield*/, (0, utils_1.request)({
251
+ url: "api/cloud/get",
252
+ method: 'post',
253
+ data: {
254
+ gameId: 'emojis',
255
+ apiKey: this._apiKey
256
+ },
257
+ })];
258
+ case 1:
259
+ rsp = _a.sent();
260
+ if (rsp.status === 401) {
261
+ throw new Error('登录已失效,请重新登录!');
262
+ }
263
+ return [2 /*return*/, JSON.parse(rsp.data.data)];
264
+ case 2:
265
+ e_1 = _a.sent();
266
+ throw e_1;
267
+ case 3: return [2 /*return*/];
268
+ }
269
+ });
270
+ });
271
+ };
272
+ /**
273
+ * 设置表情包列表
274
+ * @param data 所有表情包图像列表
275
+ */
276
+ Emoji.prototype.set = function (data) {
277
+ return __awaiter(this, void 0, void 0, function () {
278
+ var rsp, e_2;
279
+ return __generator(this, function (_a) {
280
+ switch (_a.label) {
281
+ case 0:
282
+ _a.trys.push([0, 2, , 3]);
283
+ return [4 /*yield*/, (0, utils_1.request)({
284
+ url: "api/cloud/sync",
285
+ method: 'post',
286
+ data: {
287
+ gameId: 'emojis',
288
+ data: JSON.stringify(data),
289
+ apiKey: this._apiKey
290
+ },
291
+ })];
292
+ case 1:
293
+ rsp = _a.sent();
294
+ if (rsp.status === 401) {
295
+ throw new Error('登录已失效,请重新登录!');
296
+ }
297
+ return [2 /*return*/, rsp.data];
298
+ case 2:
299
+ e_2 = _a.sent();
300
+ throw e_2;
301
+ case 3: return [2 /*return*/];
302
+ }
303
+ });
304
+ });
305
+ };
306
+ return Emoji;
307
+ }());
308
+ exports.default = Emoji;
@@ -0,0 +1,64 @@
1
+ import { ApiResponse, Account, UserInfo, AtUserList, UploadInfo, ApiKey } from './typing';
2
+ import ChatRoom from './chatroom';
3
+ import Notice from './notice';
4
+ import Emoji from './emoji';
5
+ import User from './user';
6
+ import Article from './article';
7
+ import Chat from './chat';
8
+ declare class FishPi {
9
+ /**
10
+ * 请求 API 的 API Key
11
+ */
12
+ apiKey: string;
13
+ /**
14
+ * 聊天室接口对象
15
+ */
16
+ chatroom: ChatRoom;
17
+ /**
18
+ * 通知接口对象
19
+ */
20
+ notice: Notice;
21
+ /**
22
+ * 表情包接口对象
23
+ */
24
+ emoji: Emoji;
25
+ /**
26
+ * 用户接口对象
27
+ */
28
+ account: User;
29
+ /**
30
+ * 文章接口对象
31
+ */
32
+ article: Article;
33
+ /**
34
+ * 私聊接口对象
35
+ */
36
+ chat: Chat;
37
+ /**
38
+ * 构造一个 API 请求对象
39
+ * @param token 接口 API Key,没有可以传空
40
+ */
41
+ constructor(token?: string);
42
+ setToken(apiKey: string): Promise<void>;
43
+ /**
44
+ * 登录账号返回 API Key
45
+ * @param data 用户账密
46
+ */
47
+ login(data: Account): Promise<ApiKey>;
48
+ /**
49
+ * 查询指定用户信息
50
+ * @param username 用户名
51
+ */
52
+ user(username: string): Promise<ApiResponse<UserInfo>>;
53
+ /**
54
+ * 用户名联想,通常用于 @ 列表
55
+ * @param username 用户名
56
+ */
57
+ names(name: string): Promise<AtUserList>;
58
+ /**
59
+ * 上传文件
60
+ * @param files 要上传的文件,如果是在 Node 使用,则传入文件路径数组,若是在浏览器使用,则传入文件对象数组。
61
+ */
62
+ upload(files: Array<File | string>): Promise<UploadInfo>;
63
+ }
64
+ export default FishPi;
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
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
+ };
57
+ var __importDefault = (this && this.__importDefault) || function (mod) {
58
+ return (mod && mod.__esModule) ? mod : { "default": mod };
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
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 () {
72
+ /**
73
+ * 构造一个 API 请求对象
74
+ * @param token 接口 API Key,没有可以传空
75
+ */
76
+ function FishPi(token) {
77
+ if (token === void 0) { token = ''; }
78
+ /**
79
+ * 请求 API 的 API Key
80
+ */
81
+ this.apiKey = '';
82
+ /**
83
+ * 聊天室接口对象
84
+ */
85
+ this.chatroom = new chatroom_1.default();
86
+ /**
87
+ * 通知接口对象
88
+ */
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();
106
+ if (!token) {
107
+ return;
108
+ }
109
+ this.setToken(token);
110
+ }
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;
115
+ this.chatroom.setToken(this.apiKey);
116
+ this.notice.setToken(this.apiKey);
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
+ });
123
+ });
124
+ };
125
+ /**
126
+ * 登录账号返回 API Key
127
+ * @param data 用户账密
128
+ */
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*/];
154
+ }
155
+ });
156
+ });
157
+ };
158
+ /**
159
+ * 查询指定用户信息
160
+ * @param username 用户名
161
+ */
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*/];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ /**
188
+ * 用户名联想,通常用于 @ 列表
189
+ * @param username 用户名
190
+ */
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*/];
212
+ }
213
+ });
214
+ });
215
+ };
216
+ /**
217
+ * 上传文件
218
+ * @param files 要上传的文件,如果是在 Node 使用,则传入文件路径数组,若是在浏览器使用,则传入文件对象数组。
219
+ */
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
+ });
253
+ });
254
+ };
255
+ return FishPi;
256
+ }());
257
+ exports.default = FishPi;