koishi-plugin-bilibili-notify 3.2.5-alpha.3 → 3.2.5-alpha.5
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/index.js +94890 -28
- package/lib/index.mjs +94885 -20
- package/package.json +1 -1
- package/readme.md +2 -0
- package/lib/assets/HYZhengYuan-75W-CAgMN3FH.ttf +0 -0
- package/lib/biliAPI-CDXS43YV.mjs +0 -659
- package/lib/biliAPI-DyJf03ZZ.js +0 -664
- package/lib/biliAPI.d.mts +0 -82
- package/lib/biliAPI.d.ts +0 -82
- package/lib/biliAPI.js +0 -5
- package/lib/biliAPI.mjs +0 -4
- package/lib/blive-BBVUYbxX.js +0 -43
- package/lib/blive-CyC_0-9A.mjs +0 -37
- package/lib/blive.d.mts +0 -19
- package/lib/blive.d.ts +0 -19
- package/lib/blive.js +0 -4
- package/lib/blive.mjs +0 -3
- package/lib/chunk-CrFLpmCJ.js +0 -67
- package/lib/chunk-DBmNgn_A.mjs +0 -40
- package/lib/comRegister-CcqOpkwB.mjs +0 -1421
- package/lib/comRegister-t7UnYFig.js +0 -1426
- package/lib/comRegister.d.mts +0 -109
- package/lib/comRegister.d.ts +0 -109
- package/lib/comRegister.js +0 -6
- package/lib/comRegister.mjs +0 -5
- package/lib/database-4f9U--Ji.mjs +0 -20
- package/lib/database-Ct2yIdxk.js +0 -37
- package/lib/database-Do3O9MDA.d.mts +0 -18
- package/lib/database-KWDs372o.d.ts +0 -18
- package/lib/database.d.mts +0 -2
- package/lib/database.d.ts +0 -2
- package/lib/database.js +0 -5
- package/lib/database.mjs +0 -3
- package/lib/font/HYZhengYuan-75W.js +0 -5
- package/lib/font/HYZhengYuan-75W.mjs +0 -5
- package/lib/generateImg-E9JeFpQX.js +0 -92628
- package/lib/generateImg-zwzMYjw6.mjs +0 -92623
- package/lib/generateImg.d.mts +0 -65
- package/lib/generateImg.d.ts +0 -65
- package/lib/generateImg.js +0 -5
- package/lib/generateImg.mjs +0 -4
- package/lib/img/arrow.js +0 -5
- package/lib/img/arrow.mjs +0 -5
- package/lib/index-DeGUe4jM.d.mts +0 -265
- package/lib/index-MJKYbMf7.d.ts +0 -265
- package/lib/page/0.js +0 -0
- package/lib/page/0.mjs +0 -0
- package/lib/type/index.d.mts +0 -2
- package/lib/type/index.d.ts +0 -2
- package/lib/type/index.js +0 -5
- package/lib/type/index.mjs +0 -3
- package/lib/type-C5ZxPrgY.mjs +0 -19
- package/lib/type-WjCy4YMc.js +0 -31
- package/lib/utils/index.d.mts +0 -15
- package/lib/utils/index.d.ts +0 -15
- package/lib/utils/index.js +0 -6
- package/lib/utils/index.mjs +0 -3
- package/lib/utils-BoaYrSvG.js +0 -79
- package/lib/utils-C95cnBJG.mjs +0 -61
package/lib/index-MJKYbMf7.d.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
//#region src/type/index.d.ts
|
|
2
|
-
declare enum LiveType {
|
|
3
|
-
NotLiveBroadcast = 0,
|
|
4
|
-
StartBroadcasting = 1,
|
|
5
|
-
LiveBroadcast = 2,
|
|
6
|
-
StopBroadcast = 3,
|
|
7
|
-
FirstLiveBroadcast = 4,
|
|
8
|
-
}
|
|
9
|
-
type Channel = {
|
|
10
|
-
channelId: string;
|
|
11
|
-
dynamic: boolean;
|
|
12
|
-
live: boolean;
|
|
13
|
-
liveGuardBuy: boolean;
|
|
14
|
-
atAll: boolean;
|
|
15
|
-
bot: string;
|
|
16
|
-
};
|
|
17
|
-
type ChannelArr = Array<Channel>;
|
|
18
|
-
type TargetItem = {
|
|
19
|
-
channelArr: ChannelArr;
|
|
20
|
-
platform: string;
|
|
21
|
-
};
|
|
22
|
-
type Target = Array<TargetItem>;
|
|
23
|
-
type SubItem = {
|
|
24
|
-
id: number;
|
|
25
|
-
uid: string;
|
|
26
|
-
uname: string;
|
|
27
|
-
roomId: string;
|
|
28
|
-
target: Target;
|
|
29
|
-
platform: string;
|
|
30
|
-
live: boolean;
|
|
31
|
-
dynamic: boolean;
|
|
32
|
-
card: {
|
|
33
|
-
enable: boolean;
|
|
34
|
-
cardColorStart: string;
|
|
35
|
-
cardColorEnd: string;
|
|
36
|
-
cardBasePlateColor: string;
|
|
37
|
-
cardBasePlateBorder: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
type SubManager = Array<SubItem>;
|
|
41
|
-
type MasterInfo = {
|
|
42
|
-
username: string;
|
|
43
|
-
userface: string;
|
|
44
|
-
roomId: number;
|
|
45
|
-
liveOpenFollowerNum: number;
|
|
46
|
-
liveEndFollowerNum: number;
|
|
47
|
-
liveFollowerChange: number;
|
|
48
|
-
};
|
|
49
|
-
type LiveUsersItem = {
|
|
50
|
-
face: string;
|
|
51
|
-
is_reserve_recall: boolean;
|
|
52
|
-
jump_url: string;
|
|
53
|
-
mid: number;
|
|
54
|
-
room_id: number;
|
|
55
|
-
title: string;
|
|
56
|
-
uname: string;
|
|
57
|
-
};
|
|
58
|
-
type LiveUsers = {
|
|
59
|
-
count: number;
|
|
60
|
-
group: string;
|
|
61
|
-
items: Array<LiveUsersItem>;
|
|
62
|
-
};
|
|
63
|
-
type RichTextNode = Array<{
|
|
64
|
-
emoji?: {
|
|
65
|
-
icon_url: string;
|
|
66
|
-
size: number;
|
|
67
|
-
text: string;
|
|
68
|
-
type: number;
|
|
69
|
-
};
|
|
70
|
-
orig_text: string;
|
|
71
|
-
text: string;
|
|
72
|
-
type: string;
|
|
73
|
-
}>;
|
|
74
|
-
type Dynamic = {
|
|
75
|
-
basic: Object;
|
|
76
|
-
id_str: string;
|
|
77
|
-
modules: {
|
|
78
|
-
module_author: {
|
|
79
|
-
avatar: Object;
|
|
80
|
-
decorate: {
|
|
81
|
-
card_url: string;
|
|
82
|
-
fan: {
|
|
83
|
-
num_str: number;
|
|
84
|
-
color: string;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
face: string;
|
|
88
|
-
face_nft: boolean;
|
|
89
|
-
following: boolean;
|
|
90
|
-
jump_url: string;
|
|
91
|
-
label: string;
|
|
92
|
-
mid: number;
|
|
93
|
-
name: string;
|
|
94
|
-
official_verify: Object;
|
|
95
|
-
pendant: Object;
|
|
96
|
-
pub_action: string;
|
|
97
|
-
pub_action_text: string;
|
|
98
|
-
pub_location_text: string;
|
|
99
|
-
pub_time: string;
|
|
100
|
-
pub_ts: number;
|
|
101
|
-
type: string;
|
|
102
|
-
vip: {
|
|
103
|
-
type: number;
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
module_dynamic: {
|
|
107
|
-
additional: any;
|
|
108
|
-
desc: {
|
|
109
|
-
rich_text_nodes: Array<{
|
|
110
|
-
orig_text: string;
|
|
111
|
-
text: string;
|
|
112
|
-
type: string;
|
|
113
|
-
emoji: {
|
|
114
|
-
icon_url: string;
|
|
115
|
-
size: number;
|
|
116
|
-
text: string;
|
|
117
|
-
type: number;
|
|
118
|
-
};
|
|
119
|
-
jump_url: string;
|
|
120
|
-
rid: string;
|
|
121
|
-
goods: {
|
|
122
|
-
jump_url: string;
|
|
123
|
-
type: number;
|
|
124
|
-
};
|
|
125
|
-
icon_name: string;
|
|
126
|
-
}>;
|
|
127
|
-
text: string;
|
|
128
|
-
};
|
|
129
|
-
major: {
|
|
130
|
-
opus: {
|
|
131
|
-
fold_action: Array<string>;
|
|
132
|
-
jump_url: string;
|
|
133
|
-
pics: Array<{
|
|
134
|
-
height: number;
|
|
135
|
-
live_url: string;
|
|
136
|
-
size: number;
|
|
137
|
-
url: string;
|
|
138
|
-
width: number;
|
|
139
|
-
}>;
|
|
140
|
-
summary: {
|
|
141
|
-
rich_text_nodes: RichTextNode;
|
|
142
|
-
text: string;
|
|
143
|
-
};
|
|
144
|
-
title: string;
|
|
145
|
-
};
|
|
146
|
-
archive: {
|
|
147
|
-
jump_url: string;
|
|
148
|
-
badge: {
|
|
149
|
-
text: string;
|
|
150
|
-
};
|
|
151
|
-
cover: string;
|
|
152
|
-
duration_text: string;
|
|
153
|
-
title: string;
|
|
154
|
-
desc: string;
|
|
155
|
-
stat: {
|
|
156
|
-
play: number;
|
|
157
|
-
danmaku: number;
|
|
158
|
-
};
|
|
159
|
-
bvid: string;
|
|
160
|
-
};
|
|
161
|
-
draw: any;
|
|
162
|
-
type: string;
|
|
163
|
-
};
|
|
164
|
-
topic: any;
|
|
165
|
-
};
|
|
166
|
-
module_stat: {
|
|
167
|
-
comment: {
|
|
168
|
-
count: number;
|
|
169
|
-
};
|
|
170
|
-
forward: {
|
|
171
|
-
count: number;
|
|
172
|
-
};
|
|
173
|
-
like: {
|
|
174
|
-
count: number;
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
orig?: Dynamic;
|
|
179
|
-
type: string;
|
|
180
|
-
visible: boolean;
|
|
181
|
-
};
|
|
182
|
-
type Live = {
|
|
183
|
-
code: number;
|
|
184
|
-
message: string;
|
|
185
|
-
msg: string;
|
|
186
|
-
data: {
|
|
187
|
-
[key: string]: {
|
|
188
|
-
title: string;
|
|
189
|
-
room_id: number;
|
|
190
|
-
uid: number;
|
|
191
|
-
online: number;
|
|
192
|
-
live_time: number;
|
|
193
|
-
live_status: number;
|
|
194
|
-
short_id: number;
|
|
195
|
-
area: number;
|
|
196
|
-
area_name: string;
|
|
197
|
-
area_v2_id: number;
|
|
198
|
-
area_v2_name: string;
|
|
199
|
-
area_v2_parent_name: string;
|
|
200
|
-
area_v2_parent_id: number;
|
|
201
|
-
uname: string;
|
|
202
|
-
face: string;
|
|
203
|
-
tag_name: string;
|
|
204
|
-
tags: string;
|
|
205
|
-
cover_from_user: string;
|
|
206
|
-
keyframe: string;
|
|
207
|
-
lock_till: string;
|
|
208
|
-
hidden_till: string;
|
|
209
|
-
broadcast_type: number;
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
type LiveStatus = {
|
|
214
|
-
live: boolean;
|
|
215
|
-
roomId: string;
|
|
216
|
-
liveRoomInfo: any;
|
|
217
|
-
masterInfo: MasterInfo;
|
|
218
|
-
watchedNum: string;
|
|
219
|
-
liveStartTimeInit: boolean;
|
|
220
|
-
liveStartTime: string;
|
|
221
|
-
push: number;
|
|
222
|
-
};
|
|
223
|
-
type AllDynamicInfo = {
|
|
224
|
-
code: number;
|
|
225
|
-
message: string;
|
|
226
|
-
data: {
|
|
227
|
-
has_more: boolean;
|
|
228
|
-
items: Array<Dynamic>;
|
|
229
|
-
offset: string;
|
|
230
|
-
update_baseline: string;
|
|
231
|
-
update_num: number;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
declare enum PushType {
|
|
235
|
-
Live = 0,
|
|
236
|
-
Dynamic = 1,
|
|
237
|
-
StartBroadcasting = 2,
|
|
238
|
-
LiveGuardBuy = 3,
|
|
239
|
-
}
|
|
240
|
-
type Result = {
|
|
241
|
-
code: number;
|
|
242
|
-
msg?: string;
|
|
243
|
-
data?: any;
|
|
244
|
-
};
|
|
245
|
-
type CreateGroup = {
|
|
246
|
-
code: number;
|
|
247
|
-
message: string;
|
|
248
|
-
ttl: number;
|
|
249
|
-
data: {
|
|
250
|
-
tagid: number;
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
type GroupList = {
|
|
254
|
-
code: number;
|
|
255
|
-
message: string;
|
|
256
|
-
ttl: number;
|
|
257
|
-
data: Array<{
|
|
258
|
-
tagid: number;
|
|
259
|
-
name: string;
|
|
260
|
-
count: number;
|
|
261
|
-
tip: string;
|
|
262
|
-
}>;
|
|
263
|
-
};
|
|
264
|
-
//#endregion
|
|
265
|
-
export { AllDynamicInfo, Channel, ChannelArr, CreateGroup, Dynamic, GroupList, Live, LiveStatus, LiveType, LiveUsers, LiveUsersItem, MasterInfo, PushType, Result, RichTextNode, SubItem, SubManager, Target, TargetItem };
|
package/lib/page/0.js
DELETED
|
File without changes
|
package/lib/page/0.mjs
DELETED
|
File without changes
|
package/lib/type/index.d.mts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { AllDynamicInfo, Channel, ChannelArr, CreateGroup, Dynamic, GroupList, Live, LiveStatus, LiveType, LiveUsers, LiveUsersItem, MasterInfo, PushType, Result, RichTextNode, SubItem, SubManager, Target, TargetItem } from "../index-DeGUe4jM.mjs";
|
|
2
|
-
export { AllDynamicInfo, Channel, ChannelArr, CreateGroup, Dynamic, GroupList, Live, LiveStatus, LiveType, LiveUsers, LiveUsersItem, MasterInfo, PushType, Result, RichTextNode, SubItem, SubManager, Target, TargetItem };
|
package/lib/type/index.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { AllDynamicInfo, Channel, ChannelArr, CreateGroup, Dynamic, GroupList, Live, LiveStatus, LiveType, LiveUsers, LiveUsersItem, MasterInfo, PushType, Result, RichTextNode, SubItem, SubManager, Target, TargetItem } from "../index-MJKYbMf7.js";
|
|
2
|
-
export { AllDynamicInfo, Channel, ChannelArr, CreateGroup, Dynamic, GroupList, Live, LiveStatus, LiveType, LiveUsers, LiveUsersItem, MasterInfo, PushType, Result, RichTextNode, SubItem, SubManager, Target, TargetItem };
|
package/lib/type/index.js
DELETED
package/lib/type/index.mjs
DELETED
package/lib/type-C5ZxPrgY.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#region src/type/index.ts
|
|
2
|
-
let LiveType = /* @__PURE__ */ function(LiveType$1) {
|
|
3
|
-
LiveType$1[LiveType$1["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
|
|
4
|
-
LiveType$1[LiveType$1["StartBroadcasting"] = 1] = "StartBroadcasting";
|
|
5
|
-
LiveType$1[LiveType$1["LiveBroadcast"] = 2] = "LiveBroadcast";
|
|
6
|
-
LiveType$1[LiveType$1["StopBroadcast"] = 3] = "StopBroadcast";
|
|
7
|
-
LiveType$1[LiveType$1["FirstLiveBroadcast"] = 4] = "FirstLiveBroadcast";
|
|
8
|
-
return LiveType$1;
|
|
9
|
-
}({});
|
|
10
|
-
let PushType = /* @__PURE__ */ function(PushType$1) {
|
|
11
|
-
PushType$1[PushType$1["Live"] = 0] = "Live";
|
|
12
|
-
PushType$1[PushType$1["Dynamic"] = 1] = "Dynamic";
|
|
13
|
-
PushType$1[PushType$1["StartBroadcasting"] = 2] = "StartBroadcasting";
|
|
14
|
-
PushType$1[PushType$1["LiveGuardBuy"] = 3] = "LiveGuardBuy";
|
|
15
|
-
return PushType$1;
|
|
16
|
-
}({});
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { LiveType, PushType };
|
package/lib/type-WjCy4YMc.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/type/index.ts
|
|
3
|
-
let LiveType = /* @__PURE__ */ function(LiveType$1) {
|
|
4
|
-
LiveType$1[LiveType$1["NotLiveBroadcast"] = 0] = "NotLiveBroadcast";
|
|
5
|
-
LiveType$1[LiveType$1["StartBroadcasting"] = 1] = "StartBroadcasting";
|
|
6
|
-
LiveType$1[LiveType$1["LiveBroadcast"] = 2] = "LiveBroadcast";
|
|
7
|
-
LiveType$1[LiveType$1["StopBroadcast"] = 3] = "StopBroadcast";
|
|
8
|
-
LiveType$1[LiveType$1["FirstLiveBroadcast"] = 4] = "FirstLiveBroadcast";
|
|
9
|
-
return LiveType$1;
|
|
10
|
-
}({});
|
|
11
|
-
let PushType = /* @__PURE__ */ function(PushType$1) {
|
|
12
|
-
PushType$1[PushType$1["Live"] = 0] = "Live";
|
|
13
|
-
PushType$1[PushType$1["Dynamic"] = 1] = "Dynamic";
|
|
14
|
-
PushType$1[PushType$1["StartBroadcasting"] = 2] = "StartBroadcasting";
|
|
15
|
-
PushType$1[PushType$1["LiveGuardBuy"] = 3] = "LiveGuardBuy";
|
|
16
|
-
return PushType$1;
|
|
17
|
-
}({});
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
Object.defineProperty(exports, 'LiveType', {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return LiveType;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(exports, 'PushType', {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return PushType;
|
|
30
|
-
}
|
|
31
|
-
});
|
package/lib/utils/index.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/utils/index.d.ts
|
|
2
|
-
interface RetryOptions {
|
|
3
|
-
attempts: number;
|
|
4
|
-
onFailure?: (error: Error, attempts: number) => Promise<void> | void;
|
|
5
|
-
}
|
|
6
|
-
declare function Retry(options?: RetryOptions): MethodDecorator;
|
|
7
|
-
/**
|
|
8
|
-
* 高阶函数:为函数添加锁机制
|
|
9
|
-
* @param {Function} fn - 需要包装的原始函数
|
|
10
|
-
* @returns {Function} 带锁功能的函数
|
|
11
|
-
*/
|
|
12
|
-
declare function withLock(fn: any): (...args: any[]) => void;
|
|
13
|
-
declare function withRetry<T>(fn: (...args: unknown[]) => T | Promise<T>, maxAttempts?: number, delayMs?: number): Promise<T>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { Retry, withLock, withRetry };
|
package/lib/utils/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/utils/index.d.ts
|
|
2
|
-
interface RetryOptions {
|
|
3
|
-
attempts: number;
|
|
4
|
-
onFailure?: (error: Error, attempts: number) => Promise<void> | void;
|
|
5
|
-
}
|
|
6
|
-
declare function Retry(options?: RetryOptions): MethodDecorator;
|
|
7
|
-
/**
|
|
8
|
-
* 高阶函数:为函数添加锁机制
|
|
9
|
-
* @param {Function} fn - 需要包装的原始函数
|
|
10
|
-
* @returns {Function} 带锁功能的函数
|
|
11
|
-
*/
|
|
12
|
-
declare function withLock(fn: any): (...args: any[]) => void;
|
|
13
|
-
declare function withRetry<T>(fn: (...args: unknown[]) => T | Promise<T>, maxAttempts?: number, delayMs?: number): Promise<T>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { Retry, withLock, withRetry };
|
package/lib/utils/index.js
DELETED
package/lib/utils/index.mjs
DELETED
package/lib/utils-BoaYrSvG.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/index.ts
|
|
3
|
-
function Retry(options = { attempts: 3 }) {
|
|
4
|
-
return (target, propertyKey, descriptor) => {
|
|
5
|
-
const originalMethod = descriptor.value;
|
|
6
|
-
descriptor.value = async function(...args) {
|
|
7
|
-
let lastError;
|
|
8
|
-
for (let i = 0; i < options.attempts; i++) try {
|
|
9
|
-
return await originalMethod.apply(this, args);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
lastError = error;
|
|
12
|
-
if (options.onFailure) await options.onFailure.call(this, lastError, i + 1);
|
|
13
|
-
}
|
|
14
|
-
throw lastError;
|
|
15
|
-
};
|
|
16
|
-
return descriptor;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 高阶函数:为函数添加锁机制
|
|
21
|
-
* @param {Function} fn - 需要包装的原始函数
|
|
22
|
-
* @returns {Function} 带锁功能的函数
|
|
23
|
-
*/
|
|
24
|
-
function withLock(fn) {
|
|
25
|
-
const isAsync = fn.constructor.name === "AsyncFunction";
|
|
26
|
-
let locked = false;
|
|
27
|
-
if (isAsync) return (...args) => {
|
|
28
|
-
if (locked) return;
|
|
29
|
-
locked = true;
|
|
30
|
-
Promise.resolve(fn(...args)).catch((err) => {
|
|
31
|
-
console.error("Execution error:", err);
|
|
32
|
-
throw err;
|
|
33
|
-
}).finally(() => {
|
|
34
|
-
locked = false;
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
return (...args) => {
|
|
38
|
-
if (locked) return;
|
|
39
|
-
locked = true;
|
|
40
|
-
try {
|
|
41
|
-
fn(...args);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
console.error("Execution error:", err);
|
|
44
|
-
throw err;
|
|
45
|
-
} finally {
|
|
46
|
-
locked = false;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
async function withRetry(fn, maxAttempts = 3, delayMs = 1e3) {
|
|
51
|
-
let attempt = 0;
|
|
52
|
-
while (attempt < maxAttempts) try {
|
|
53
|
-
return await fn();
|
|
54
|
-
} catch (error) {
|
|
55
|
-
attempt++;
|
|
56
|
-
if (attempt >= maxAttempts) throw error;
|
|
57
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
Object.defineProperty(exports, 'Retry', {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return Retry;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(exports, 'withLock', {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function () {
|
|
71
|
-
return withLock;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(exports, 'withRetry', {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
get: function () {
|
|
77
|
-
return withRetry;
|
|
78
|
-
}
|
|
79
|
-
});
|
package/lib/utils-C95cnBJG.mjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//#region src/utils/index.ts
|
|
2
|
-
function Retry(options = { attempts: 3 }) {
|
|
3
|
-
return (target, propertyKey, descriptor) => {
|
|
4
|
-
const originalMethod = descriptor.value;
|
|
5
|
-
descriptor.value = async function(...args) {
|
|
6
|
-
let lastError;
|
|
7
|
-
for (let i = 0; i < options.attempts; i++) try {
|
|
8
|
-
return await originalMethod.apply(this, args);
|
|
9
|
-
} catch (error) {
|
|
10
|
-
lastError = error;
|
|
11
|
-
if (options.onFailure) await options.onFailure.call(this, lastError, i + 1);
|
|
12
|
-
}
|
|
13
|
-
throw lastError;
|
|
14
|
-
};
|
|
15
|
-
return descriptor;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 高阶函数:为函数添加锁机制
|
|
20
|
-
* @param {Function} fn - 需要包装的原始函数
|
|
21
|
-
* @returns {Function} 带锁功能的函数
|
|
22
|
-
*/
|
|
23
|
-
function withLock(fn) {
|
|
24
|
-
const isAsync = fn.constructor.name === "AsyncFunction";
|
|
25
|
-
let locked = false;
|
|
26
|
-
if (isAsync) return (...args) => {
|
|
27
|
-
if (locked) return;
|
|
28
|
-
locked = true;
|
|
29
|
-
Promise.resolve(fn(...args)).catch((err) => {
|
|
30
|
-
console.error("Execution error:", err);
|
|
31
|
-
throw err;
|
|
32
|
-
}).finally(() => {
|
|
33
|
-
locked = false;
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
return (...args) => {
|
|
37
|
-
if (locked) return;
|
|
38
|
-
locked = true;
|
|
39
|
-
try {
|
|
40
|
-
fn(...args);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.error("Execution error:", err);
|
|
43
|
-
throw err;
|
|
44
|
-
} finally {
|
|
45
|
-
locked = false;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
async function withRetry(fn, maxAttempts = 3, delayMs = 1e3) {
|
|
50
|
-
let attempt = 0;
|
|
51
|
-
while (attempt < maxAttempts) try {
|
|
52
|
-
return await fn();
|
|
53
|
-
} catch (error) {
|
|
54
|
-
attempt++;
|
|
55
|
-
if (attempt >= maxAttempts) throw error;
|
|
56
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
export { Retry, withLock, withRetry };
|