@lightcone-ai/daemon 0.15.10 → 0.15.12
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.
|
@@ -34,13 +34,12 @@ export class KuaishouAdapter {
|
|
|
34
34
|
|
|
35
35
|
async checkLoginStatus() {
|
|
36
36
|
const profileDir = process.env.KUAISHOU_PROFILE_DIR ?? '(not set)';
|
|
37
|
-
|
|
38
|
-
await sleep(4000);
|
|
39
|
-
const urlResult = await this._cdp.send('Runtime.evaluate', { expression: 'window.location.href', returnByValue: true });
|
|
40
|
-
const url = urlResult.result?.value ?? '';
|
|
37
|
+
// Check cookies directly without navigating — avoids leaving the current page
|
|
41
38
|
const result = await this._cdp.send('Network.getAllCookies', {});
|
|
42
39
|
const cookies = result.cookies ?? [];
|
|
43
40
|
const loggedIn = cookies.some(c => (c.name === 'userId' || c.name === 'passToken') && c.value?.length > 0);
|
|
41
|
+
const urlResult = await this._cdp.send('Runtime.evaluate', { expression: 'window.location.href', returnByValue: true });
|
|
42
|
+
const url = urlResult.result?.value ?? '';
|
|
44
43
|
console.error(`[KuaishouAdapter] checkLoginStatus: loggedIn=${loggedIn} url=${url}`);
|
|
45
44
|
return { loggedIn, url, profileDir, userId: null, nickname: null };
|
|
46
45
|
}
|
|
@@ -51,7 +50,7 @@ export class KuaishouAdapter {
|
|
|
51
50
|
await cdp.send('Page.navigate', { url: 'https://cp.kuaishou.com/article/publish/image' });
|
|
52
51
|
await this._waitForSelector('input[type="file"], [class*="upload"]', 12000);
|
|
53
52
|
|
|
54
|
-
const loggedIn = await this.checkLoginStatus();
|
|
53
|
+
const { loggedIn } = await this.checkLoginStatus();
|
|
55
54
|
if (!loggedIn) throw new Error('LOGIN_EXPIRED: 快手登录已过期,请重新扫码连接');
|
|
56
55
|
|
|
57
56
|
if (images.length > 0) {
|
|
@@ -80,11 +79,12 @@ export class KuaishouAdapter {
|
|
|
80
79
|
await cdp.send('Page.navigate', { url: 'https://cp.kuaishou.com/article/publish/video' });
|
|
81
80
|
await this._waitForSelector('input[type="file"], [class*="upload"]', 12000);
|
|
82
81
|
|
|
83
|
-
const loggedIn = await this.checkLoginStatus();
|
|
82
|
+
const { loggedIn } = await this.checkLoginStatus();
|
|
84
83
|
if (!loggedIn) throw new Error('LOGIN_EXPIRED: 快手登录已过期,请重新扫码连接');
|
|
85
84
|
|
|
86
85
|
await this._uploadFiles([video], 'video');
|
|
87
|
-
|
|
86
|
+
// Wait for upload to complete: title field appears only after upload finishes
|
|
87
|
+
await this._waitForSelector('[placeholder*="标题"]', 120000);
|
|
88
88
|
|
|
89
89
|
if (title) {
|
|
90
90
|
await this._fillField('[placeholder*="标题"]', title);
|
|
@@ -155,13 +155,20 @@ export class KuaishouAdapter {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
async _uploadFiles(filePaths) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
// Wait up to 10s for the file input to appear (may be hidden/dynamically rendered)
|
|
159
|
+
const deadline = Date.now() + 10000;
|
|
160
|
+
let objectId = null;
|
|
161
|
+
while (Date.now() < deadline) {
|
|
162
|
+
const result = await this._cdp.send('Runtime.evaluate', {
|
|
163
|
+
expression: `document.querySelector('input[type="file"]')`,
|
|
164
|
+
returnByValue: false,
|
|
165
|
+
});
|
|
166
|
+
if (result.result?.objectId) { objectId = result.result.objectId; break; }
|
|
167
|
+
await sleep(500);
|
|
168
|
+
}
|
|
169
|
+
if (!objectId) throw new Error('No file input found on page after 10s');
|
|
163
170
|
await this._cdp.send('DOM.setFileInputFiles', {
|
|
164
|
-
objectId
|
|
171
|
+
objectId,
|
|
165
172
|
files: filePaths,
|
|
166
173
|
});
|
|
167
174
|
await sleep(500);
|