@gobing-ai/knowledge-kit 0.1.25 → 0.1.28
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/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +10 -0
- package/dist/board/daily-voice/index.js +1327 -2168
- package/dist/board/itc/index.js +10 -0
- package/dist/index.js +6043 -4620
- package/package.json +1 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +4 -1
- package/plugins/ingestions/aihot-ingest/src/rss.ts +22 -11
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +423 -141
- package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +1 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +114 -82
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/cnblogs-pub/dist/index.js +114 -82
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/csdn-pub/dist/index.js +114 -82
- package/plugins/publishings/csdn-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/infoq-pub/dist/index.js +114 -82
- package/plugins/publishings/infoq-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/jike-pub/dist/index.js +114 -82
- package/plugins/publishings/jike-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/juejin-pub/dist/index.js +114 -82
- package/plugins/publishings/juejin-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/linkedin-pub/dist/index.js +165 -93
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +51 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +114 -82
- package/plugins/publishings/medium-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +305 -87
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +145 -5
- package/plugins/publishings/shipinhao-pub/src/cover-crop.ts +60 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +15 -2
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +15 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +22 -1
- package/plugins/publishings/sspai-pub/dist/index.js +114 -82
- package/plugins/publishings/sspai-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/substack-pub/dist/index.js +114 -82
- package/plugins/publishings/substack-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/surfdash-pub/dist/index.js +96 -20
- package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
- package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
- package/plugins/publishings/threads-pub/dist/index.js +119 -83
- package/plugins/publishings/threads-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/threads-pub/src/index.ts +10 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +149 -86
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +68 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +273 -91
- package/plugins/publishings/weibo-pub/dist/profile-check.js +178 -11
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +136 -10
- package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
- package/plugins/publishings/x-pub/dist/index.js +114 -82
- package/plugins/publishings/x-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xhs-pub/dist/index.js +114 -82
- package/plugins/publishings/xhs-pub/dist/profile-check.js +34 -3
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +114 -82
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +34 -3
|
@@ -20171,6 +20171,187 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
|
|
|
20171
20171
|
import { homedir } from "os";
|
|
20172
20172
|
import { join, resolve } from "path";
|
|
20173
20173
|
|
|
20174
|
+
// ../../packages/publish-harness/src/session-state.ts
|
|
20175
|
+
import { randomUUID } from "crypto";
|
|
20176
|
+
init_dist();
|
|
20177
|
+
|
|
20178
|
+
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20179
|
+
import {
|
|
20180
|
+
chmodSync,
|
|
20181
|
+
closeSync,
|
|
20182
|
+
copyFileSync,
|
|
20183
|
+
lstatSync,
|
|
20184
|
+
mkdirSync as mkdirSync2,
|
|
20185
|
+
openSync,
|
|
20186
|
+
readdirSync as readdirSync2,
|
|
20187
|
+
readlinkSync,
|
|
20188
|
+
realpathSync as realpathSync2,
|
|
20189
|
+
renameSync as renameSync2,
|
|
20190
|
+
rmdirSync,
|
|
20191
|
+
unlinkSync
|
|
20192
|
+
} from "fs";
|
|
20193
|
+
function lstat(path) {
|
|
20194
|
+
try {
|
|
20195
|
+
return lstatSync(path);
|
|
20196
|
+
} catch (error) {
|
|
20197
|
+
if (error.code === "ENOENT")
|
|
20198
|
+
return null;
|
|
20199
|
+
throw error;
|
|
20200
|
+
}
|
|
20201
|
+
}
|
|
20202
|
+
function realpath(path) {
|
|
20203
|
+
return realpathSync2(path);
|
|
20204
|
+
}
|
|
20205
|
+
function mkdirExclusive(path, mode = 448) {
|
|
20206
|
+
try {
|
|
20207
|
+
mkdirSync2(path, { mode });
|
|
20208
|
+
return true;
|
|
20209
|
+
} catch (error) {
|
|
20210
|
+
if (error.code === "EEXIST")
|
|
20211
|
+
return false;
|
|
20212
|
+
throw error;
|
|
20213
|
+
}
|
|
20214
|
+
}
|
|
20215
|
+
function rmdir(path) {
|
|
20216
|
+
try {
|
|
20217
|
+
rmdirSync(path);
|
|
20218
|
+
return true;
|
|
20219
|
+
} catch (error) {
|
|
20220
|
+
const code = error.code;
|
|
20221
|
+
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20222
|
+
return false;
|
|
20223
|
+
throw error;
|
|
20224
|
+
}
|
|
20225
|
+
}
|
|
20226
|
+
function readlink(path) {
|
|
20227
|
+
try {
|
|
20228
|
+
return readlinkSync(path);
|
|
20229
|
+
} catch {
|
|
20230
|
+
return null;
|
|
20231
|
+
}
|
|
20232
|
+
}
|
|
20233
|
+
function unlink(path) {
|
|
20234
|
+
try {
|
|
20235
|
+
unlinkSync(path);
|
|
20236
|
+
return true;
|
|
20237
|
+
} catch (error) {
|
|
20238
|
+
if (error.code === "ENOENT")
|
|
20239
|
+
return false;
|
|
20240
|
+
throw error;
|
|
20241
|
+
}
|
|
20242
|
+
}
|
|
20243
|
+
function rename(from, to) {
|
|
20244
|
+
try {
|
|
20245
|
+
renameSync2(from, to);
|
|
20246
|
+
return true;
|
|
20247
|
+
} catch (error) {
|
|
20248
|
+
if (error.code === "ENOENT")
|
|
20249
|
+
return false;
|
|
20250
|
+
throw error;
|
|
20251
|
+
}
|
|
20252
|
+
}
|
|
20253
|
+
function chmod(path, mode) {
|
|
20254
|
+
chmodSync(path, mode);
|
|
20255
|
+
}
|
|
20256
|
+
function createExclusiveFile(path) {
|
|
20257
|
+
closeSync(openSync(path, "wx", 384));
|
|
20258
|
+
}
|
|
20259
|
+
|
|
20260
|
+
// ../../packages/publish-harness/src/session-state.ts
|
|
20261
|
+
function channelStorageStatePath(profileDir) {
|
|
20262
|
+
return `${profileDir}/storage-state.json`;
|
|
20263
|
+
}
|
|
20264
|
+
var DEFAULT_CHANNEL_STATE_SETTLE_MS = 3000;
|
|
20265
|
+
async function readSavedState(profileDir) {
|
|
20266
|
+
const fs = createNodeFileSystem();
|
|
20267
|
+
const file = channelStorageStatePath(profileDir);
|
|
20268
|
+
try {
|
|
20269
|
+
if (!await fs.exists(file))
|
|
20270
|
+
return { corrupt: false };
|
|
20271
|
+
return { state: JSON.parse(await fs.readFile(file)), corrupt: false };
|
|
20272
|
+
} catch {
|
|
20273
|
+
return { corrupt: true };
|
|
20274
|
+
}
|
|
20275
|
+
}
|
|
20276
|
+
async function persistChannelSessionState(context, profileDir) {
|
|
20277
|
+
const target = channelStorageStatePath(profileDir);
|
|
20278
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
20279
|
+
const fs = createNodeFileSystem();
|
|
20280
|
+
let reserved = false;
|
|
20281
|
+
try {
|
|
20282
|
+
createExclusiveFile(temporary);
|
|
20283
|
+
reserved = true;
|
|
20284
|
+
await context.storageState({ path: temporary });
|
|
20285
|
+
chmod(temporary, 384);
|
|
20286
|
+
await fs.rename(temporary, target);
|
|
20287
|
+
} finally {
|
|
20288
|
+
if (reserved) {
|
|
20289
|
+
await Promise.resolve().then(() => fs.deleteFile(temporary)).catch(() => {
|
|
20290
|
+
return;
|
|
20291
|
+
});
|
|
20292
|
+
}
|
|
20293
|
+
}
|
|
20294
|
+
}
|
|
20295
|
+
async function restoreChannelSessionState(context, page, profileDir) {
|
|
20296
|
+
const { state, corrupt } = await readSavedState(profileDir);
|
|
20297
|
+
if (corrupt) {
|
|
20298
|
+
throw new Error(`the channel saved session state is unreadable (${channelStorageStatePath(profileDir)})`);
|
|
20299
|
+
}
|
|
20300
|
+
const saved = state?.cookies ?? [];
|
|
20301
|
+
if (saved.length === 0)
|
|
20302
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20303
|
+
if (typeof context.cookies !== "function" || typeof context.addCookies !== "function") {
|
|
20304
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20305
|
+
}
|
|
20306
|
+
const nowSeconds = Date.now() / 1000;
|
|
20307
|
+
const current = await context.cookies().catch(() => []);
|
|
20308
|
+
const alive = saved.filter((cookie) => cookie.expires === undefined || cookie.expires === -1 || cookie.expires > nowSeconds);
|
|
20309
|
+
const skippedExpired = saved.length - alive.length;
|
|
20310
|
+
const held = new Set(current.map((cookie) => `${cookie.domain}|${cookie.name}`));
|
|
20311
|
+
const shadowed = alive.filter((cookie) => held.has(`${cookie.domain}|${cookie.name}`)).length;
|
|
20312
|
+
const inject = alive.filter((cookie) => !held.has(`${cookie.domain}|${cookie.name}`));
|
|
20313
|
+
if (inject.length > 0)
|
|
20314
|
+
await context.addCookies(inject);
|
|
20315
|
+
if (page !== undefined) {
|
|
20316
|
+
for (const entry of state?.origins ?? []) {
|
|
20317
|
+
if (entry.origin === undefined || (entry.localStorage ?? []).length === 0)
|
|
20318
|
+
continue;
|
|
20319
|
+
await page.evaluate(({ origin, items }) => {
|
|
20320
|
+
const page = globalThis;
|
|
20321
|
+
if (page.location.origin !== origin)
|
|
20322
|
+
return;
|
|
20323
|
+
for (const item of items)
|
|
20324
|
+
page.localStorage.setItem(item.name, item.value);
|
|
20325
|
+
}, { origin: entry.origin, items: entry.localStorage ?? [] }).catch(() => {
|
|
20326
|
+
return;
|
|
20327
|
+
});
|
|
20328
|
+
}
|
|
20329
|
+
}
|
|
20330
|
+
return { restored: inject.length > 0, skippedExpired, shadowed };
|
|
20331
|
+
}
|
|
20332
|
+
function stateRestoringLauncher(base) {
|
|
20333
|
+
return {
|
|
20334
|
+
async launch(request) {
|
|
20335
|
+
const context = await base.launch(request);
|
|
20336
|
+
try {
|
|
20337
|
+
const pages = typeof context.pages === "function" ? context.pages() : [];
|
|
20338
|
+
const page = pages[0];
|
|
20339
|
+
const outcome = await restoreChannelSessionState(context, page, request.profileDir);
|
|
20340
|
+
if (outcome.skippedExpired > 0 || outcome.shadowed > 0) {
|
|
20341
|
+
echoError(`channel session: replayed ${outcome.restored ? "a" : "no"} saved session (${outcome.skippedExpired} expired, ${outcome.shadowed} shadowed by the profile)`);
|
|
20342
|
+
}
|
|
20343
|
+
} catch (error) {
|
|
20344
|
+
await Promise.resolve().then(() => context.close()).catch(() => {
|
|
20345
|
+
return;
|
|
20346
|
+
});
|
|
20347
|
+
throw error;
|
|
20348
|
+
}
|
|
20349
|
+
return context;
|
|
20350
|
+
}
|
|
20351
|
+
};
|
|
20352
|
+
}
|
|
20353
|
+
|
|
20354
|
+
// ../../packages/publish-harness/src/index.ts
|
|
20174
20355
|
class FakeTransportCore {
|
|
20175
20356
|
callLogs = [];
|
|
20176
20357
|
nextResult;
|
|
@@ -20455,85 +20636,6 @@ init_dist();
|
|
|
20455
20636
|
import { homedir as homedir4 } from "os";
|
|
20456
20637
|
import { isAbsolute, join as join4, relative, resolve as resolve4, sep } from "path";
|
|
20457
20638
|
|
|
20458
|
-
// ../../packages/publish-harness/src/bot-fs.ts
|
|
20459
|
-
import {
|
|
20460
|
-
chmodSync,
|
|
20461
|
-
closeSync,
|
|
20462
|
-
copyFileSync,
|
|
20463
|
-
lstatSync,
|
|
20464
|
-
mkdirSync as mkdirSync2,
|
|
20465
|
-
openSync,
|
|
20466
|
-
readdirSync as readdirSync2,
|
|
20467
|
-
readlinkSync,
|
|
20468
|
-
realpathSync as realpathSync2,
|
|
20469
|
-
renameSync as renameSync2,
|
|
20470
|
-
rmdirSync,
|
|
20471
|
-
unlinkSync
|
|
20472
|
-
} from "fs";
|
|
20473
|
-
function lstat(path) {
|
|
20474
|
-
try {
|
|
20475
|
-
return lstatSync(path);
|
|
20476
|
-
} catch (error) {
|
|
20477
|
-
if (error.code === "ENOENT")
|
|
20478
|
-
return null;
|
|
20479
|
-
throw error;
|
|
20480
|
-
}
|
|
20481
|
-
}
|
|
20482
|
-
function realpath(path) {
|
|
20483
|
-
return realpathSync2(path);
|
|
20484
|
-
}
|
|
20485
|
-
function mkdirExclusive(path, mode = 448) {
|
|
20486
|
-
try {
|
|
20487
|
-
mkdirSync2(path, { mode });
|
|
20488
|
-
return true;
|
|
20489
|
-
} catch (error) {
|
|
20490
|
-
if (error.code === "EEXIST")
|
|
20491
|
-
return false;
|
|
20492
|
-
throw error;
|
|
20493
|
-
}
|
|
20494
|
-
}
|
|
20495
|
-
function rmdir(path) {
|
|
20496
|
-
try {
|
|
20497
|
-
rmdirSync(path);
|
|
20498
|
-
return true;
|
|
20499
|
-
} catch (error) {
|
|
20500
|
-
const code = error.code;
|
|
20501
|
-
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
20502
|
-
return false;
|
|
20503
|
-
throw error;
|
|
20504
|
-
}
|
|
20505
|
-
}
|
|
20506
|
-
function readlink(path) {
|
|
20507
|
-
try {
|
|
20508
|
-
return readlinkSync(path);
|
|
20509
|
-
} catch {
|
|
20510
|
-
return null;
|
|
20511
|
-
}
|
|
20512
|
-
}
|
|
20513
|
-
function unlink(path) {
|
|
20514
|
-
try {
|
|
20515
|
-
unlinkSync(path);
|
|
20516
|
-
return true;
|
|
20517
|
-
} catch (error) {
|
|
20518
|
-
if (error.code === "ENOENT")
|
|
20519
|
-
return false;
|
|
20520
|
-
throw error;
|
|
20521
|
-
}
|
|
20522
|
-
}
|
|
20523
|
-
function rename(from, to) {
|
|
20524
|
-
try {
|
|
20525
|
-
renameSync2(from, to);
|
|
20526
|
-
return true;
|
|
20527
|
-
} catch (error) {
|
|
20528
|
-
if (error.code === "ENOENT")
|
|
20529
|
-
return false;
|
|
20530
|
-
throw error;
|
|
20531
|
-
}
|
|
20532
|
-
}
|
|
20533
|
-
function chmod(path, mode) {
|
|
20534
|
-
chmodSync(path, mode);
|
|
20535
|
-
}
|
|
20536
|
-
|
|
20537
20639
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
20538
20640
|
import { homedir as homedir2 } from "os";
|
|
20539
20641
|
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
@@ -20558,7 +20660,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20558
20660
|
const leaseDir = join3(leaseRoot, id);
|
|
20559
20661
|
await fileSystem.ensureDir(leaseRoot);
|
|
20560
20662
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20561
|
-
|
|
20663
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20664
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20665
|
+
}
|
|
20666
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20667
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20668
|
+
}
|
|
20562
20669
|
}
|
|
20563
20670
|
const token = randomBytes(16).toString("hex");
|
|
20564
20671
|
const owner = {
|
|
@@ -20674,9 +20781,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20674
20781
|
}
|
|
20675
20782
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20676
20783
|
}
|
|
20677
|
-
const
|
|
20784
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20785
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20678
20786
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20679
20787
|
}
|
|
20788
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20789
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20790
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20791
|
+
return false;
|
|
20792
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20793
|
+
return false;
|
|
20794
|
+
const target = staleLeaseDir(leaseDir);
|
|
20795
|
+
try {
|
|
20796
|
+
rename(leaseDir, target);
|
|
20797
|
+
} catch {
|
|
20798
|
+
return false;
|
|
20799
|
+
}
|
|
20800
|
+
const moved = await readOwner(fileSystem, target);
|
|
20801
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20802
|
+
try {
|
|
20803
|
+
rename(target, leaseDir);
|
|
20804
|
+
} catch {}
|
|
20805
|
+
return false;
|
|
20806
|
+
}
|
|
20807
|
+
return true;
|
|
20808
|
+
}
|
|
20809
|
+
function staleLeaseDir(leaseDir) {
|
|
20810
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20811
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20812
|
+
}
|
|
20680
20813
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20681
20814
|
try {
|
|
20682
20815
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20802,7 +20935,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20802
20935
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20803
20936
|
if (lstat(syncData) === null)
|
|
20804
20937
|
return false;
|
|
20805
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20938
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20806
20939
|
}
|
|
20807
20940
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20808
20941
|
return {
|
|
@@ -21033,6 +21166,7 @@ var TARGET = "weibo";
|
|
|
21033
21166
|
var WEIBO_HOME_URL = "https://weibo.com";
|
|
21034
21167
|
var WEIBO_ARTICLE_URL = "https://card.weibo.com/article/v3/editor";
|
|
21035
21168
|
var WEIBO_MOBILE_COMPOSE_URL = "https://m.weibo.cn/compose/";
|
|
21169
|
+
var MOBILE_COMPOSE_URL_RE = /^https:\/\/m\.weibo\.cn\//;
|
|
21036
21170
|
var LOGIN_URL_RE = /(passport\.weibo\.com|\/login)/;
|
|
21037
21171
|
var WEIBO_OPERATIONS = ["post", "article"];
|
|
21038
21172
|
var WEIBO_POST_SELECTORS = {
|
|
@@ -21106,19 +21240,56 @@ function resolveDriver(options) {
|
|
|
21106
21240
|
}
|
|
21107
21241
|
return { driver: "script" };
|
|
21108
21242
|
}
|
|
21109
|
-
|
|
21110
|
-
if (LOGIN_URL_RE.test(
|
|
21243
|
+
function weiboSurfaceReady(facts) {
|
|
21244
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21111
21245
|
return false;
|
|
21112
|
-
if (
|
|
21246
|
+
if (facts.composer && (facts.composerLabelled || MOBILE_COMPOSE_URL_RE.test(facts.url)))
|
|
21113
21247
|
return true;
|
|
21114
|
-
return
|
|
21248
|
+
return facts.articleTitle;
|
|
21249
|
+
}
|
|
21250
|
+
var isWeiboAuthenticated = async (page) => {
|
|
21251
|
+
const facts = { url: page.url(), composer: false, composerLabelled: false, articleTitle: false };
|
|
21252
|
+
if (LOGIN_URL_RE.test(facts.url))
|
|
21253
|
+
return false;
|
|
21254
|
+
if ((await trySelectors(page, WEIBO_POST_SELECTORS.composer, { visible: false })).found) {
|
|
21255
|
+
facts.composer = true;
|
|
21256
|
+
facts.composerLabelled = (await trySelectors(page, WEIBO_POST_SELECTORS.composer.filter((s) => s.includes("placeholder")), {
|
|
21257
|
+
visible: false
|
|
21258
|
+
})).found;
|
|
21259
|
+
if (weiboSurfaceReady(facts) && MOBILE_HOST_RE.test(facts.url))
|
|
21260
|
+
return weiboSessionCanWrite(page);
|
|
21261
|
+
if (weiboSurfaceReady(facts))
|
|
21262
|
+
return true;
|
|
21263
|
+
}
|
|
21264
|
+
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
21265
|
+
return weiboSurfaceReady(facts);
|
|
21115
21266
|
};
|
|
21267
|
+
var MOBILE_HOST_RE = /^https?:\/\/m\.weibo\.cn\//;
|
|
21268
|
+
async function weiboSessionCanWrite(page) {
|
|
21269
|
+
const canWrite = await page.evaluate(async () => {
|
|
21270
|
+
const response = await fetch("https://m.weibo.cn/api/config", { credentials: "include" });
|
|
21271
|
+
const body = await response.json();
|
|
21272
|
+
return body.data?.login === true;
|
|
21273
|
+
}).catch(() => false);
|
|
21274
|
+
return canWrite === true;
|
|
21275
|
+
}
|
|
21116
21276
|
var WEIBO_CONFIG = {
|
|
21117
21277
|
channel: TARGET,
|
|
21118
|
-
homeUrl:
|
|
21278
|
+
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21119
21279
|
isAuthenticated: isWeiboAuthenticated,
|
|
21120
21280
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21121
|
-
checkHeadedOnly: false
|
|
21281
|
+
checkHeadedOnly: false,
|
|
21282
|
+
sessionState: {
|
|
21283
|
+
onAuthenticated: async ({ context, page, profileDir }) => {
|
|
21284
|
+
await page.waitForTimeout(DEFAULT_CHANNEL_STATE_SETTLE_MS);
|
|
21285
|
+
try {
|
|
21286
|
+
await persistChannelSessionState(context, profileDir);
|
|
21287
|
+
} catch {
|
|
21288
|
+
throw new Error("weibo authenticated session snapshot failed");
|
|
21289
|
+
}
|
|
21290
|
+
},
|
|
21291
|
+
onOpen: ({ context, page, profileDir }) => restoreChannelSessionState(context, page, profileDir).then()
|
|
21292
|
+
}
|
|
21122
21293
|
};
|
|
21123
21294
|
async function resolveCover(options, content, operation) {
|
|
21124
21295
|
const list = options?.images;
|
|
@@ -21161,7 +21332,7 @@ class WeiboBrowserTransport {
|
|
|
21161
21332
|
constructor(operation = "post", driver = "script", deps = {}) {
|
|
21162
21333
|
this.operation = operation;
|
|
21163
21334
|
this.driver = driver;
|
|
21164
|
-
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21335
|
+
this.launcher = stateRestoringLauncher(deps.launcher ?? kkBrowserLauncher);
|
|
21165
21336
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21166
21337
|
this.coverTimeoutMs = deps.coverTimeoutMs ?? COVER_TIMEOUT_MS;
|
|
21167
21338
|
}
|
|
@@ -21477,6 +21648,15 @@ function apiSubmitScript(text, picId) {
|
|
|
21477
21648
|
const cfg = (window.config || {});
|
|
21478
21649
|
const form = new URLSearchParams({ content: ${JSON.stringify(text)}, st: String(cfg.st || '') });
|
|
21479
21650
|
${picId === "" ? "" : `form.set('pic_id', ${JSON.stringify(picId)});`}
|
|
21651
|
+
// The mobile write endpoint answers a request without the site's own XSRF token with
|
|
21652
|
+
// ok:-100 + a passport signin URL even on a live session (measured 2026-11-26: fresh
|
|
21653
|
+
// SUB/MLOGIN, st present, composer logged in). Send the cookie back as the header.
|
|
21654
|
+
// No regex here on purpose: this body is a template literal, where an escape would collapse
|
|
21655
|
+
// before the page ever runs it.
|
|
21656
|
+
const xsrf = document.cookie
|
|
21657
|
+
.split('; ')
|
|
21658
|
+
.filter((c) => c.indexOf('XSRF-TOKEN=') === 0)
|
|
21659
|
+
.map((c) => c.slice('XSRF-TOKEN='.length))[0] || '';
|
|
21480
21660
|
let response;
|
|
21481
21661
|
try {
|
|
21482
21662
|
response = await fetch('https://m.weibo.cn/api/statuses/update', {
|
|
@@ -21487,6 +21667,7 @@ function apiSubmitScript(text, picId) {
|
|
|
21487
21667
|
headers: {
|
|
21488
21668
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
21489
21669
|
'X-Requested-With': 'XMLHttpRequest',
|
|
21670
|
+
...(xsrf === '' ? {} : { 'X-XSRF-TOKEN': decodeURIComponent(xsrf) }),
|
|
21490
21671
|
Referer: 'https://m.weibo.cn/compose/',
|
|
21491
21672
|
},
|
|
21492
21673
|
body: form.toString(),
|
|
@@ -21498,7 +21679,7 @@ function apiSubmitScript(text, picId) {
|
|
|
21498
21679
|
try { body = await response.json(); } catch { body = null; }
|
|
21499
21680
|
const data = (body && body.data) || {};
|
|
21500
21681
|
const id = String(data.id ?? data.idstr ?? '');
|
|
21501
|
-
const detail = id !== '' ? '' : JSON.stringify(body ?? {}).replace(
|
|
21682
|
+
const detail = id !== '' ? '' : JSON.stringify(body ?? {}).replace(/\\s+/g, ' ').slice(0, 160);
|
|
21502
21683
|
return JSON.stringify({ status: response.status, id: id, detail: detail });
|
|
21503
21684
|
})()`;
|
|
21504
21685
|
}
|
|
@@ -21800,5 +21981,6 @@ export {
|
|
|
21800
21981
|
main2 as main,
|
|
21801
21982
|
picIdFromImageUrl,
|
|
21802
21983
|
processPublishIO,
|
|
21803
|
-
resolveOperation
|
|
21984
|
+
resolveOperation,
|
|
21985
|
+
weiboSurfaceReady
|
|
21804
21986
|
};
|