@koishi-ce/plugin-market 1.0.9 → 1.0.10
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/dist/index.js +1 -1
- package/dist/style.css +1 -1
- package/lib/index.d.ts +8 -1
- package/lib/index.mjs +4 -1
- package/package.json +3 -3
- package/src/__tests__/index.test.ts +580 -281
- package/src/browser/index.ts +6 -1
- package/src/browser/market.ts +6 -2
- package/src/node/deps.ts +7 -2
- package/src/node/index.ts +74 -22
- package/src/node/installer.ts +120 -51
- package/src/node/market.ts +42 -21
- package/src/node/proc.ts +8 -2
- package/src/shared/index.ts +27 -12
package/src/shared/index.ts
CHANGED
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
Logger,
|
|
11
11
|
Time,
|
|
12
12
|
} from "@koishi-ce/koishi";
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
SearchObject,
|
|
15
|
+
SearchResult,
|
|
16
|
+
} from "@koishi-ce/registry";
|
|
14
17
|
|
|
15
18
|
declare module "@koishi-ce/console" {
|
|
16
19
|
interface Events {
|
|
@@ -27,21 +30,31 @@ declare module "@koishi-ce/console" {
|
|
|
27
30
|
const logger = new Logger("market");
|
|
28
31
|
|
|
29
32
|
export abstract class MarketProvider extends DataService<MarketProvider.Payload> {
|
|
30
|
-
private _task: Promise<SearchResult | undefined> | null =
|
|
33
|
+
private _task: Promise<SearchResult | undefined> | null =
|
|
34
|
+
null;
|
|
31
35
|
private _timestamp = 0;
|
|
32
36
|
protected _error: unknown;
|
|
33
37
|
|
|
34
38
|
constructor(ctx: Context) {
|
|
35
39
|
super(ctx, "market", { authority: 4 });
|
|
36
40
|
|
|
37
|
-
ctx.console.addListener(
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
ctx.console.addListener(
|
|
42
|
+
"market/refresh",
|
|
43
|
+
() => this.start(true),
|
|
44
|
+
{
|
|
45
|
+
authority: 4,
|
|
46
|
+
},
|
|
47
|
+
);
|
|
40
48
|
|
|
41
49
|
ctx.on("console/connection", async (client) => {
|
|
42
50
|
if (!ctx.console.clients[client.id]) return;
|
|
43
|
-
if (Date.now() - this._timestamp <= Time.hour * 12)
|
|
44
|
-
|
|
51
|
+
if (Date.now() - this._timestamp <= Time.hour * 12)
|
|
52
|
+
return;
|
|
53
|
+
if (
|
|
54
|
+
await this.ctx.serial("console/intercept", client, {
|
|
55
|
+
authority: 4,
|
|
56
|
+
})
|
|
57
|
+
)
|
|
45
58
|
return;
|
|
46
59
|
this.start();
|
|
47
60
|
});
|
|
@@ -57,11 +70,13 @@ export abstract class MarketProvider extends DataService<MarketProvider.Payload>
|
|
|
57
70
|
abstract collect(): Promise<SearchResult | undefined>;
|
|
58
71
|
|
|
59
72
|
async prepare(): Promise<SearchResult | undefined> {
|
|
60
|
-
return (this._task ||= this.collect().catch(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
return (this._task ||= this.collect().catch(
|
|
74
|
+
(error: unknown) => {
|
|
75
|
+
logger.warn(error);
|
|
76
|
+
this._error = error;
|
|
77
|
+
return undefined;
|
|
78
|
+
},
|
|
79
|
+
));
|
|
65
80
|
}
|
|
66
81
|
}
|
|
67
82
|
|