@cloud411716/fancy-webnovel 1.0.41 → 1.0.43

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.
@@ -12,6 +12,9 @@ import { initProject } from './init-project.js';
12
12
 
13
13
  // inject is declared in the root index.js; only apply() is imported by index.js
14
14
 
15
+ /** UserQuestionError codes that indicate user cancellation */
16
+ const USER_CANCEL_CODES = new Set(['ASK_CANCELLED', 'ASK_ABORTED']);
17
+
15
18
  function isValidPath(p) {
16
19
  return (
17
20
  !p.includes('..') &&
@@ -77,11 +80,19 @@ export function apply(ctx) {
77
80
  let projectRoot = rawInput;
78
81
 
79
82
  if (!projectRoot) {
80
- const result = await ctx.userQuestions.ask({
81
- questions: [bootstrap.askPath()],
82
- agent: invocation.agent,
83
- signal,
84
- });
83
+ let result;
84
+ try {
85
+ result = await ctx.userQuestions.ask({
86
+ questions: [bootstrap.askPath()],
87
+ agent: invocation.agent,
88
+ signal,
89
+ });
90
+ } catch (err) {
91
+ if (err?.code && USER_CANCEL_CODES.has(err.code)) {
92
+ return notify(session, 'error', bootstrap.notify({ type: 'cancelled' }));
93
+ }
94
+ throw err;
95
+ }
85
96
  projectRoot = result.answers[0]?.custom?.trim() ?? '';
86
97
  }
87
98
 
@@ -103,17 +114,25 @@ export function apply(ctx) {
103
114
  }
104
115
 
105
116
  // ---------- confirm ----------
106
- const confirm = await ctx.userQuestions.ask({
107
- questions: [{
108
- id: 'confirm',
109
- question: bootstrap.notify({ type: 'confirm', projectRoot }),
110
- detail: projectRoot,
111
- hideCustomInput: true,
112
- options: bootstrap.confirmOptions(),
113
- }],
114
- agent: invocation.agent,
115
- signal,
116
- });
117
+ let confirm;
118
+ try {
119
+ confirm = await ctx.userQuestions.ask({
120
+ questions: [{
121
+ id: 'confirm',
122
+ question: bootstrap.notify({ type: 'confirm', projectRoot }),
123
+ detail: projectRoot,
124
+ hideCustomInput: true,
125
+ options: bootstrap.confirmOptions(),
126
+ }],
127
+ agent: invocation.agent,
128
+ signal,
129
+ });
130
+ } catch (err) {
131
+ if (err?.code && USER_CANCEL_CODES.has(err.code)) {
132
+ return notify(session, 'error', bootstrap.notify({ type: 'cancelled' }));
133
+ }
134
+ throw err;
135
+ }
117
136
  const ans = confirm.answers[0];
118
137
  const chosen = ans?.selected?.[0] ?? ans?.custom;
119
138
  if (chosen !== '确认创建') {
@@ -14,6 +14,9 @@ import * as fanqie from './platforms/fanqie.js';
14
14
  import * as jinjiang from './platforms/jinjiang.js';
15
15
  import * as qimao from './platforms/qimao.js';
16
16
 
17
+ /** UserQuestionError codes that indicate user cancellation */
18
+ const USER_CANCEL_CODES = new Set(['ASK_CANCELLED', 'ASK_ABORTED']);
19
+
17
20
  // inject is declared in the root index.js; only apply() is imported by index.js
18
21
 
19
22
  const PLATFORM_TABLE = [
@@ -133,15 +136,25 @@ export function apply(ctx) {
133
136
  }
134
137
 
135
138
  // ---------- platform selection ----------
136
- const platformResult = await ctx.userQuestions.ask({
137
- questions: [{
138
- id: 'platform',
139
- ...scan.askPlatform(),
140
- question: `${scan.platformList()}\n\n请选择要扫的平台(输入编号 1-4):`,
141
- }],
142
- agent: invocation.agent,
143
- signal,
144
- });
139
+ let platformResult;
140
+ try {
141
+ platformResult = await ctx.userQuestions.ask({
142
+ questions: [{
143
+ id: 'platform',
144
+ ...scan.askPlatform(),
145
+ question: `${scan.platformList()}\n\n请选择要扫的平台(输入编号 1-4):`,
146
+ }],
147
+ agent: invocation.agent,
148
+ signal,
149
+ });
150
+ } catch (err) {
151
+ // Handle user cancellation (ASK_CANCELLED, ASK_ABORTED, or any cancellation)
152
+ if (err?.code && USER_CANCEL_CODES.has(err.code)) {
153
+ return notify(session, 'error', scan.notify({ type: 'cancelled' }));
154
+ }
155
+ // Re-throw unexpected errors
156
+ throw err;
157
+ }
145
158
  const answer = platformResult.answers[0]?.custom?.trim();
146
159
  if (!answer) {
147
160
  return notify(session, 'error', scan.notify({ type: 'cancelled' }));
@@ -154,11 +167,19 @@ export function apply(ctx) {
154
167
  const platform = row[1];
155
168
 
156
169
  // ---------- rank selection (multi-select) ----------
157
- const rankResult = await ctx.userQuestions.ask({
158
- questions: [scan.askRankList(platform)],
159
- agent: invocation.agent,
160
- signal,
161
- });
170
+ let rankResult;
171
+ try {
172
+ rankResult = await ctx.userQuestions.ask({
173
+ questions: [scan.askRankList(platform)],
174
+ agent: invocation.agent,
175
+ signal,
176
+ });
177
+ } catch (err) {
178
+ if (err?.code && USER_CANCEL_CODES.has(err.code)) {
179
+ return notify(session, 'error', scan.notify({ type: 'cancelled' }));
180
+ }
181
+ throw err;
182
+ }
162
183
  const selected = rankResult.answers[0]?.selected ?? [];
163
184
  const custom = rankResult.answers[0]?.custom?.trim();
164
185
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {