@gobing-ai/knowledge-kit 0.1.27 → 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 +5980 -4651
- 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/daily-stages.ts +7 -7
- package/plugins/kk/workflows/kk-news-generate.yaml +1 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +81 -80
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +81 -80
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/csdn-pub/dist/index.js +81 -80
- package/plugins/publishings/csdn-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/infoq-pub/dist/index.js +81 -80
- package/plugins/publishings/infoq-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/jike-pub/dist/index.js +81 -80
- package/plugins/publishings/jike-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/juejin-pub/dist/index.js +81 -80
- package/plugins/publishings/juejin-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +81 -80
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/medium-pub/dist/index.js +81 -80
- package/plugins/publishings/medium-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/shipinhao-pub/dist/index.js +272 -85
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +112 -3
- 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 +81 -80
- package/plugins/publishings/sspai-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/substack-pub/dist/index.js +81 -80
- package/plugins/publishings/substack-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +43 -5
- package/plugins/publishings/threads-pub/dist/index.js +86 -81
- package/plugins/publishings/threads-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/threads-pub/src/index.ts +10 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +84 -83
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/weibo-pub/dist/index.js +217 -83
- package/plugins/publishings/weibo-pub/dist/profile-check.js +123 -3
- package/plugins/publishings/weibo-pub/src/index.ts +60 -2
- package/plugins/publishings/weibo-pub/src/profile-check.ts +4 -2
- package/plugins/publishings/x-pub/dist/index.js +81 -80
- package/plugins/publishings/x-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/xhs-pub/dist/index.js +81 -80
- package/plugins/publishings/xhs-pub/dist/profile-check.js +1 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +81 -80
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +1 -1
|
@@ -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";
|
|
@@ -20833,7 +20935,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20833
20935
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20834
20936
|
if (lstat(syncData) === null)
|
|
20835
20937
|
return false;
|
|
20836
|
-
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)}`);
|
|
20837
20939
|
}
|
|
20838
20940
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20839
20941
|
return {
|
|
@@ -21154,18 +21256,40 @@ var isWeiboAuthenticated = async (page) => {
|
|
|
21154
21256
|
facts.composerLabelled = (await trySelectors(page, WEIBO_POST_SELECTORS.composer.filter((s) => s.includes("placeholder")), {
|
|
21155
21257
|
visible: false
|
|
21156
21258
|
})).found;
|
|
21259
|
+
if (weiboSurfaceReady(facts) && MOBILE_HOST_RE.test(facts.url))
|
|
21260
|
+
return weiboSessionCanWrite(page);
|
|
21157
21261
|
if (weiboSurfaceReady(facts))
|
|
21158
21262
|
return true;
|
|
21159
21263
|
}
|
|
21160
21264
|
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
21161
21265
|
return weiboSurfaceReady(facts);
|
|
21162
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
|
+
}
|
|
21163
21276
|
var WEIBO_CONFIG = {
|
|
21164
21277
|
channel: TARGET,
|
|
21165
21278
|
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21166
21279
|
isAuthenticated: isWeiboAuthenticated,
|
|
21167
21280
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21168
|
-
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
|
+
}
|
|
21169
21293
|
};
|
|
21170
21294
|
async function resolveCover(options, content, operation) {
|
|
21171
21295
|
const list = options?.images;
|
|
@@ -21208,7 +21332,7 @@ class WeiboBrowserTransport {
|
|
|
21208
21332
|
constructor(operation = "post", driver = "script", deps = {}) {
|
|
21209
21333
|
this.operation = operation;
|
|
21210
21334
|
this.driver = driver;
|
|
21211
|
-
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21335
|
+
this.launcher = stateRestoringLauncher(deps.launcher ?? kkBrowserLauncher);
|
|
21212
21336
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21213
21337
|
this.coverTimeoutMs = deps.coverTimeoutMs ?? COVER_TIMEOUT_MS;
|
|
21214
21338
|
}
|
|
@@ -21524,6 +21648,15 @@ function apiSubmitScript(text, picId) {
|
|
|
21524
21648
|
const cfg = (window.config || {});
|
|
21525
21649
|
const form = new URLSearchParams({ content: ${JSON.stringify(text)}, st: String(cfg.st || '') });
|
|
21526
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] || '';
|
|
21527
21660
|
let response;
|
|
21528
21661
|
try {
|
|
21529
21662
|
response = await fetch('https://m.weibo.cn/api/statuses/update', {
|
|
@@ -21534,6 +21667,7 @@ function apiSubmitScript(text, picId) {
|
|
|
21534
21667
|
headers: {
|
|
21535
21668
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
21536
21669
|
'X-Requested-With': 'XMLHttpRequest',
|
|
21670
|
+
...(xsrf === '' ? {} : { 'X-XSRF-TOKEN': decodeURIComponent(xsrf) }),
|
|
21537
21671
|
Referer: 'https://m.weibo.cn/compose/',
|
|
21538
21672
|
},
|
|
21539
21673
|
body: form.toString(),
|
|
@@ -21545,7 +21679,7 @@ function apiSubmitScript(text, picId) {
|
|
|
21545
21679
|
try { body = await response.json(); } catch { body = null; }
|
|
21546
21680
|
const data = (body && body.data) || {};
|
|
21547
21681
|
const id = String(data.id ?? data.idstr ?? '');
|
|
21548
|
-
const detail = id !== '' ? '' : JSON.stringify(body ?? {}).replace(
|
|
21682
|
+
const detail = id !== '' ? '' : JSON.stringify(body ?? {}).replace(/\\s+/g, ' ').slice(0, 160);
|
|
21549
21683
|
return JSON.stringify({ status: response.status, id: id, detail: detail });
|
|
21550
21684
|
})()`;
|
|
21551
21685
|
}
|
|
@@ -20194,6 +20194,9 @@ function rename(from, to) {
|
|
|
20194
20194
|
function chmod(path, mode) {
|
|
20195
20195
|
chmodSync(path, mode);
|
|
20196
20196
|
}
|
|
20197
|
+
function createExclusiveFile(path) {
|
|
20198
|
+
closeSync(openSync(path, "wx", 384));
|
|
20199
|
+
}
|
|
20197
20200
|
|
|
20198
20201
|
// ../../packages/publish-harness/src/bot-transaction.ts
|
|
20199
20202
|
import { homedir } from "os";
|
|
@@ -20459,6 +20462,101 @@ class BotError extends Error {
|
|
|
20459
20462
|
this.details = details;
|
|
20460
20463
|
}
|
|
20461
20464
|
}
|
|
20465
|
+
// ../../packages/publish-harness/src/session-state.ts
|
|
20466
|
+
import { randomUUID } from "crypto";
|
|
20467
|
+
init_dist();
|
|
20468
|
+
function channelStorageStatePath(profileDir) {
|
|
20469
|
+
return `${profileDir}/storage-state.json`;
|
|
20470
|
+
}
|
|
20471
|
+
var DEFAULT_CHANNEL_STATE_SETTLE_MS = 3000;
|
|
20472
|
+
async function readSavedState(profileDir) {
|
|
20473
|
+
const fs = createNodeFileSystem();
|
|
20474
|
+
const file = channelStorageStatePath(profileDir);
|
|
20475
|
+
try {
|
|
20476
|
+
if (!await fs.exists(file))
|
|
20477
|
+
return { corrupt: false };
|
|
20478
|
+
return { state: JSON.parse(await fs.readFile(file)), corrupt: false };
|
|
20479
|
+
} catch {
|
|
20480
|
+
return { corrupt: true };
|
|
20481
|
+
}
|
|
20482
|
+
}
|
|
20483
|
+
async function persistChannelSessionState(context, profileDir) {
|
|
20484
|
+
const target = channelStorageStatePath(profileDir);
|
|
20485
|
+
const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
20486
|
+
const fs = createNodeFileSystem();
|
|
20487
|
+
let reserved = false;
|
|
20488
|
+
try {
|
|
20489
|
+
createExclusiveFile(temporary);
|
|
20490
|
+
reserved = true;
|
|
20491
|
+
await context.storageState({ path: temporary });
|
|
20492
|
+
chmod(temporary, 384);
|
|
20493
|
+
await fs.rename(temporary, target);
|
|
20494
|
+
} finally {
|
|
20495
|
+
if (reserved) {
|
|
20496
|
+
await Promise.resolve().then(() => fs.deleteFile(temporary)).catch(() => {
|
|
20497
|
+
return;
|
|
20498
|
+
});
|
|
20499
|
+
}
|
|
20500
|
+
}
|
|
20501
|
+
}
|
|
20502
|
+
async function restoreChannelSessionState(context, page, profileDir) {
|
|
20503
|
+
const { state, corrupt } = await readSavedState(profileDir);
|
|
20504
|
+
if (corrupt) {
|
|
20505
|
+
throw new Error(`the channel saved session state is unreadable (${channelStorageStatePath(profileDir)})`);
|
|
20506
|
+
}
|
|
20507
|
+
const saved = state?.cookies ?? [];
|
|
20508
|
+
if (saved.length === 0)
|
|
20509
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20510
|
+
if (typeof context.cookies !== "function" || typeof context.addCookies !== "function") {
|
|
20511
|
+
return { restored: false, skippedExpired: 0, shadowed: 0 };
|
|
20512
|
+
}
|
|
20513
|
+
const nowSeconds = Date.now() / 1000;
|
|
20514
|
+
const current = await context.cookies().catch(() => []);
|
|
20515
|
+
const alive = saved.filter((cookie) => cookie.expires === undefined || cookie.expires === -1 || cookie.expires > nowSeconds);
|
|
20516
|
+
const skippedExpired = saved.length - alive.length;
|
|
20517
|
+
const held = new Set(current.map((cookie) => `${cookie.domain}|${cookie.name}`));
|
|
20518
|
+
const shadowed = alive.filter((cookie) => held.has(`${cookie.domain}|${cookie.name}`)).length;
|
|
20519
|
+
const inject = alive.filter((cookie) => !held.has(`${cookie.domain}|${cookie.name}`));
|
|
20520
|
+
if (inject.length > 0)
|
|
20521
|
+
await context.addCookies(inject);
|
|
20522
|
+
if (page !== undefined) {
|
|
20523
|
+
for (const entry of state?.origins ?? []) {
|
|
20524
|
+
if (entry.origin === undefined || (entry.localStorage ?? []).length === 0)
|
|
20525
|
+
continue;
|
|
20526
|
+
await page.evaluate(({ origin, items }) => {
|
|
20527
|
+
const page = globalThis;
|
|
20528
|
+
if (page.location.origin !== origin)
|
|
20529
|
+
return;
|
|
20530
|
+
for (const item of items)
|
|
20531
|
+
page.localStorage.setItem(item.name, item.value);
|
|
20532
|
+
}, { origin: entry.origin, items: entry.localStorage ?? [] }).catch(() => {
|
|
20533
|
+
return;
|
|
20534
|
+
});
|
|
20535
|
+
}
|
|
20536
|
+
}
|
|
20537
|
+
return { restored: inject.length > 0, skippedExpired, shadowed };
|
|
20538
|
+
}
|
|
20539
|
+
function stateRestoringLauncher(base) {
|
|
20540
|
+
return {
|
|
20541
|
+
async launch(request) {
|
|
20542
|
+
const context = await base.launch(request);
|
|
20543
|
+
try {
|
|
20544
|
+
const pages = typeof context.pages === "function" ? context.pages() : [];
|
|
20545
|
+
const page = pages[0];
|
|
20546
|
+
const outcome = await restoreChannelSessionState(context, page, request.profileDir);
|
|
20547
|
+
if (outcome.skippedExpired > 0 || outcome.shadowed > 0) {
|
|
20548
|
+
echoError(`channel session: replayed ${outcome.restored ? "a" : "no"} saved session (${outcome.skippedExpired} expired, ${outcome.shadowed} shadowed by the profile)`);
|
|
20549
|
+
}
|
|
20550
|
+
} catch (error) {
|
|
20551
|
+
await Promise.resolve().then(() => context.close()).catch(() => {
|
|
20552
|
+
return;
|
|
20553
|
+
});
|
|
20554
|
+
throw error;
|
|
20555
|
+
}
|
|
20556
|
+
return context;
|
|
20557
|
+
}
|
|
20558
|
+
};
|
|
20559
|
+
}
|
|
20462
20560
|
// ../../packages/publish-harness/src/index.ts
|
|
20463
20561
|
import { homedir as homedir4 } from "os";
|
|
20464
20562
|
import { join as join4, resolve as resolve4 } from "path";
|
|
@@ -20537,7 +20635,7 @@ function quarantineProfileSyncData(profileDir) {
|
|
|
20537
20635
|
const syncData = join5(profileDir, "Default", "Sync Data");
|
|
20538
20636
|
if (lstat(syncData) === null)
|
|
20539
20637
|
return false;
|
|
20540
|
-
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0,
|
|
20638
|
+
return rename(syncData, `${syncData}.broken-${new Date().toISOString().replace(/[:.]/g, "").slice(0, 17)}`);
|
|
20541
20639
|
}
|
|
20542
20640
|
function createKkBrowserLauncher(loadPlaywright = () => import("playwright"), ownership, leaseOptions = {}) {
|
|
20543
20641
|
return {
|
|
@@ -21184,22 +21282,44 @@ var isWeiboAuthenticated = async (page) => {
|
|
|
21184
21282
|
facts.composerLabelled = (await trySelectors(page, WEIBO_POST_SELECTORS.composer.filter((s) => s.includes("placeholder")), {
|
|
21185
21283
|
visible: false
|
|
21186
21284
|
})).found;
|
|
21285
|
+
if (weiboSurfaceReady(facts) && MOBILE_HOST_RE.test(facts.url))
|
|
21286
|
+
return weiboSessionCanWrite(page);
|
|
21187
21287
|
if (weiboSurfaceReady(facts))
|
|
21188
21288
|
return true;
|
|
21189
21289
|
}
|
|
21190
21290
|
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
21191
21291
|
return weiboSurfaceReady(facts);
|
|
21192
21292
|
};
|
|
21293
|
+
var MOBILE_HOST_RE = /^https?:\/\/m\.weibo\.cn\//;
|
|
21294
|
+
async function weiboSessionCanWrite(page) {
|
|
21295
|
+
const canWrite = await page.evaluate(async () => {
|
|
21296
|
+
const response = await fetch("https://m.weibo.cn/api/config", { credentials: "include" });
|
|
21297
|
+
const body = await response.json();
|
|
21298
|
+
return body.data?.login === true;
|
|
21299
|
+
}).catch(() => false);
|
|
21300
|
+
return canWrite === true;
|
|
21301
|
+
}
|
|
21193
21302
|
var WEIBO_CONFIG = {
|
|
21194
21303
|
channel: TARGET,
|
|
21195
21304
|
homeUrl: WEIBO_MOBILE_COMPOSE_URL,
|
|
21196
21305
|
isAuthenticated: isWeiboAuthenticated,
|
|
21197
21306
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21198
|
-
checkHeadedOnly: false
|
|
21307
|
+
checkHeadedOnly: false,
|
|
21308
|
+
sessionState: {
|
|
21309
|
+
onAuthenticated: async ({ context, page, profileDir }) => {
|
|
21310
|
+
await page.waitForTimeout(DEFAULT_CHANNEL_STATE_SETTLE_MS);
|
|
21311
|
+
try {
|
|
21312
|
+
await persistChannelSessionState(context, profileDir);
|
|
21313
|
+
} catch {
|
|
21314
|
+
throw new Error("weibo authenticated session snapshot failed");
|
|
21315
|
+
}
|
|
21316
|
+
},
|
|
21317
|
+
onOpen: ({ context, page, profileDir }) => restoreChannelSessionState(context, page, profileDir).then()
|
|
21318
|
+
}
|
|
21199
21319
|
};
|
|
21200
21320
|
if (false) {}
|
|
21201
21321
|
|
|
21202
21322
|
// ../../plugins/publishings/weibo-pub/src/profile-check.ts
|
|
21203
21323
|
if (import.meta.main) {
|
|
21204
|
-
process.exit(await runProfileCli(WEIBO_CONFIG, Bun.argv.slice(2)));
|
|
21324
|
+
process.exit(await runProfileCli(WEIBO_CONFIG, Bun.argv.slice(2), { launcher: stateRestoringLauncher(kkBrowserLauncher) }));
|
|
21205
21325
|
}
|
|
@@ -11,12 +11,16 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
type ChannelBrowserConfig,
|
|
13
13
|
checkChannelSession,
|
|
14
|
+
DEFAULT_CHANNEL_STATE_SETTLE_MS,
|
|
14
15
|
expectOutcome,
|
|
15
16
|
kkBrowserLauncher,
|
|
16
17
|
markdownToHtml,
|
|
17
18
|
pasteHtml,
|
|
19
|
+
persistChannelSessionState,
|
|
18
20
|
resolveChannelProfileDir,
|
|
19
21
|
resolveSelector,
|
|
22
|
+
restoreChannelSessionState,
|
|
23
|
+
stateRestoringLauncher,
|
|
20
24
|
uploadFile,
|
|
21
25
|
} from '@gobing-ai/publish-harness/browser';
|
|
22
26
|
import {
|
|
@@ -272,12 +276,37 @@ export const isWeiboAuthenticated: IsAuthenticatedPredicate = async (page) => {
|
|
|
272
276
|
},
|
|
273
277
|
)
|
|
274
278
|
).found;
|
|
279
|
+
// The composer alone is not a session: m.weibo.cn renders the same 发送/公开 surface for a
|
|
280
|
+
// guest (measured 2026-11-26 — logged-out profile, empty `SUB` session, every post answered
|
|
281
|
+
// `ok:-100` + a passport redirect). The site's own write-session flag is the evidence.
|
|
282
|
+
if (weiboSurfaceReady(facts) && MOBILE_HOST_RE.test(facts.url)) return weiboSessionCanWrite(page);
|
|
275
283
|
if (weiboSurfaceReady(facts)) return true;
|
|
276
284
|
}
|
|
277
285
|
facts.articleTitle = (await trySelectors(page, WEIBO_ARTICLE_SELECTORS.title, { visible: false })).found;
|
|
278
286
|
return weiboSurfaceReady(facts);
|
|
279
287
|
};
|
|
280
288
|
|
|
289
|
+
/** `m.weibo.cn` — the host whose `/api/config` flag states whether this session can write. */
|
|
290
|
+
const MOBILE_HOST_RE = /^https?:\/\/m\.weibo\.cn\//;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Whether this mobile session may actually post: the site's own `/api/config` `login` flag.
|
|
294
|
+
*
|
|
295
|
+
* A guest page carries a composer, a `st` and a `uid`, so nothing on the rendered surface separates
|
|
296
|
+
* "signed in" from "signed out"; the write endpoint does, and it answers a guest with
|
|
297
|
+
* `{"ok":-100}`. Fail closed: a probe that cannot answer is not a session.
|
|
298
|
+
*/
|
|
299
|
+
async function weiboSessionCanWrite(page: Page): Promise<boolean> {
|
|
300
|
+
const canWrite = await page
|
|
301
|
+
.evaluate(async () => {
|
|
302
|
+
const response = await fetch('https://m.weibo.cn/api/config', { credentials: 'include' });
|
|
303
|
+
const body = (await response.json()) as { data?: { login?: unknown } };
|
|
304
|
+
return body.data?.login === true;
|
|
305
|
+
})
|
|
306
|
+
.catch(() => false);
|
|
307
|
+
return canWrite === true;
|
|
308
|
+
}
|
|
309
|
+
|
|
281
310
|
/**
|
|
282
311
|
* Site-owned config for the shared session check and operator CLI (ADR-032). The publish preflight
|
|
283
312
|
* never forwards `checkHeadedOnly`: it is the operator CLI's setting, and a refusal must never
|
|
@@ -298,6 +327,23 @@ export const WEIBO_CONFIG: ChannelBrowserConfig = {
|
|
|
298
327
|
isAuthenticated: isWeiboAuthenticated,
|
|
299
328
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
300
329
|
checkHeadedOnly: false,
|
|
330
|
+
// 2026-11-26: a login that verifies does not survive the window closing — measured: `kk bot
|
|
331
|
+
// login --save weibo` reported site-verified at 20:54, and 10 minutes later the same profile
|
|
332
|
+
// answered `GET /api/config` with `login:false` and the desktop redirected to `/newlogin`.
|
|
333
|
+
// So the mobile session lives in state the profile does not keep (cookies aside), and the same
|
|
334
|
+
// storageState rail shipinhao/wechatmp use is what makes one sign-in reusable.
|
|
335
|
+
sessionState: {
|
|
336
|
+
onAuthenticated: async ({ context, page, profileDir }) => {
|
|
337
|
+
await page.waitForTimeout(DEFAULT_CHANNEL_STATE_SETTLE_MS);
|
|
338
|
+
try {
|
|
339
|
+
await persistChannelSessionState(context, profileDir);
|
|
340
|
+
} catch {
|
|
341
|
+
// Storage-state errors can carry cookie values: never relay the exception.
|
|
342
|
+
throw new Error('weibo authenticated session snapshot failed');
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
onOpen: ({ context, page, profileDir }) => restoreChannelSessionState(context, page, profileDir).then(),
|
|
346
|
+
},
|
|
301
347
|
};
|
|
302
348
|
|
|
303
349
|
/**
|
|
@@ -360,7 +406,9 @@ export class WeiboBrowserTransport implements PublishTransport {
|
|
|
360
406
|
) {
|
|
361
407
|
this.operation = operation;
|
|
362
408
|
this.driver = driver;
|
|
363
|
-
this
|
|
409
|
+
// 2026-11-26: every context this transport opens re-injects the captured session first —
|
|
410
|
+
// the profile's own store does not keep the mobile session across launches.
|
|
411
|
+
this.launcher = stateRestoringLauncher(deps.launcher ?? kkBrowserLauncher);
|
|
364
412
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
365
413
|
// Explicit seam (tests pin a small value); production keeps the longer cover budget.
|
|
366
414
|
this.coverTimeoutMs = deps.coverTimeoutMs ?? COVER_TIMEOUT_MS;
|
|
@@ -849,6 +897,15 @@ function apiSubmitScript(text: string, picId: string): string {
|
|
|
849
897
|
const cfg = (window.config || {});
|
|
850
898
|
const form = new URLSearchParams({ content: ${JSON.stringify(text)}, st: String(cfg.st || '') });
|
|
851
899
|
${picId === '' ? '' : `form.set('pic_id', ${JSON.stringify(picId)});`}
|
|
900
|
+
// The mobile write endpoint answers a request without the site's own XSRF token with
|
|
901
|
+
// ok:-100 + a passport signin URL even on a live session (measured 2026-11-26: fresh
|
|
902
|
+
// SUB/MLOGIN, st present, composer logged in). Send the cookie back as the header.
|
|
903
|
+
// No regex here on purpose: this body is a template literal, where an escape would collapse
|
|
904
|
+
// before the page ever runs it.
|
|
905
|
+
const xsrf = document.cookie
|
|
906
|
+
.split('; ')
|
|
907
|
+
.filter((c) => c.indexOf('XSRF-TOKEN=') === 0)
|
|
908
|
+
.map((c) => c.slice('XSRF-TOKEN='.length))[0] || '';
|
|
852
909
|
let response;
|
|
853
910
|
try {
|
|
854
911
|
response = await fetch('https://m.weibo.cn/api/statuses/update', {
|
|
@@ -859,6 +916,7 @@ function apiSubmitScript(text: string, picId: string): string {
|
|
|
859
916
|
headers: {
|
|
860
917
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
861
918
|
'X-Requested-With': 'XMLHttpRequest',
|
|
919
|
+
...(xsrf === '' ? {} : { 'X-XSRF-TOKEN': decodeURIComponent(xsrf) }),
|
|
862
920
|
Referer: 'https://m.weibo.cn/compose/',
|
|
863
921
|
},
|
|
864
922
|
body: form.toString(),
|
|
@@ -870,7 +928,7 @@ function apiSubmitScript(text: string, picId: string): string {
|
|
|
870
928
|
try { body = await response.json(); } catch { body = null; }
|
|
871
929
|
const data = (body && body.data) || {};
|
|
872
930
|
const id = String(data.id ?? data.idstr ?? '');
|
|
873
|
-
const detail = id !== '' ? '' : JSON.stringify(body ?? {}).replace(
|
|
931
|
+
const detail = id !== '' ? '' : JSON.stringify(body ?? {}).replace(/\\s+/g, ' ').slice(0, 160);
|
|
874
932
|
return JSON.stringify({ status: response.status, id: id, detail: detail });
|
|
875
933
|
})()`;
|
|
876
934
|
}
|
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
* a selector that never attaches is a refusal (`Bun plugins/publishings/weibo-pub/src/profile-check.ts
|
|
13
13
|
* login` is the recovery), never silent success.
|
|
14
14
|
*/
|
|
15
|
-
import { runProfileCli } from '@gobing-ai/publish-harness/browser';
|
|
15
|
+
import { kkBrowserLauncher, runProfileCli, stateRestoringLauncher } from '@gobing-ai/publish-harness/browser';
|
|
16
16
|
import { WEIBO_CONFIG } from './index';
|
|
17
17
|
|
|
18
18
|
if (import.meta.main) {
|
|
19
|
-
process.exit(
|
|
19
|
+
process.exit(
|
|
20
|
+
await runProfileCli(WEIBO_CONFIG, Bun.argv.slice(2), { launcher: stateRestoringLauncher(kkBrowserLauncher) }),
|
|
21
|
+
);
|
|
20
22
|
}
|