@zhin.js/plugin-rss 1.1.16 → 1.1.18
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/runtime.d.ts +2 -1
- package/lib/runtime.d.ts.map +1 -1
- package/lib/runtime.js +3 -2
- package/lib/runtime.js.map +1 -1
- package/package.json +12 -13
- package/pages/index/index.js +6 -7
- package/pages/index/index.ts +6 -7
- package/plugin.js +63 -38
- package/src/runtime.ts +3 -2
package/lib/runtime.d.ts
CHANGED
|
@@ -20,5 +20,6 @@ export interface RssRuntime {
|
|
|
20
20
|
readonly config: Readonly<RssConfig>;
|
|
21
21
|
readonly outbound: RssOutboundPush | null;
|
|
22
22
|
}
|
|
23
|
-
export declare const
|
|
23
|
+
export declare const rssRuntimeStore: import("zhin.js").PluginStore<RssRuntime, unknown>;
|
|
24
|
+
export declare const rssRuntimeToken: import("zhin.js").PluginStore<RssRuntime, unknown>;
|
|
24
25
|
//# sourceMappingURL=runtime.d.ts.map
|
package/lib/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE;IACpC,qGAAqG;IACrG,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAA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AS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEpB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,eAAe,oDAG3B,CAAC;AACF,eAAO,MAAM,eAAe,oDAAkB,CAAC"}
|
package/lib/runtime.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const
|
|
1
|
+
import { definePluginStore } from 'zhin.js';
|
|
2
|
+
export const rssRuntimeStore = definePluginStore('zhin.rss.runtime', 'Owner-scoped RSS runtime');
|
|
3
|
+
export const rssRuntimeToken = rssRuntimeStore;
|
|
3
4
|
//# sourceMappingURL=runtime.js.map
|
package/lib/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAwB5C,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAC9C,kBAAkB,EAClB,0BAA0B,CAC3B,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-rss",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"description": "RSS/Atom feed subscription plugin for Zhin.js (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -42,26 +42,25 @@
|
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"rss-parser": "^3.13.0",
|
|
45
|
-
"@zhin.js/console-contract": "1.1.
|
|
46
|
-
"@zhin.js/
|
|
47
|
-
"@zhin.js/
|
|
48
|
-
"@zhin.js/tool": "1.1.
|
|
49
|
-
"@zhin.js/
|
|
50
|
-
"@zhin.js/skill": "1.1.14"
|
|
45
|
+
"@zhin.js/console-contract": "1.1.5",
|
|
46
|
+
"@zhin.js/im-contract": "1.1.13",
|
|
47
|
+
"@zhin.js/page": "1.1.17",
|
|
48
|
+
"@zhin.js/tool": "1.1.18",
|
|
49
|
+
"@zhin.js/skill": "1.1.16"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"typescript": "^6.0.3",
|
|
54
53
|
"vitest": "^4.1.10",
|
|
55
54
|
"zod": "^4.4.3",
|
|
56
|
-
"zhin.js": "1.1.
|
|
55
|
+
"zhin.js": "1.1.24"
|
|
57
56
|
},
|
|
58
57
|
"peerDependencies": {
|
|
59
58
|
"zod": "^4.0.0",
|
|
60
|
-
"@zhin.js/command": "^1.1.
|
|
61
|
-
"@zhin.js/
|
|
62
|
-
"zhin.js": "^1.1.
|
|
63
|
-
"@zhin.js/tool": "^1.1.
|
|
64
|
-
"
|
|
59
|
+
"@zhin.js/command": "^1.1.17",
|
|
60
|
+
"@zhin.js/page": "^1.1.17",
|
|
61
|
+
"@zhin.js/skill": "^1.1.16",
|
|
62
|
+
"@zhin.js/tool": "^1.1.18",
|
|
63
|
+
"zhin.js": "^1.1.24"
|
|
65
64
|
},
|
|
66
65
|
"peerDependenciesMeta": {
|
|
67
66
|
"@zhin.js/command": {
|
package/pages/index/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import { definePage } from '@zhin.js/console-contract';
|
|
3
|
-
import { createDeclarativePage } from '@zhin.js/client';
|
|
2
|
+
import { definePage, createDeclarativePage } from '@zhin.js/console-contract';
|
|
4
3
|
export const meta = definePage({
|
|
5
4
|
title: 'RSS 订阅',
|
|
6
5
|
titleI18n: { en: 'RSS Subscriptions' },
|
|
@@ -60,11 +59,11 @@ export default createDeclarativePage({
|
|
|
60
59
|
{
|
|
61
60
|
id: 'config',
|
|
62
61
|
title: { zh: '配置详情', en: 'Configuration Details' },
|
|
63
|
-
entries:
|
|
64
|
-
pollCron:
|
|
65
|
-
maxItemsPerPoll:
|
|
66
|
-
fetchTimeoutMs:
|
|
67
|
-
|
|
62
|
+
entries: [
|
|
63
|
+
{ label: 'pollCron', dataKey: 'pollCron' },
|
|
64
|
+
{ label: 'maxItemsPerPoll', dataKey: 'maxItemsPerPoll' },
|
|
65
|
+
{ label: 'fetchTimeoutMs', value: { $format: '{0} ms', args: ['fetchTimeoutMs'] } },
|
|
66
|
+
],
|
|
68
67
|
},
|
|
69
68
|
],
|
|
70
69
|
});
|
package/pages/index/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { definePage } from '@zhin.js/console-contract';
|
|
2
|
-
import { createDeclarativePage } from '@zhin.js/client';
|
|
1
|
+
import { definePage, createDeclarativePage } from '@zhin.js/console-contract';
|
|
3
2
|
|
|
4
3
|
export interface RssSubscriptionItem {
|
|
5
4
|
readonly id: string;
|
|
@@ -82,11 +81,11 @@ export default createDeclarativePage<RssConsoleStatus>({
|
|
|
82
81
|
{
|
|
83
82
|
id: 'config',
|
|
84
83
|
title: { zh: '配置详情', en: 'Configuration Details' },
|
|
85
|
-
entries:
|
|
86
|
-
pollCron:
|
|
87
|
-
maxItemsPerPoll:
|
|
88
|
-
fetchTimeoutMs:
|
|
89
|
-
|
|
84
|
+
entries: [
|
|
85
|
+
{ label: 'pollCron', dataKey: 'pollCron' },
|
|
86
|
+
{ label: 'maxItemsPerPoll', dataKey: 'maxItemsPerPoll' },
|
|
87
|
+
{ label: 'fetchTimeoutMs', value: { $format: '{0} ms', args: ['fetchTimeoutMs'] } },
|
|
88
|
+
],
|
|
90
89
|
},
|
|
91
90
|
],
|
|
92
91
|
});
|
package/plugin.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import { DataMigrationError,
|
|
2
|
+
import { DataMigrationError, TargetMigrationScopes } from 'zhin.js/plugin-runtime';
|
|
3
3
|
import { createSubscriptionTargetMigration, subscriptionMigrationScope } from "./lib/target-migration.js";
|
|
4
4
|
import { projectLocaleToken, resolveLocale } from 'zhin.js/i18n';
|
|
5
|
-
import { definePlugin, logger, databaseHostToken, outboundHostToken, pluginConsoleRpcToken, scheduleHostToken, } from 'zhin.js';
|
|
5
|
+
import { definePlugin, definePluginCapabilityGraph, logger, databaseHostToken, outboundHostToken, pluginConsoleRpcToken, pluginDataMigrationProviderToken, pluginTaskProviderToken, scheduleHostToken, } from 'zhin.js';
|
|
6
6
|
import { createAdministratorRssState } from "./lib/storage.js";
|
|
7
7
|
import { AdministratorRssTasks } from "./lib/admin-tasks.js";
|
|
8
8
|
import { createRssConsoleRpc } from "./lib/console.js";
|
|
9
9
|
import { resolveRssConfig } from "./lib/feed.js";
|
|
10
10
|
import { createInMemoryRssDb, RSS_SEEN_TABLE, RSS_SUBS_TABLE, } from "./lib/db-store.js";
|
|
11
11
|
import { cleanOldSeen, pollAllFeeds } from "./lib/poll.js";
|
|
12
|
-
import {
|
|
12
|
+
import { rssRuntimeStore } from "./lib/runtime.js";
|
|
13
13
|
function defineRssTables(db) {
|
|
14
14
|
db.define(RSS_SUBS_TABLE, {
|
|
15
15
|
url: { type: 'text', nullable: false },
|
|
@@ -43,6 +43,21 @@ export default definePlugin({
|
|
|
43
43
|
metadata: {
|
|
44
44
|
displayName: 'RSS',
|
|
45
45
|
},
|
|
46
|
+
capabilityGraph: definePluginCapabilityGraph({
|
|
47
|
+
provides: [
|
|
48
|
+
rssRuntimeStore,
|
|
49
|
+
pluginConsoleRpcToken,
|
|
50
|
+
pluginDataMigrationProviderToken,
|
|
51
|
+
pluginTaskProviderToken,
|
|
52
|
+
],
|
|
53
|
+
injects: [databaseHostToken, outboundHostToken, scheduleHostToken, projectLocaleToken],
|
|
54
|
+
features: {
|
|
55
|
+
commands: ['rss-add/[url]', 'rss-check/[[url]]', 'rss-list', 'rss-preview/[url]', 'rss-remove/[url]'],
|
|
56
|
+
skills: ['rss'],
|
|
57
|
+
tools: ['skill/rss/rss_list_subscriptions', 'skill/rss/rss_preview_feed'],
|
|
58
|
+
pages: ['index'],
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
46
61
|
setup(context) {
|
|
47
62
|
const config = resolveRssConfig(context.config.get());
|
|
48
63
|
const database = context.resources.has(databaseHostToken) ? context.resources.use(databaseHostToken) : undefined;
|
|
@@ -52,8 +67,9 @@ export default definePlugin({
|
|
|
52
67
|
return host;
|
|
53
68
|
})() : createInMemoryRssDb();
|
|
54
69
|
const migrationScopes = database ? new TargetMigrationScopes({ pending: scope => scope.startsWith('historical:') }) : undefined;
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
const dataMigration = database && migrationScopes
|
|
71
|
+
? createSubscriptionTargetMigration({ database, scopes: migrationScopes })
|
|
72
|
+
: undefined;
|
|
57
73
|
const outbound = context.resources.has(outboundHostToken) ? context.resources.use(outboundHostToken) : undefined;
|
|
58
74
|
let outboundPush = null;
|
|
59
75
|
if (outbound) {
|
|
@@ -69,15 +85,20 @@ export default definePlugin({
|
|
|
69
85
|
await run();
|
|
70
86
|
};
|
|
71
87
|
}
|
|
72
|
-
|
|
88
|
+
let projectLocale;
|
|
89
|
+
try {
|
|
90
|
+
projectLocale = context.resources.use(projectLocaleToken);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
projectLocale = undefined;
|
|
94
|
+
}
|
|
95
|
+
const runtime = rssRuntimeStore.provide(context, Object.freeze({
|
|
73
96
|
db,
|
|
74
97
|
migrationScopes,
|
|
75
|
-
locale: resolveLocale(
|
|
98
|
+
locale: resolveLocale(projectLocale),
|
|
76
99
|
config: Object.freeze({ ...config }),
|
|
77
100
|
outbound: outboundPush,
|
|
78
|
-
});
|
|
79
|
-
context.resources.provide(rssRuntimeToken, runtime);
|
|
80
|
-
context.resources.provide(pluginConsoleRpcToken, createRssConsoleRpc(runtime));
|
|
101
|
+
}));
|
|
81
102
|
// Keep optional in-memory/chat-only installations working. Administrator tasks
|
|
82
103
|
// must have the real durable state port, exact outbound and an active scheduler.
|
|
83
104
|
let administrator;
|
|
@@ -92,36 +113,40 @@ export default definePlugin({
|
|
|
92
113
|
catch { /* No persistent state port: no administrator provider. */ }
|
|
93
114
|
if (state) {
|
|
94
115
|
administrator = new AdministratorRssTasks(createAdministratorRssState(database), outbound, config, undefined, runtime.locale);
|
|
95
|
-
context.resources.provide(pluginTaskProviderToken, administrator);
|
|
96
116
|
context.lifecycle.add(() => administrator?.stop());
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
if (context.resources.has(scheduleHostToken)) {
|
|
120
|
+
const schedule = context.resources.use(scheduleHostToken);
|
|
121
|
+
const dispose = schedule.register({
|
|
122
|
+
id: 'rss/poll_feeds',
|
|
123
|
+
cron: config.pollCron,
|
|
124
|
+
description: 'Poll RSS subscriptions',
|
|
125
|
+
async execute() {
|
|
126
|
+
// Both pools share this existing registration. A slow chat feed does not
|
|
127
|
+
// prevent administrator polling, and neither pool shares the other's cursor.
|
|
128
|
+
const results = await Promise.allSettled([pollAllFeeds(runtime), administrator?.tick()]);
|
|
129
|
+
// Keep the schedule lease until both pools drain, even if one fails.
|
|
130
|
+
for (const result of results)
|
|
131
|
+
if (result.status === 'rejected')
|
|
132
|
+
throw result.reason;
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
const disposeClean = schedule.register({
|
|
136
|
+
id: 'rss/clean_old_seen',
|
|
137
|
+
cron: '0 0 4 * * *',
|
|
138
|
+
description: 'Clean seen records older than 7 days',
|
|
139
|
+
async execute() {
|
|
140
|
+
await cleanOldSeen(runtime);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
context.lifecycle.add(dispose);
|
|
144
|
+
context.lifecycle.add(disposeClean);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
consoleRpc: createRssConsoleRpc(runtime),
|
|
148
|
+
...(dataMigration ? { dataMigration } : {}),
|
|
149
|
+
...(administrator ? { tasks: administrator } : {}),
|
|
150
|
+
};
|
|
126
151
|
},
|
|
127
152
|
});
|
package/src/runtime.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DeliveryTarget, TargetMigrationScopes } from 'zhin.js/plugin-runtime';
|
|
2
2
|
import type { Locale } from 'zhin.js/i18n';
|
|
3
|
-
import {
|
|
3
|
+
import { definePluginStore } from 'zhin.js';
|
|
4
4
|
import type { RssConfig } from './feed.js';
|
|
5
5
|
import type { RssMemoryDb } from './memory-store.js';
|
|
6
6
|
import type { ChannelInfo } from './channel.js';
|
|
@@ -24,7 +24,8 @@ export interface RssRuntime {
|
|
|
24
24
|
readonly outbound: RssOutboundPush | null;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const
|
|
27
|
+
export const rssRuntimeStore = definePluginStore<RssRuntime>(
|
|
28
28
|
'zhin.rss.runtime',
|
|
29
29
|
'Owner-scoped RSS runtime',
|
|
30
30
|
);
|
|
31
|
+
export const rssRuntimeToken = rssRuntimeStore;
|