@lightcone-ai/daemon 0.15.10 → 0.15.11
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,7 +79,7 @@ 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');
|
|
@@ -155,13 +154,20 @@ export class KuaishouAdapter {
|
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
async _uploadFiles(filePaths) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
// Wait up to 10s for the file input to appear (may be hidden/dynamically rendered)
|
|
158
|
+
const deadline = Date.now() + 10000;
|
|
159
|
+
let objectId = null;
|
|
160
|
+
while (Date.now() < deadline) {
|
|
161
|
+
const result = await this._cdp.send('Runtime.evaluate', {
|
|
162
|
+
expression: `document.querySelector('input[type="file"]')`,
|
|
163
|
+
returnByValue: false,
|
|
164
|
+
});
|
|
165
|
+
if (result.result?.objectId) { objectId = result.result.objectId; break; }
|
|
166
|
+
await sleep(500);
|
|
167
|
+
}
|
|
168
|
+
if (!objectId) throw new Error('No file input found on page after 10s');
|
|
163
169
|
await this._cdp.send('DOM.setFileInputFiles', {
|
|
164
|
-
objectId
|
|
170
|
+
objectId,
|
|
165
171
|
files: filePaths,
|
|
166
172
|
});
|
|
167
173
|
await sleep(500);
|