@qcplay/cli 1.0.16 → 1.0.17
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/platform-publish.js +26 -6
- package/package.json +1 -1
package/lib/platform-publish.js
CHANGED
|
@@ -225,6 +225,9 @@ const BROWSER_PLATFORM_SPECS = {
|
|
|
225
225
|
collection: [
|
|
226
226
|
'input[placeholder*="搜索合集"]',
|
|
227
227
|
'input[placeholder*="合集"]',
|
|
228
|
+
'[role="dialog"] input:not([type="file"]):not([type="hidden"])',
|
|
229
|
+
'[class*="modal"] input:not([type="file"]):not([type="hidden"])',
|
|
230
|
+
'[class*="dialog"] input:not([type="file"]):not([type="hidden"])',
|
|
228
231
|
'[class*="collection"] input',
|
|
229
232
|
'[class*="album"] input'
|
|
230
233
|
],
|
|
@@ -242,6 +245,10 @@ function normalizeText(value) {
|
|
|
242
245
|
return String(value ?? "").trim();
|
|
243
246
|
}
|
|
244
247
|
|
|
248
|
+
function escapeRegExp(value) {
|
|
249
|
+
return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
250
|
+
}
|
|
251
|
+
|
|
245
252
|
function normalizeKey(value) {
|
|
246
253
|
return normalizeText(value).toLowerCase().replace(/\s+/g, "");
|
|
247
254
|
}
|
|
@@ -6150,7 +6157,7 @@ async function publishXiaohongshu(page, entry, article, spec, options, promptUse
|
|
|
6150
6157
|
}
|
|
6151
6158
|
let imageInput = await firstExisting(page, spec.imageInputs);
|
|
6152
6159
|
if (!imageInput) {
|
|
6153
|
-
if (
|
|
6160
|
+
if (shouldWaitForXiaohongshuLogin(options)) {
|
|
6154
6161
|
await openPlatformLogin(page, entry, spec);
|
|
6155
6162
|
options.onProgress?.("小红书尚未登录,请在已打开的浏览器中扫码;登录完成后将自动继续上传图片");
|
|
6156
6163
|
imageInput = await waitForXiaohongshuUploadInput(page, spec, 600000);
|
|
@@ -6187,13 +6194,22 @@ async function publishXiaohongshu(page, entry, article, spec, options, promptUse
|
|
|
6187
6194
|
await fillLocator(titleInput, article.title);
|
|
6188
6195
|
await fillLocator(bodyInput, body);
|
|
6189
6196
|
if (publishing.collection) {
|
|
6190
|
-
const collectionTrigger =
|
|
6197
|
+
const collectionTrigger =
|
|
6198
|
+
(await waitForVisibleButton(page, [/添加(?:到)?合集/, /选择合集/, /加入合集/, /^合集$/], 3000)) ||
|
|
6199
|
+
(await waitForVisibleTextAcrossFrames(page, /添加(?:到)?合集|选择合集|加入合集|^合集$/, 3000, false));
|
|
6191
6200
|
if (!collectionTrigger) throw new Error("小红书页面未找到“添加合集”控件");
|
|
6192
6201
|
await collectionTrigger.click();
|
|
6193
6202
|
const collectionInput = await waitForVisible(page, spec.collection, 5000);
|
|
6194
|
-
if (
|
|
6195
|
-
|
|
6196
|
-
|
|
6203
|
+
if (collectionInput) {
|
|
6204
|
+
await fillLocator(collectionInput, publishing.collection);
|
|
6205
|
+
if (typeof collectionInput.press === "function") {
|
|
6206
|
+
await collectionInput.press("Enter").catch(() => {});
|
|
6207
|
+
}
|
|
6208
|
+
}
|
|
6209
|
+
await page.waitForTimeout(500);
|
|
6210
|
+
const collectionOption =
|
|
6211
|
+
(await waitForVisibleButton(page, [new RegExp(`^${escapeRegExp(publishing.collection)}$`)], 8000)) ||
|
|
6212
|
+
(await waitForVisibleTextAcrossFrames(page, publishing.collection, 8000));
|
|
6197
6213
|
if (!collectionOption) throw new Error(`小红书未找到精确合集: ${publishing.collection}`);
|
|
6198
6214
|
await collectionOption.click();
|
|
6199
6215
|
}
|
|
@@ -6206,7 +6222,7 @@ async function publishXiaohongshu(page, entry, article, spec, options, promptUse
|
|
|
6206
6222
|
options.onProgress?.("小红书待发布内容已准备完成,请在浏览器中核对后手动点击“发布”;程序将等待并验证发布结果");
|
|
6207
6223
|
return waitForManualXiaohongshuSubmission(page, 600000);
|
|
6208
6224
|
}
|
|
6209
|
-
await reviewPreparedDraft(page, entry,
|
|
6225
|
+
await reviewPreparedDraft(page, entry, options);
|
|
6210
6226
|
const initialUrl = page.url();
|
|
6211
6227
|
const mutationPromise =
|
|
6212
6228
|
typeof page.waitForResponse === "function"
|
|
@@ -6223,6 +6239,10 @@ function isInteractiveTerminal(streams = {}) {
|
|
|
6223
6239
|
return Boolean(input.isTTY && output.isTTY);
|
|
6224
6240
|
}
|
|
6225
6241
|
|
|
6242
|
+
export function shouldWaitForXiaohongshuLogin(options = {}) {
|
|
6243
|
+
return !isInteractiveTerminal(options.streams);
|
|
6244
|
+
}
|
|
6245
|
+
|
|
6226
6246
|
async function waitForXiaohongshuUploadInput(page, spec, timeoutMs) {
|
|
6227
6247
|
const deadline = Date.now() + timeoutMs;
|
|
6228
6248
|
do {
|