@jackwener/opencli 1.6.0 → 1.6.2
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/CHANGELOG.md +8 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +27 -45
- package/README.zh-CN.md +32 -34
- package/autoresearch/browse-tasks.json +18 -20
- package/autoresearch/commands/debug.ts +163 -0
- package/autoresearch/commands/fix.ts +145 -0
- package/autoresearch/commands/plan.ts +88 -0
- package/autoresearch/commands/run.ts +138 -0
- package/autoresearch/config.ts +82 -0
- package/autoresearch/engine.ts +359 -0
- package/autoresearch/eval-all.ts +127 -0
- package/autoresearch/eval-browse.ts +1 -1
- package/autoresearch/eval-publish.ts +238 -0
- package/autoresearch/eval-save.ts +249 -0
- package/autoresearch/eval-skill.ts +14 -8
- package/autoresearch/eval-v2ex.ts +220 -0
- package/autoresearch/eval-zhihu.ts +230 -0
- package/autoresearch/logger.ts +69 -0
- package/autoresearch/presets/combined-reliability.ts +27 -0
- package/autoresearch/presets/index.ts +23 -0
- package/autoresearch/presets/operate-reliability.ts +24 -0
- package/autoresearch/presets/save-reliability.ts +26 -0
- package/autoresearch/presets/skill-quality.ts +20 -0
- package/autoresearch/presets/v2ex-reliability.ts +24 -0
- package/autoresearch/presets/zhihu-reliability.ts +25 -0
- package/autoresearch/publish-tasks.json +345 -0
- package/autoresearch/run-save.sh +11 -0
- package/autoresearch/save-adapters/xhs-explore-deep.ts +64 -0
- package/autoresearch/save-adapters/xhs-note-comments.ts +61 -0
- package/autoresearch/save-adapters/xhs-search-full.ts +62 -0
- package/autoresearch/save-adapters/zhihu-hot-detail.ts +52 -0
- package/autoresearch/save-adapters/zhihu-question-full.ts +57 -0
- package/autoresearch/save-adapters/zhihu-search-detail.ts +53 -0
- package/autoresearch/save-tasks.json +281 -0
- package/autoresearch/v2ex-tasks.json +899 -0
- package/autoresearch/zhihu-tasks.json +848 -0
- package/bun.lock +615 -0
- package/dist/browser/base-page.d.ts +4 -2
- package/dist/browser/base-page.js +37 -4
- package/dist/browser/bridge.js +10 -8
- package/dist/browser/cdp.js +2 -6
- package/dist/browser/daemon-client.d.ts +11 -1
- package/dist/browser/daemon-client.js +3 -0
- package/dist/browser/dom-helpers.d.ts +4 -2
- package/dist/browser/dom-helpers.js +42 -31
- package/dist/browser/dom-snapshot.js +23 -1
- package/dist/browser/page.d.ts +7 -2
- package/dist/browser/page.js +112 -30
- package/dist/browser.test.js +1 -1
- package/dist/build-manifest.d.ts +1 -0
- package/dist/build-manifest.js +1 -0
- package/dist/cli-manifest.json +1133 -182
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +48 -7
- package/dist/cli.test.d.ts +1 -0
- package/dist/cli.test.js +88 -0
- package/dist/clis/1688/item.d.ts +70 -0
- package/dist/clis/1688/item.js +187 -0
- package/dist/clis/1688/item.test.d.ts +1 -0
- package/dist/clis/1688/item.test.js +67 -0
- package/dist/clis/1688/search.d.ts +56 -0
- package/dist/clis/1688/search.js +309 -0
- package/dist/clis/1688/search.test.d.ts +1 -0
- package/dist/clis/1688/search.test.js +75 -0
- package/dist/clis/1688/shared.d.ts +112 -0
- package/dist/clis/1688/shared.js +514 -0
- package/dist/clis/1688/shared.test.d.ts +1 -0
- package/dist/clis/1688/shared.test.js +57 -0
- package/dist/clis/1688/store.d.ts +45 -0
- package/dist/clis/1688/store.js +226 -0
- package/dist/clis/1688/store.test.d.ts +1 -0
- package/dist/clis/1688/store.test.js +62 -0
- package/dist/clis/amazon/bestsellers.d.ts +0 -20
- package/dist/clis/amazon/bestsellers.js +6 -129
- package/dist/clis/amazon/bestsellers.test.js +12 -3
- package/dist/clis/amazon/movers-shakers.d.ts +1 -0
- package/dist/clis/amazon/movers-shakers.js +7 -0
- package/dist/clis/amazon/new-releases.d.ts +1 -0
- package/dist/clis/amazon/new-releases.js +7 -0
- package/dist/clis/amazon/rankings.d.ts +59 -0
- package/dist/clis/amazon/rankings.js +226 -0
- package/dist/clis/amazon/rankings.test.d.ts +1 -0
- package/dist/clis/amazon/rankings.test.js +41 -0
- package/dist/clis/amazon/shared.d.ts +11 -0
- package/dist/clis/amazon/shared.js +121 -11
- package/dist/clis/amazon/shared.test.js +11 -0
- package/dist/clis/bilibili/comments.js +2 -2
- package/dist/clis/bilibili/comments.test.js +3 -2
- package/dist/clis/bilibili/download.js +2 -1
- package/dist/clis/bilibili/subtitle.js +4 -3
- package/dist/clis/bilibili/subtitle.test.js +2 -1
- package/dist/clis/bilibili/utils.d.ts +5 -0
- package/dist/clis/bilibili/utils.js +30 -0
- package/dist/clis/bilibili/utils.test.d.ts +1 -0
- package/dist/clis/bilibili/utils.test.js +17 -0
- package/dist/clis/douban/marks.js +1 -1
- package/dist/clis/douban/subject.yaml +50 -19
- package/dist/clis/doubao/utils.js +32 -12
- package/dist/clis/douyin/_shared/browser-fetch.test.js +0 -1
- package/dist/clis/douyin/_shared/transcode.test.js +0 -2
- package/dist/clis/douyin/draft.test.js +0 -2
- package/dist/clis/facebook/search.test.js +0 -2
- package/dist/clis/gemini/ask.js +9 -3
- package/dist/clis/gemini/ask.test.d.ts +1 -0
- package/dist/clis/gemini/ask.test.js +100 -0
- package/dist/clis/gemini/reply-state.test.d.ts +1 -0
- package/dist/clis/gemini/reply-state.test.js +641 -0
- package/dist/clis/gemini/utils.d.ts +44 -1
- package/dist/clis/gemini/utils.js +528 -61
- package/dist/clis/gemini/utils.test.js +149 -2
- package/dist/clis/hupu/detail.d.ts +1 -0
- package/dist/clis/hupu/detail.js +72 -0
- package/dist/clis/hupu/hot.yaml +43 -0
- package/dist/clis/hupu/like.d.ts +1 -0
- package/dist/clis/hupu/like.js +75 -0
- package/dist/clis/hupu/reply.d.ts +1 -0
- package/dist/clis/hupu/reply.js +71 -0
- package/dist/clis/hupu/search.d.ts +1 -0
- package/dist/clis/hupu/search.js +59 -0
- package/dist/clis/hupu/unlike.d.ts +1 -0
- package/dist/clis/hupu/unlike.js +75 -0
- package/dist/clis/hupu/utils.d.ts +20 -0
- package/dist/clis/hupu/utils.js +319 -0
- package/dist/clis/instagram/_shared/private-publish.d.ts +138 -0
- package/dist/clis/instagram/_shared/private-publish.js +1030 -0
- package/dist/clis/instagram/_shared/private-publish.test.d.ts +1 -0
- package/dist/clis/instagram/_shared/private-publish.test.js +705 -0
- package/dist/clis/instagram/_shared/protocol-capture.d.ts +26 -0
- package/dist/clis/instagram/_shared/protocol-capture.js +282 -0
- package/dist/clis/instagram/_shared/protocol-capture.test.d.ts +1 -0
- package/dist/clis/instagram/_shared/protocol-capture.test.js +114 -0
- package/dist/clis/instagram/_shared/runtime-info.d.ts +9 -0
- package/dist/clis/instagram/_shared/runtime-info.js +81 -0
- package/dist/clis/instagram/note.d.ts +1 -0
- package/dist/clis/instagram/note.js +222 -0
- package/dist/clis/instagram/note.test.d.ts +1 -0
- package/dist/clis/instagram/note.test.js +81 -0
- package/dist/clis/instagram/post.d.ts +4 -0
- package/dist/clis/instagram/post.js +1496 -0
- package/dist/clis/instagram/post.test.d.ts +1 -0
- package/dist/clis/instagram/post.test.js +1647 -0
- package/dist/clis/instagram/reel.d.ts +1 -0
- package/dist/clis/instagram/reel.js +826 -0
- package/dist/clis/instagram/reel.test.d.ts +1 -0
- package/dist/clis/instagram/reel.test.js +167 -0
- package/dist/clis/instagram/story.d.ts +1 -0
- package/dist/clis/instagram/story.js +115 -0
- package/dist/clis/instagram/story.test.d.ts +1 -0
- package/dist/clis/instagram/story.test.js +167 -0
- package/dist/clis/sinafinance/stock-rank.d.ts +4 -0
- package/dist/clis/sinafinance/stock-rank.js +65 -0
- package/dist/clis/substack/utils.test.js +0 -2
- package/dist/clis/twitter/post.js +72 -45
- package/dist/clis/twitter/post.test.d.ts +1 -0
- package/dist/clis/twitter/post.test.js +116 -0
- package/dist/clis/twitter/reply.d.ts +12 -0
- package/dist/clis/twitter/reply.js +257 -35
- package/dist/clis/twitter/reply.test.d.ts +1 -0
- package/dist/clis/twitter/reply.test.js +151 -0
- package/dist/clis/twitter/search.js +67 -5
- package/dist/clis/twitter/search.test.js +83 -5
- package/dist/clis/xianyu/chat.d.ts +7 -0
- package/dist/clis/xianyu/chat.js +146 -0
- package/dist/clis/xianyu/chat.test.d.ts +1 -0
- package/dist/clis/xianyu/chat.test.js +15 -0
- package/dist/clis/xianyu/item.d.ts +7 -0
- package/dist/clis/xianyu/item.js +152 -0
- package/dist/clis/xianyu/item.test.d.ts +1 -0
- package/dist/clis/xianyu/item.test.js +56 -0
- package/dist/clis/xianyu/search.d.ts +10 -0
- package/dist/clis/xianyu/search.js +134 -0
- package/dist/clis/xianyu/search.test.d.ts +1 -0
- package/dist/clis/xianyu/search.test.js +17 -0
- package/dist/clis/xianyu/utils.d.ts +1 -0
- package/dist/clis/xianyu/utils.js +8 -0
- package/dist/clis/xiaoe/catalog.yaml +129 -0
- package/dist/clis/xiaoe/content.yaml +43 -0
- package/dist/clis/xiaoe/courses.yaml +73 -0
- package/dist/clis/xiaoe/detail.yaml +39 -0
- package/dist/clis/xiaoe/play-url.yaml +124 -0
- package/dist/clis/xiaohongshu/comments.test.js +0 -2
- package/dist/clis/xiaohongshu/creator-note-detail.test.js +0 -2
- package/dist/clis/xiaohongshu/creator-notes.test.js +0 -2
- package/dist/clis/xiaohongshu/download.test.js +0 -2
- package/dist/clis/xiaohongshu/note.test.js +0 -2
- package/dist/clis/xiaohongshu/publish.test.js +0 -2
- package/dist/clis/xiaohongshu/search.js +29 -20
- package/dist/clis/xiaohongshu/search.test.js +56 -48
- package/dist/clis/yuanbao/ask.d.ts +21 -0
- package/dist/clis/yuanbao/ask.js +427 -0
- package/dist/clis/yuanbao/ask.test.d.ts +1 -0
- package/dist/clis/yuanbao/ask.test.js +124 -0
- package/dist/clis/yuanbao/new.d.ts +1 -0
- package/dist/clis/yuanbao/new.js +70 -0
- package/dist/clis/yuanbao/new.test.d.ts +1 -0
- package/dist/clis/yuanbao/new.test.js +30 -0
- package/dist/clis/yuanbao/shared.d.ts +13 -0
- package/dist/clis/yuanbao/shared.js +49 -0
- package/dist/clis/zhihu/question.js +30 -19
- package/dist/clis/zhihu/question.test.js +34 -16
- package/dist/commanderAdapter.js +8 -4
- package/dist/commanderAdapter.test.js +42 -0
- package/dist/completion.js +3 -1
- package/dist/completion.test.d.ts +1 -0
- package/dist/completion.test.js +23 -0
- package/dist/doctor.js +1 -1
- package/dist/electron-apps.d.ts +2 -0
- package/dist/electron-apps.js +7 -1
- package/dist/errors.js +1 -1
- package/dist/execution.js +25 -35
- package/dist/explore.js +1 -1
- package/dist/launcher.d.ts +4 -0
- package/dist/launcher.js +64 -8
- package/dist/launcher.test.js +88 -7
- package/dist/output.d.ts +2 -0
- package/dist/output.js +10 -1
- package/dist/output.test.d.ts +0 -3
- package/dist/output.test.js +59 -92
- package/dist/pipeline/executor.test.js +0 -2
- package/dist/pipeline/steps/download.test.js +0 -2
- package/dist/registry.d.ts +2 -0
- package/dist/serialization.d.ts +1 -0
- package/dist/serialization.js +1 -0
- package/dist/types.d.ts +9 -2
- package/docs/.vitepress/config.mts +4 -0
- package/docs/adapters/browser/1688.md +52 -0
- package/docs/adapters/browser/36kr.md +2 -1
- package/docs/adapters/browser/doubao.md +5 -1
- package/docs/adapters/browser/hupu.md +53 -0
- package/docs/adapters/browser/sinafinance.md +32 -2
- package/docs/adapters/browser/weibo.md +6 -1
- package/docs/adapters/browser/wikipedia.md +2 -0
- package/docs/adapters/browser/xianyu.md +42 -0
- package/docs/adapters/browser/xiaoe.md +44 -0
- package/docs/adapters/browser/yuanbao.md +64 -0
- package/docs/adapters/index.md +14 -5
- package/docs/comparison.md +1 -1
- package/docs/developer/ai-workflow.md +2 -2
- package/docs/developer/contributing.md +1 -1
- package/docs/developer/testing.md +2 -0
- package/docs/guide/plugins.md +1 -0
- package/docs/guide/troubleshooting.md +11 -0
- package/docs/superpowers/specs/2026-04-03-v2ex-autoresearch-design.md +41 -0
- package/docs/zh/guide/plugins.md +1 -0
- package/extension/dist/background.js +1127 -0
- package/extension/src/background.test.ts +39 -0
- package/extension/src/background.ts +223 -34
- package/extension/src/cdp.ts +194 -4
- package/extension/src/protocol.ts +22 -1
- package/package.json +3 -2
- package/scripts/postinstall.js +1 -1
- package/skills/opencli-explorer/SKILL.md +1 -1
- package/skills/opencli-oneshot/SKILL.md +2 -2
- package/skills/opencli-operate/SKILL.md +120 -27
- package/skills/opencli-usage/SKILL.md +31 -20
- package/skills/opencli-usage/browser.md +114 -16
- package/skills/opencli-usage/public-api.md +32 -3
- package/skills/smart-search/SKILL.md +156 -0
- package/skills/smart-search/references/sources-ai.md +74 -0
- package/skills/smart-search/references/sources-info.md +43 -0
- package/skills/smart-search/references/sources-media.md +50 -0
- package/skills/smart-search/references/sources-other.md +42 -0
- package/skills/smart-search/references/sources-shopping.md +31 -0
- package/skills/smart-search/references/sources-social.md +51 -0
- package/skills/smart-search/references/sources-tech.md +42 -0
- package/skills/smart-search/references/sources-travel.md +20 -0
- package/src/browser/base-page.ts +41 -6
- package/src/browser/bridge.ts +11 -8
- package/src/browser/cdp.ts +1 -8
- package/src/browser/daemon-client.ts +11 -1
- package/src/browser/dom-helpers.ts +43 -31
- package/src/browser/dom-snapshot.ts +23 -1
- package/src/browser/page.ts +115 -31
- package/src/browser.test.ts +1 -1
- package/src/build-manifest.ts +2 -0
- package/src/cli.test.ts +133 -0
- package/src/cli.ts +73 -11
- package/src/clis/1688/item.test.ts +69 -0
- package/src/clis/1688/item.ts +282 -0
- package/src/clis/1688/search.test.ts +81 -0
- package/src/clis/1688/search.ts +402 -0
- package/src/clis/1688/shared.test.ts +75 -0
- package/src/clis/1688/shared.ts +623 -0
- package/src/clis/1688/store.test.ts +69 -0
- package/src/clis/1688/store.ts +300 -0
- package/src/clis/amazon/bestsellers.test.ts +12 -3
- package/src/clis/amazon/bestsellers.ts +6 -178
- package/src/clis/amazon/movers-shakers.ts +8 -0
- package/src/clis/amazon/new-releases.ts +8 -0
- package/src/clis/amazon/rankings.test.ts +47 -0
- package/src/clis/amazon/rankings.ts +312 -0
- package/src/clis/amazon/shared.test.ts +16 -0
- package/src/clis/amazon/shared.ts +134 -12
- package/src/clis/bilibili/comments.test.ts +4 -3
- package/src/clis/bilibili/comments.ts +2 -2
- package/src/clis/bilibili/download.ts +2 -1
- package/src/clis/bilibili/subtitle.test.ts +2 -1
- package/src/clis/bilibili/subtitle.ts +4 -3
- package/src/clis/bilibili/utils.test.ts +21 -0
- package/src/clis/bilibili/utils.ts +27 -0
- package/src/clis/douban/marks.ts +1 -1
- package/src/clis/douban/subject.yaml +50 -19
- package/src/clis/doubao/utils.ts +32 -12
- package/src/clis/douyin/_shared/browser-fetch.test.ts +0 -1
- package/src/clis/douyin/_shared/transcode.test.ts +0 -2
- package/src/clis/douyin/draft.test.ts +0 -2
- package/src/clis/facebook/search.test.ts +0 -2
- package/src/clis/gemini/ask.test.ts +116 -0
- package/src/clis/gemini/ask.ts +10 -3
- package/src/clis/gemini/reply-state.test.ts +708 -0
- package/src/clis/gemini/utils.test.ts +184 -2
- package/src/clis/gemini/utils.ts +588 -60
- package/src/clis/hupu/detail.ts +126 -0
- package/src/clis/hupu/hot.yaml +43 -0
- package/src/clis/hupu/like.ts +76 -0
- package/src/clis/hupu/reply.ts +76 -0
- package/src/clis/hupu/search.ts +95 -0
- package/src/clis/hupu/unlike.ts +76 -0
- package/src/clis/hupu/utils.ts +381 -0
- package/src/clis/instagram/_shared/private-publish.test.ts +827 -0
- package/src/clis/instagram/_shared/private-publish.ts +1303 -0
- package/src/clis/instagram/_shared/protocol-capture.test.ts +148 -0
- package/src/clis/instagram/_shared/protocol-capture.ts +321 -0
- package/src/clis/instagram/_shared/runtime-info.ts +91 -0
- package/src/clis/instagram/note.test.ts +96 -0
- package/src/clis/instagram/note.ts +254 -0
- package/src/clis/instagram/post.test.ts +1716 -0
- package/src/clis/instagram/post.ts +1620 -0
- package/src/clis/instagram/reel.test.ts +191 -0
- package/src/clis/instagram/reel.ts +886 -0
- package/src/clis/instagram/story.test.ts +191 -0
- package/src/clis/instagram/story.ts +151 -0
- package/src/clis/sinafinance/stock-rank.ts +68 -0
- package/src/clis/substack/utils.test.ts +0 -2
- package/src/clis/twitter/post.test.ts +157 -0
- package/src/clis/twitter/post.ts +82 -48
- package/src/clis/twitter/reply.test.ts +177 -0
- package/src/clis/twitter/reply.ts +285 -39
- package/src/clis/twitter/search.test.ts +88 -5
- package/src/clis/twitter/search.ts +68 -5
- package/src/clis/xianyu/chat.test.ts +20 -0
- package/src/clis/xianyu/chat.ts +175 -0
- package/src/clis/xianyu/item.test.ts +67 -0
- package/src/clis/xianyu/item.ts +172 -0
- package/src/clis/xianyu/search.test.ts +22 -0
- package/src/clis/xianyu/search.ts +151 -0
- package/src/clis/xianyu/utils.ts +9 -0
- package/src/clis/xiaoe/catalog.yaml +129 -0
- package/src/clis/xiaoe/content.yaml +43 -0
- package/src/clis/xiaoe/courses.yaml +73 -0
- package/src/clis/xiaoe/detail.yaml +39 -0
- package/src/clis/xiaoe/play-url.yaml +124 -0
- package/src/clis/xiaohongshu/comments.test.ts +0 -2
- package/src/clis/xiaohongshu/creator-note-detail.test.ts +0 -2
- package/src/clis/xiaohongshu/creator-notes.test.ts +0 -2
- package/src/clis/xiaohongshu/download.test.ts +0 -2
- package/src/clis/xiaohongshu/note.test.ts +0 -2
- package/src/clis/xiaohongshu/publish.test.ts +0 -2
- package/src/clis/xiaohongshu/search.test.ts +59 -48
- package/src/clis/xiaohongshu/search.ts +31 -21
- package/src/clis/yuanbao/ask.test.ts +156 -0
- package/src/clis/yuanbao/ask.ts +522 -0
- package/src/clis/yuanbao/new.test.ts +36 -0
- package/src/clis/yuanbao/new.ts +81 -0
- package/src/clis/yuanbao/shared.ts +57 -0
- package/src/clis/zhihu/question.test.ts +42 -17
- package/src/clis/zhihu/question.ts +31 -26
- package/src/commanderAdapter.test.ts +51 -0
- package/src/commanderAdapter.ts +8 -4
- package/src/completion.test.ts +30 -0
- package/src/completion.ts +3 -1
- package/src/doctor.ts +1 -1
- package/src/electron-apps.ts +9 -1
- package/src/errors.ts +1 -1
- package/src/execution.ts +26 -30
- package/src/explore.ts +1 -1
- package/src/launcher.test.ts +121 -7
- package/src/launcher.ts +87 -9
- package/src/output.test.ts +50 -90
- package/src/output.ts +10 -1
- package/src/pipeline/executor.test.ts +0 -2
- package/src/pipeline/steps/download.test.ts +0 -2
- package/src/registry.ts +2 -0
- package/src/serialization.ts +2 -0
- package/src/types.ts +9 -2
- package/tests/e2e/browser-auth.test.ts +9 -0
- package/CLI-EXPLORER.md +0 -724
- package/CLI-ONESHOT.md +0 -216
- package/SKILL.md +0 -59
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { AuthRequiredError, CommandExecutionError } from '../../errors.js';
|
|
2
|
+
export function stripHtml(html) {
|
|
3
|
+
if (!html)
|
|
4
|
+
return '';
|
|
5
|
+
const decoded = html
|
|
6
|
+
.replace(/\\u003c/g, '<')
|
|
7
|
+
.replace(/\\u003e/g, '>')
|
|
8
|
+
.replace(/\\n/g, '\n')
|
|
9
|
+
.replace(/\\r/g, '');
|
|
10
|
+
return decoded.replace(/<[^>]+>/g, '').trim();
|
|
11
|
+
}
|
|
12
|
+
export function decodeHtmlEntities(html) {
|
|
13
|
+
if (!html)
|
|
14
|
+
return '';
|
|
15
|
+
return html.replace(/ /g, ' ')
|
|
16
|
+
.replace(/</g, '<')
|
|
17
|
+
.replace(/>/g, '>')
|
|
18
|
+
.replace(/&/g, '&')
|
|
19
|
+
.replace(/"/g, '"')
|
|
20
|
+
.replace(/'/g, "'");
|
|
21
|
+
}
|
|
22
|
+
export function getHupuThreadUrl(tid) {
|
|
23
|
+
return `https://bbs.hupu.com/${encodeURIComponent(String(tid))}-1.html`;
|
|
24
|
+
}
|
|
25
|
+
export function getHupuSearchUrl(query, page, forum, sort) {
|
|
26
|
+
const searchParams = new URLSearchParams();
|
|
27
|
+
searchParams.append('q', String(query));
|
|
28
|
+
searchParams.append('page', String(page));
|
|
29
|
+
if (forum) {
|
|
30
|
+
searchParams.append('topicId', String(forum));
|
|
31
|
+
}
|
|
32
|
+
if (sort) {
|
|
33
|
+
searchParams.append('sortby', String(sort));
|
|
34
|
+
}
|
|
35
|
+
return `https://bbs.hupu.com/search?${searchParams.toString()}`;
|
|
36
|
+
}
|
|
37
|
+
export async function readHupuNextData(page, url, actionLabel, options = {}) {
|
|
38
|
+
await page.goto(url);
|
|
39
|
+
const result = await page.evaluate(`
|
|
40
|
+
(async () => {
|
|
41
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
42
|
+
const expectedTid = ${JSON.stringify(options.expectedTid || '')};
|
|
43
|
+
const timeoutMs = ${JSON.stringify(options.timeoutMs ?? 5000)};
|
|
44
|
+
let lastSeenTid = '';
|
|
45
|
+
let lastSeenHref = '';
|
|
46
|
+
|
|
47
|
+
const waitFor = async (predicate, limitMs = timeoutMs) => {
|
|
48
|
+
const start = Date.now();
|
|
49
|
+
while (Date.now() - start < limitMs) {
|
|
50
|
+
if (predicate()) return true;
|
|
51
|
+
await wait(100);
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const ready = await waitFor(() => {
|
|
57
|
+
const script = document.getElementById('__NEXT_DATA__');
|
|
58
|
+
if (!script?.textContent) return false;
|
|
59
|
+
|
|
60
|
+
lastSeenHref = location.href;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const parsed = JSON.parse(script.textContent);
|
|
64
|
+
const threadTid = parsed?.props?.pageProps?.detail?.thread?.tid;
|
|
65
|
+
lastSeenTid = typeof threadTid === 'string' ? threadTid : '';
|
|
66
|
+
|
|
67
|
+
if (!expectedTid) return true;
|
|
68
|
+
return threadTid === expectedTid;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
if (!ready) {
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
error: expectedTid
|
|
77
|
+
? \`帖子数据未就绪或tid不匹配(expected=\${expectedTid}, actual=\${lastSeenTid || 'unknown'}, href=\${lastSeenHref || location.href})\`
|
|
78
|
+
: '无法找到帖子数据'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const text = document.getElementById('__NEXT_DATA__')?.textContent || '';
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
data: JSON.parse(text)
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
error: error instanceof Error ? error.message : String(error)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
})()
|
|
95
|
+
`);
|
|
96
|
+
if (!result || typeof result !== 'object' || !result.ok) {
|
|
97
|
+
throw new CommandExecutionError(`${actionLabel} failed: ${result?.error || 'invalid browser response'}`);
|
|
98
|
+
}
|
|
99
|
+
return result.data;
|
|
100
|
+
}
|
|
101
|
+
export async function readHupuSearchData(page, url, actionLabel) {
|
|
102
|
+
await page.goto(url);
|
|
103
|
+
const result = await page.evaluate(`
|
|
104
|
+
(async () => {
|
|
105
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
106
|
+
const waitFor = async (predicate, timeoutMs = 5000) => {
|
|
107
|
+
const start = Date.now();
|
|
108
|
+
while (Date.now() - start < timeoutMs) {
|
|
109
|
+
if (predicate()) return true;
|
|
110
|
+
await wait(100);
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const extractFromScript = () => {
|
|
116
|
+
const marker = 'window.$$data=';
|
|
117
|
+
for (const script of Array.from(document.scripts)) {
|
|
118
|
+
const text = script.textContent || '';
|
|
119
|
+
const dataIndex = text.indexOf(marker);
|
|
120
|
+
if (dataIndex === -1) continue;
|
|
121
|
+
|
|
122
|
+
const jsonStart = dataIndex + marker.length;
|
|
123
|
+
let braceCount = 0;
|
|
124
|
+
let jsonEnd = jsonStart;
|
|
125
|
+
let inString = false;
|
|
126
|
+
let escapeNext = false;
|
|
127
|
+
|
|
128
|
+
for (let i = jsonStart; i < text.length; i++) {
|
|
129
|
+
const char = text[i];
|
|
130
|
+
|
|
131
|
+
if (escapeNext) {
|
|
132
|
+
escapeNext = false;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (char === '\\\\') {
|
|
137
|
+
escapeNext = true;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (char === '"') {
|
|
142
|
+
inString = !inString;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!inString) {
|
|
147
|
+
if (char === '{') {
|
|
148
|
+
braceCount++;
|
|
149
|
+
} else if (char === '}') {
|
|
150
|
+
braceCount--;
|
|
151
|
+
if (braceCount === 0) {
|
|
152
|
+
jsonEnd = i;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (jsonEnd > jsonStart) {
|
|
160
|
+
return text.substring(jsonStart, jsonEnd + 1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return '';
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const ready = await waitFor(() => {
|
|
167
|
+
return typeof window.$$data !== 'undefined' || Boolean(extractFromScript());
|
|
168
|
+
});
|
|
169
|
+
if (!ready) {
|
|
170
|
+
return { ok: false, error: '无法找到搜索数据' };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
if (typeof window.$$data !== 'undefined') {
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
data: JSON.parse(JSON.stringify(window.$$data))
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const jsonString = extractFromScript();
|
|
182
|
+
return {
|
|
183
|
+
ok: true,
|
|
184
|
+
data: JSON.parse(jsonString)
|
|
185
|
+
};
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return {
|
|
188
|
+
ok: false,
|
|
189
|
+
error: error instanceof Error ? error.message : String(error)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
})()
|
|
193
|
+
`);
|
|
194
|
+
if (!result || typeof result !== 'object' || !result.ok) {
|
|
195
|
+
throw new CommandExecutionError(`${actionLabel} failed: ${result?.error || 'invalid browser response'}`);
|
|
196
|
+
}
|
|
197
|
+
return result.data;
|
|
198
|
+
}
|
|
199
|
+
function buildBrowserJsonPostScript(apiUrl, body, mode) {
|
|
200
|
+
return `
|
|
201
|
+
(async () => {
|
|
202
|
+
const url = ${JSON.stringify(apiUrl)};
|
|
203
|
+
const payload = ${JSON.stringify(body)};
|
|
204
|
+
const mode = ${JSON.stringify(mode)};
|
|
205
|
+
const getCookie = (name) => document.cookie
|
|
206
|
+
.split('; ')
|
|
207
|
+
.find((item) => item.startsWith(name + '='))
|
|
208
|
+
?.slice(name.length + 1) || '';
|
|
209
|
+
|
|
210
|
+
const findThumbcacheValue = () => {
|
|
211
|
+
const rawEntry = document.cookie
|
|
212
|
+
.split('; ')
|
|
213
|
+
.find((item) => item.startsWith('.thumbcache_'));
|
|
214
|
+
if (rawEntry && rawEntry.includes('=')) {
|
|
215
|
+
const rawValue = rawEntry.slice(rawEntry.indexOf('=') + 1);
|
|
216
|
+
try {
|
|
217
|
+
return decodeURIComponent(rawValue);
|
|
218
|
+
} catch {
|
|
219
|
+
return rawValue;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const storageKey = Object.keys(localStorage).find((key) => key.startsWith('.thumbcache_'));
|
|
224
|
+
if (!storageKey) return '';
|
|
225
|
+
return localStorage.getItem(storageKey) || '';
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const resolveDefaultPayload = (input) => {
|
|
229
|
+
const next = { ...input };
|
|
230
|
+
const sensorsRaw = decodeURIComponent(getCookie('sensorsdata2015jssdkcross') || '');
|
|
231
|
+
let deviceid = '';
|
|
232
|
+
try {
|
|
233
|
+
const sensors = JSON.parse(sensorsRaw);
|
|
234
|
+
deviceid = sensors?.props?.['$device_id'] || sensors?.distinct_id || '';
|
|
235
|
+
} catch {}
|
|
236
|
+
|
|
237
|
+
if ((next.puid === '' || next.puid == null) && getCookie('ua')) {
|
|
238
|
+
next.puid = getCookie('ua');
|
|
239
|
+
}
|
|
240
|
+
if ((next.shumei_id === '' || next.shumei_id == null) && getCookie('smidV2')) {
|
|
241
|
+
next.shumei_id = getCookie('smidV2');
|
|
242
|
+
}
|
|
243
|
+
if ((next.deviceid === '' || next.deviceid == null) && deviceid) {
|
|
244
|
+
next.deviceid = deviceid;
|
|
245
|
+
}
|
|
246
|
+
return next;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const resolveReplyPayload = (input) => {
|
|
250
|
+
const next = { ...input };
|
|
251
|
+
const thumbcache = findThumbcacheValue();
|
|
252
|
+
if ((next.shumeiId === '' || next.shumeiId == null) && thumbcache) {
|
|
253
|
+
next.shumeiId = thumbcache;
|
|
254
|
+
}
|
|
255
|
+
if ((next.deviceid === '' || next.deviceid == null) && thumbcache) {
|
|
256
|
+
next.deviceid = thumbcache;
|
|
257
|
+
}
|
|
258
|
+
return next;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const resolvedPayload = mode === 'reply'
|
|
262
|
+
? resolveReplyPayload(payload)
|
|
263
|
+
: resolveDefaultPayload(payload);
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
const response = await fetch(url, {
|
|
267
|
+
method: 'POST',
|
|
268
|
+
credentials: 'include',
|
|
269
|
+
headers: {
|
|
270
|
+
'Content-Type': 'application/json'
|
|
271
|
+
},
|
|
272
|
+
body: JSON.stringify(resolvedPayload)
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const text = await response.text();
|
|
276
|
+
let data = null;
|
|
277
|
+
try {
|
|
278
|
+
data = text ? JSON.parse(text) : null;
|
|
279
|
+
} catch {
|
|
280
|
+
data = text ? { message: text } : null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
ok: response.ok,
|
|
285
|
+
status: response.status,
|
|
286
|
+
data
|
|
287
|
+
};
|
|
288
|
+
} catch (error) {
|
|
289
|
+
return {
|
|
290
|
+
ok: false,
|
|
291
|
+
error: error instanceof Error ? error.message : String(error)
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
})()
|
|
295
|
+
`;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Execute authenticated Hupu JSON requests inside the browser page so
|
|
299
|
+
* cookies and the thread referer come from the live logged-in session.
|
|
300
|
+
*/
|
|
301
|
+
export async function postHupuJson(page, tid, apiUrl, body, actionLabel, mode = 'default') {
|
|
302
|
+
const referer = getHupuThreadUrl(tid);
|
|
303
|
+
await page.goto(referer);
|
|
304
|
+
const result = await page.evaluate(buildBrowserJsonPostScript(apiUrl, body, mode));
|
|
305
|
+
if (!result || typeof result !== 'object') {
|
|
306
|
+
throw new CommandExecutionError(`${actionLabel} failed: invalid browser response`);
|
|
307
|
+
}
|
|
308
|
+
if (result.status === 401 || result.status === 403) {
|
|
309
|
+
throw new AuthRequiredError('bbs.hupu.com', `${actionLabel} failed: please log in to Hupu first`);
|
|
310
|
+
}
|
|
311
|
+
if (result.error) {
|
|
312
|
+
throw new CommandExecutionError(`${actionLabel} failed: ${result.error}`);
|
|
313
|
+
}
|
|
314
|
+
if (!result.ok) {
|
|
315
|
+
const detail = result.data?.msg || result.data?.message || `HTTP ${result.status ?? 'unknown'}`;
|
|
316
|
+
throw new CommandExecutionError(`${actionLabel} failed: ${detail}`);
|
|
317
|
+
}
|
|
318
|
+
return result.data ?? {};
|
|
319
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { IPage } from '../../../types.js';
|
|
2
|
+
import type { InstagramProtocolCaptureEntry } from './protocol-capture.js';
|
|
3
|
+
export { buildReadInstagramRuntimeInfoJs, extractInstagramRuntimeInfo, type InstagramRuntimeInfo, resolveInstagramRuntimeInfo, } from './runtime-info.js';
|
|
4
|
+
export interface InstagramPrivateApiContext {
|
|
5
|
+
asbdId: string;
|
|
6
|
+
csrfToken: string;
|
|
7
|
+
igAppId: string;
|
|
8
|
+
igWwwClaim: string;
|
|
9
|
+
instagramAjax: string;
|
|
10
|
+
webSessionId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface InstagramImageAsset {
|
|
13
|
+
filePath: string;
|
|
14
|
+
fileName: string;
|
|
15
|
+
mimeType: string;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
byteLength: number;
|
|
19
|
+
bytes: Buffer;
|
|
20
|
+
}
|
|
21
|
+
export interface PreparedInstagramImageAsset extends InstagramImageAsset {
|
|
22
|
+
cleanupPath?: string;
|
|
23
|
+
}
|
|
24
|
+
export type InstagramMediaKind = 'image' | 'video';
|
|
25
|
+
export interface InstagramMediaItem {
|
|
26
|
+
type: InstagramMediaKind;
|
|
27
|
+
filePath: string;
|
|
28
|
+
}
|
|
29
|
+
export interface InstagramVideoAsset {
|
|
30
|
+
filePath: string;
|
|
31
|
+
fileName: string;
|
|
32
|
+
mimeType: string;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
durationMs: number;
|
|
36
|
+
byteLength: number;
|
|
37
|
+
bytes: Buffer;
|
|
38
|
+
coverImage: PreparedInstagramImageAsset;
|
|
39
|
+
cleanupPaths?: string[];
|
|
40
|
+
}
|
|
41
|
+
export type PreparedInstagramMediaAsset = {
|
|
42
|
+
type: 'image';
|
|
43
|
+
asset: PreparedInstagramImageAsset;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'video';
|
|
46
|
+
asset: InstagramVideoAsset;
|
|
47
|
+
};
|
|
48
|
+
type StoryPayloadInput = {
|
|
49
|
+
uploadId: string;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
now?: () => number;
|
|
53
|
+
jazoest: string;
|
|
54
|
+
};
|
|
55
|
+
type StoryVideoPayloadInput = StoryPayloadInput & {
|
|
56
|
+
durationMs: number;
|
|
57
|
+
};
|
|
58
|
+
type PrivateApiFetchInit = {
|
|
59
|
+
method?: string;
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
body?: unknown;
|
|
62
|
+
};
|
|
63
|
+
type PrivateApiFetchLike = (url: string | URL, init?: PrivateApiFetchInit) => Promise<Response>;
|
|
64
|
+
export declare function derivePrivateApiContextFromCapture(entries: InstagramProtocolCaptureEntry[]): InstagramPrivateApiContext | null;
|
|
65
|
+
export declare function deriveInstagramJazoest(value: string): string;
|
|
66
|
+
export declare function resolveInstagramPrivatePublishConfig(page: IPage): Promise<{
|
|
67
|
+
apiContext: InstagramPrivateApiContext;
|
|
68
|
+
jazoest: string;
|
|
69
|
+
}>;
|
|
70
|
+
export declare function buildConfigureBody(input: {
|
|
71
|
+
uploadId: string;
|
|
72
|
+
caption: string;
|
|
73
|
+
jazoest: string;
|
|
74
|
+
}): string;
|
|
75
|
+
export declare function buildConfigureSidecarPayload(input: {
|
|
76
|
+
uploadIds: string[];
|
|
77
|
+
caption: string;
|
|
78
|
+
clientSidecarId: string;
|
|
79
|
+
jazoest: string;
|
|
80
|
+
}): Record<string, unknown>;
|
|
81
|
+
export declare function readImageAsset(filePath: string): InstagramImageAsset;
|
|
82
|
+
export declare function isInstagramFeedAspectRatioAllowed(width: number, height: number): boolean;
|
|
83
|
+
export declare function getInstagramFeedNormalizedDimensions(width: number, height: number): {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
} | null;
|
|
87
|
+
export declare function isInstagramStoryAspectRatioAllowed(width: number, height: number): boolean;
|
|
88
|
+
export declare function getInstagramStoryNormalizedDimensions(width: number, height: number): {
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
} | null;
|
|
92
|
+
export declare function prepareImageAssetForPrivateUpload(filePath: string): PreparedInstagramImageAsset;
|
|
93
|
+
export declare function prepareImageAssetForPrivateStoryUpload(filePath: string): PreparedInstagramImageAsset;
|
|
94
|
+
export declare function readVideoAsset(filePath: string): InstagramVideoAsset;
|
|
95
|
+
export declare function buildConfigureToStoryPhotoPayload(input: StoryPayloadInput): Record<string, unknown>;
|
|
96
|
+
export declare function buildConfigureToStoryVideoPayload(input: StoryVideoPayloadInput): Record<string, unknown>;
|
|
97
|
+
export declare function publishMediaViaPrivateApi(input: {
|
|
98
|
+
page: unknown;
|
|
99
|
+
mediaItems: InstagramMediaItem[];
|
|
100
|
+
caption: string;
|
|
101
|
+
apiContext: InstagramPrivateApiContext;
|
|
102
|
+
jazoest: string;
|
|
103
|
+
now?: () => number;
|
|
104
|
+
fetcher?: PrivateApiFetchLike;
|
|
105
|
+
prepareMediaAsset?: (item: InstagramMediaItem) => PreparedInstagramMediaAsset | Promise<PreparedInstagramMediaAsset>;
|
|
106
|
+
waitMs?: (ms: number) => Promise<void>;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
code?: string;
|
|
109
|
+
uploadIds: string[];
|
|
110
|
+
}>;
|
|
111
|
+
export declare function publishImagesViaPrivateApi(input: {
|
|
112
|
+
page: unknown;
|
|
113
|
+
imagePaths: string[];
|
|
114
|
+
caption: string;
|
|
115
|
+
apiContext: InstagramPrivateApiContext;
|
|
116
|
+
jazoest: string;
|
|
117
|
+
now?: () => number;
|
|
118
|
+
fetcher?: PrivateApiFetchLike;
|
|
119
|
+
prepareAsset?: (filePath: string) => PreparedInstagramImageAsset | Promise<PreparedInstagramImageAsset>;
|
|
120
|
+
waitMs?: (ms: number) => Promise<void>;
|
|
121
|
+
}): Promise<{
|
|
122
|
+
code?: string;
|
|
123
|
+
uploadIds: string[];
|
|
124
|
+
}>;
|
|
125
|
+
export declare function publishStoryViaPrivateApi(input: {
|
|
126
|
+
page: unknown;
|
|
127
|
+
mediaItem: InstagramMediaItem;
|
|
128
|
+
content: string;
|
|
129
|
+
apiContext: InstagramPrivateApiContext;
|
|
130
|
+
jazoest: string;
|
|
131
|
+
currentUserId?: string;
|
|
132
|
+
now?: () => number;
|
|
133
|
+
fetcher?: PrivateApiFetchLike;
|
|
134
|
+
prepareMediaAsset?: (item: InstagramMediaItem) => PreparedInstagramMediaAsset | Promise<PreparedInstagramMediaAsset>;
|
|
135
|
+
}): Promise<{
|
|
136
|
+
mediaPk?: string;
|
|
137
|
+
uploadId: string;
|
|
138
|
+
}>;
|