@lightcone-ai/daemon 0.9.28 → 0.9.29
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.
|
@@ -66,14 +66,13 @@ export class XhsAdapter {
|
|
|
66
66
|
await sleep(1000);
|
|
67
67
|
|
|
68
68
|
// Click publish button
|
|
69
|
-
await this._clickByText('发布');
|
|
70
|
-
|
|
69
|
+
const clicked = await this._clickByText('发布');
|
|
70
|
+
if (!clicked) throw new Error('PUBLISH_FAILED: 找不到发布按钮,页面结构可能已变化');
|
|
71
|
+
await sleep(5000);
|
|
71
72
|
|
|
72
|
-
// Check result
|
|
73
|
+
// Check result — must confirm URL changed or success element appeared
|
|
73
74
|
const currentUrl = await this._getUrl();
|
|
74
|
-
|
|
75
|
-
return { success: true, post_url: currentUrl };
|
|
76
|
-
}
|
|
75
|
+
const isSuccess = currentUrl.includes('success') || currentUrl.includes('works') || currentUrl.includes('note-manager');
|
|
77
76
|
|
|
78
77
|
// Try to grab post URL from page
|
|
79
78
|
const urlResult = await cdp.send('Runtime.evaluate', {
|
|
@@ -81,7 +80,19 @@ export class XhsAdapter {
|
|
|
81
80
|
returnByValue: true,
|
|
82
81
|
});
|
|
83
82
|
const postUrl = urlResult.result?.value || currentUrl;
|
|
84
|
-
|
|
83
|
+
|
|
84
|
+
if (!isSuccess && !urlResult.result?.value) {
|
|
85
|
+
// Check if still on publish page (means publish didn't go through)
|
|
86
|
+
if (currentUrl.includes('/publish/publish')) {
|
|
87
|
+
const errorText = await cdp.send('Runtime.evaluate', {
|
|
88
|
+
expression: `document.querySelector('[class*="error"], [class*="fail"], [class*="tips"]')?.innerText || ''`,
|
|
89
|
+
returnByValue: true,
|
|
90
|
+
});
|
|
91
|
+
throw new Error(`PUBLISH_FAILED: 发布后仍停留在发布页,可能未成功。页面提示:${errorText.result?.value || '无'}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { success: true, post_url: postUrl || currentUrl };
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
async publishShortVideo({ title, text, tags = [], video, cover }) {
|
|
@@ -186,7 +197,7 @@ export class XhsAdapter {
|
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
async _clickByText(text) {
|
|
189
|
-
await this._cdp.send('Runtime.evaluate', {
|
|
200
|
+
const result = await this._cdp.send('Runtime.evaluate', {
|
|
190
201
|
expression: `
|
|
191
202
|
(function() {
|
|
192
203
|
const els = [...document.querySelectorAll('button, [role="button"]')];
|
|
@@ -197,6 +208,7 @@ export class XhsAdapter {
|
|
|
197
208
|
`,
|
|
198
209
|
returnByValue: true,
|
|
199
210
|
});
|
|
211
|
+
return result.result?.value === true;
|
|
200
212
|
}
|
|
201
213
|
|
|
202
214
|
async _getUrl() {
|
|
@@ -111,7 +111,7 @@ async function _spawnChrome(profileDir, port) {
|
|
|
111
111
|
`--remote-debugging-port=${port}`,
|
|
112
112
|
'--no-sandbox',
|
|
113
113
|
'--disable-dev-shm-usage',
|
|
114
|
-
'--headless=
|
|
114
|
+
'--headless=false',
|
|
115
115
|
`--user-data-dir=${profileDir}`,
|
|
116
116
|
'--window-size=1280,900',
|
|
117
117
|
'--disable-blink-features=AutomationControlled',
|