@jackwener/opencli 1.5.6 → 1.5.7
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 +26 -0
- package/README.md +4 -2
- package/README.zh-CN.md +4 -1
- package/SKILL.md +879 -0
- package/dist/browser/cdp.d.ts +1 -0
- package/dist/browser/cdp.js +30 -27
- package/dist/browser/daemon-client.d.ts +7 -1
- package/dist/browser/daemon-client.js +3 -0
- package/dist/browser/dom-helpers.js +1 -0
- package/dist/browser/dom-helpers.test.js +14 -1
- package/dist/browser/mcp.js +18 -13
- package/dist/browser/page.js +22 -2
- package/dist/browser/page.test.d.ts +1 -0
- package/dist/browser/page.test.js +44 -0
- package/dist/browser/stealth.js +198 -0
- package/dist/browser/stealth.test.d.ts +1 -0
- package/dist/browser/stealth.test.js +134 -0
- package/dist/browser.test.js +1 -1
- package/dist/build-manifest.d.ts +1 -0
- package/dist/build-manifest.js +5 -1
- package/dist/build-manifest.test.js +2 -0
- package/dist/cli-manifest.json +544 -137
- package/dist/cli.js +20 -3
- package/dist/clis/antigravity/serve.d.ts +1 -1
- package/dist/clis/antigravity/serve.js +5 -8
- package/dist/clis/bilibili/subtitle.js +4 -0
- package/dist/clis/bilibili/subtitle.test.d.ts +1 -0
- package/dist/clis/bilibili/subtitle.test.js +48 -0
- package/dist/clis/chatwise/ask.js +0 -2
- package/dist/clis/chatwise/export.js +0 -2
- package/dist/clis/chatwise/history.js +0 -2
- package/dist/clis/chatwise/model.js +0 -2
- package/dist/clis/chatwise/new.js +1 -2
- package/dist/clis/chatwise/read.js +0 -2
- package/dist/clis/chatwise/screenshot.js +1 -2
- package/dist/clis/chatwise/send.js +0 -2
- package/dist/clis/chatwise/status.js +1 -2
- package/dist/clis/ctrip/search.d.ts +13 -0
- package/dist/clis/ctrip/search.js +73 -48
- package/dist/clis/ctrip/search.test.d.ts +1 -0
- package/dist/clis/ctrip/search.test.js +64 -0
- package/dist/clis/douyin/_shared/sts2.js +8 -2
- package/dist/clis/douyin/_shared/sts2.test.d.ts +1 -0
- package/dist/clis/douyin/_shared/sts2.test.js +27 -0
- package/dist/clis/douyin/activities.js +4 -2
- package/dist/clis/douyin/activities.test.js +34 -1
- package/dist/clis/douyin/collections.js +1 -1
- package/dist/clis/douyin/collections.test.js +24 -2
- package/dist/clis/douyin/draft.d.ts +8 -11
- package/dist/clis/douyin/draft.js +302 -185
- package/dist/clis/douyin/draft.test.d.ts +1 -1
- package/dist/clis/douyin/draft.test.js +357 -2
- package/dist/clis/douyin/hashtag.js +9 -2
- package/dist/clis/douyin/hashtag.test.js +35 -2
- package/dist/clis/douyin/profile.js +1 -1
- package/dist/clis/douyin/profile.test.js +36 -1
- package/dist/clis/douyin/videos.js +22 -5
- package/dist/clis/douyin/videos.test.js +45 -2
- package/dist/clis/facebook/search.test.d.ts +5 -0
- package/dist/clis/facebook/search.test.js +60 -0
- package/dist/clis/facebook/search.yaml +4 -3
- package/dist/clis/instagram/download.d.ts +16 -0
- package/dist/clis/instagram/download.js +225 -0
- package/dist/clis/instagram/download.test.d.ts +1 -0
- package/dist/clis/instagram/download.test.js +118 -0
- package/dist/clis/notebooklm/bind-current.d.ts +1 -0
- package/dist/clis/notebooklm/bind-current.js +29 -0
- package/dist/clis/notebooklm/bind-current.test.d.ts +1 -0
- package/dist/clis/notebooklm/bind-current.test.js +35 -0
- package/dist/clis/notebooklm/binding.test.d.ts +1 -0
- package/dist/clis/notebooklm/binding.test.js +44 -0
- package/dist/clis/notebooklm/compat.test.d.ts +3 -0
- package/dist/clis/notebooklm/compat.test.js +16 -0
- package/dist/clis/notebooklm/current.d.ts +1 -0
- package/dist/clis/notebooklm/current.js +28 -0
- package/dist/clis/notebooklm/get.d.ts +1 -0
- package/dist/clis/notebooklm/get.js +37 -0
- package/dist/clis/notebooklm/history.d.ts +1 -0
- package/dist/clis/notebooklm/history.js +25 -0
- package/dist/clis/notebooklm/history.test.d.ts +1 -0
- package/dist/clis/notebooklm/history.test.js +58 -0
- package/dist/clis/notebooklm/list.d.ts +1 -0
- package/dist/clis/notebooklm/list.js +35 -0
- package/dist/clis/notebooklm/note-list.d.ts +1 -0
- package/dist/clis/notebooklm/note-list.js +28 -0
- package/dist/clis/notebooklm/note-list.test.d.ts +1 -0
- package/dist/clis/notebooklm/note-list.test.js +56 -0
- package/dist/clis/notebooklm/notes-get.d.ts +1 -0
- package/dist/clis/notebooklm/notes-get.js +47 -0
- package/dist/clis/notebooklm/notes-get.test.d.ts +1 -0
- package/dist/clis/notebooklm/notes-get.test.js +72 -0
- package/dist/clis/notebooklm/rpc.d.ts +36 -0
- package/dist/clis/notebooklm/rpc.js +189 -0
- package/dist/clis/notebooklm/rpc.test.d.ts +1 -0
- package/dist/clis/notebooklm/rpc.test.js +105 -0
- package/dist/clis/notebooklm/shared.d.ts +87 -0
- package/dist/clis/notebooklm/shared.js +3 -0
- package/dist/clis/notebooklm/source-fulltext.d.ts +1 -0
- package/dist/clis/notebooklm/source-fulltext.js +44 -0
- package/dist/clis/notebooklm/source-fulltext.test.d.ts +1 -0
- package/dist/clis/notebooklm/source-fulltext.test.js +106 -0
- package/dist/clis/notebooklm/source-get.d.ts +1 -0
- package/dist/clis/notebooklm/source-get.js +40 -0
- package/dist/clis/notebooklm/source-get.test.d.ts +1 -0
- package/dist/clis/notebooklm/source-get.test.js +84 -0
- package/dist/clis/notebooklm/source-guide.d.ts +1 -0
- package/dist/clis/notebooklm/source-guide.js +44 -0
- package/dist/clis/notebooklm/source-guide.test.d.ts +1 -0
- package/dist/clis/notebooklm/source-guide.test.js +104 -0
- package/dist/clis/notebooklm/source-list.d.ts +1 -0
- package/dist/clis/notebooklm/source-list.js +30 -0
- package/dist/clis/notebooklm/status.d.ts +1 -0
- package/dist/clis/notebooklm/status.js +31 -0
- package/dist/clis/notebooklm/summary.d.ts +1 -0
- package/dist/clis/notebooklm/summary.js +30 -0
- package/dist/clis/notebooklm/summary.test.d.ts +1 -0
- package/dist/clis/notebooklm/summary.test.js +78 -0
- package/dist/clis/notebooklm/utils.d.ts +37 -0
- package/dist/clis/notebooklm/utils.js +739 -0
- package/dist/clis/notebooklm/utils.test.d.ts +1 -0
- package/dist/clis/notebooklm/utils.test.js +390 -0
- package/dist/clis/substack/utils.d.ts +4 -0
- package/dist/clis/substack/utils.js +8 -2
- package/dist/clis/substack/utils.test.d.ts +1 -0
- package/dist/clis/substack/utils.test.js +46 -0
- package/dist/clis/v2ex/hot.yaml +4 -1
- package/dist/clis/v2ex/latest.yaml +4 -1
- package/dist/clis/v2ex/topic.yaml +6 -1
- package/dist/clis/weixin/download.d.ts +9 -0
- package/dist/clis/weixin/download.js +76 -6
- package/dist/clis/weread/book.js +108 -2
- package/dist/clis/weread/commands.test.js +262 -152
- package/dist/clis/weread/utils.d.ts +10 -0
- package/dist/clis/weread/utils.js +27 -7
- package/dist/clis/xiaohongshu/comments.d.ts +3 -0
- package/dist/clis/xiaohongshu/comments.js +76 -17
- package/dist/clis/xiaohongshu/comments.test.js +70 -9
- package/dist/clis/xiaohongshu/download.d.ts +4 -1
- package/dist/clis/xiaohongshu/download.js +83 -22
- package/dist/clis/xiaohongshu/download.test.d.ts +1 -0
- package/dist/clis/xiaohongshu/download.test.js +75 -0
- package/dist/clis/xiaohongshu/note-helpers.d.ts +12 -0
- package/dist/clis/xiaohongshu/note-helpers.js +23 -0
- package/dist/clis/xiaohongshu/note.d.ts +7 -0
- package/dist/clis/xiaohongshu/note.js +76 -0
- package/dist/clis/xiaohongshu/note.test.d.ts +1 -0
- package/dist/clis/xiaohongshu/note.test.js +136 -0
- package/dist/clis/xiaohongshu/search.js +9 -0
- package/dist/clis/xiaohongshu/search.test.js +10 -4
- package/dist/clis/youtube/search.js +57 -17
- package/dist/clis/zhihu/question.js +19 -17
- package/dist/clis/zhihu/question.test.d.ts +1 -0
- package/dist/clis/zhihu/question.test.js +54 -0
- package/dist/commanderAdapter.js +9 -0
- package/dist/commanderAdapter.test.js +25 -0
- package/dist/commands/daemon.d.ts +9 -0
- package/dist/commands/daemon.js +124 -0
- package/dist/commands/daemon.test.d.ts +1 -0
- package/dist/commands/daemon.test.js +185 -0
- package/dist/completion.js +3 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/daemon.d.ts +1 -1
- package/dist/daemon.js +25 -14
- package/dist/daemon.test.d.ts +1 -0
- package/dist/daemon.test.js +65 -0
- package/dist/discovery.d.ts +9 -0
- package/dist/discovery.js +47 -2
- package/dist/electron-apps.d.ts +29 -0
- package/dist/electron-apps.js +65 -0
- package/dist/electron-apps.test.d.ts +1 -0
- package/dist/electron-apps.test.js +43 -0
- package/dist/engine.test.js +41 -9
- package/dist/execution.js +20 -16
- package/dist/idle-manager.d.ts +19 -0
- package/dist/idle-manager.js +54 -0
- package/dist/launcher.d.ts +36 -0
- package/dist/launcher.js +152 -0
- package/dist/launcher.test.d.ts +1 -0
- package/dist/launcher.test.js +57 -0
- package/dist/main.js +3 -3
- package/dist/registry.d.ts +1 -0
- package/dist/registry.js +31 -3
- package/dist/registry.test.js +13 -0
- package/dist/runtime.d.ts +5 -3
- package/dist/runtime.js +12 -5
- package/dist/serialization.d.ts +1 -0
- package/dist/serialization.js +3 -0
- package/dist/serialization.test.js +17 -1
- package/dist/tui.d.ts +7 -0
- package/dist/tui.js +52 -0
- package/dist/tui.test.d.ts +1 -0
- package/dist/tui.test.js +19 -0
- package/dist/weixin-download.test.js +14 -0
- package/docs/.vitepress/config.mts +1 -0
- package/docs/adapters/browser/notebooklm.md +69 -0
- package/docs/adapters/browser/xiaohongshu.md +19 -10
- package/docs/adapters/index.md +67 -66
- package/docs/guide/browser-bridge.md +12 -0
- package/docs/guide/troubleshooting.md +9 -4
- package/docs/superpowers/plans/2026-03-31-daemon-lifecycle-redesign.md +857 -0
- package/docs/superpowers/specs/2026-03-31-daemon-lifecycle-redesign.md +208 -0
- package/docs/zh/guide/browser-bridge.md +12 -0
- package/extension/dist/background.js +794 -513
- package/extension/src/background.test.ts +202 -2
- package/extension/src/background.ts +174 -10
- package/extension/src/cdp.ts +12 -0
- package/extension/src/protocol.ts +7 -5
- package/package.json +1 -1
- package/src/browser/cdp.ts +24 -17
- package/src/browser/daemon-client.ts +7 -1
- package/src/browser/dom-helpers.test.ts +15 -1
- package/src/browser/dom-helpers.ts +1 -0
- package/src/browser/mcp.ts +18 -13
- package/src/browser/page.test.ts +58 -0
- package/src/browser/page.ts +18 -2
- package/src/browser/stealth.test.ts +153 -0
- package/src/browser/stealth.ts +198 -0
- package/src/browser.test.ts +1 -1
- package/src/build-manifest.test.ts +2 -0
- package/src/build-manifest.ts +6 -1
- package/src/cli.ts +21 -3
- package/src/clis/antigravity/SKILL.md +3 -12
- package/src/clis/antigravity/serve.ts +5 -10
- package/src/clis/bilibili/subtitle.test.ts +60 -0
- package/src/clis/bilibili/subtitle.ts +4 -0
- package/src/clis/chatwise/ask.ts +0 -2
- package/src/clis/chatwise/export.ts +0 -2
- package/src/clis/chatwise/history.ts +0 -2
- package/src/clis/chatwise/model.ts +0 -2
- package/src/clis/chatwise/new.ts +1 -2
- package/src/clis/chatwise/read.ts +0 -2
- package/src/clis/chatwise/screenshot.ts +1 -2
- package/src/clis/chatwise/send.ts +0 -2
- package/src/clis/chatwise/status.ts +1 -2
- package/src/clis/ctrip/search.test.ts +73 -0
- package/src/clis/ctrip/search.ts +97 -47
- package/src/clis/douyin/_shared/sts2.test.ts +31 -0
- package/src/clis/douyin/_shared/sts2.ts +11 -3
- package/src/clis/douyin/activities.test.ts +41 -1
- package/src/clis/douyin/activities.ts +12 -3
- package/src/clis/douyin/collections.test.ts +35 -2
- package/src/clis/douyin/collections.ts +1 -1
- package/src/clis/douyin/draft.test.ts +444 -2
- package/src/clis/douyin/draft.ts +382 -218
- package/src/clis/douyin/hashtag.test.ts +42 -2
- package/src/clis/douyin/hashtag.ts +11 -3
- package/src/clis/douyin/profile.test.ts +43 -1
- package/src/clis/douyin/profile.ts +9 -2
- package/src/clis/douyin/videos.test.ts +52 -2
- package/src/clis/douyin/videos.ts +49 -15
- package/src/clis/facebook/search.test.ts +70 -0
- package/src/clis/facebook/search.yaml +4 -3
- package/src/clis/instagram/download.test.ts +159 -0
- package/src/clis/instagram/download.ts +286 -0
- package/src/clis/notebooklm/bind-current.test.ts +43 -0
- package/src/clis/notebooklm/bind-current.ts +36 -0
- package/src/clis/notebooklm/binding.test.ts +53 -0
- package/src/clis/notebooklm/compat.test.ts +19 -0
- package/src/clis/notebooklm/current.ts +38 -0
- package/src/clis/notebooklm/get.ts +53 -0
- package/src/clis/notebooklm/history.test.ts +70 -0
- package/src/clis/notebooklm/history.ts +36 -0
- package/src/clis/notebooklm/list.ts +40 -0
- package/src/clis/notebooklm/note-list.test.ts +64 -0
- package/src/clis/notebooklm/note-list.ts +42 -0
- package/src/clis/notebooklm/notes-get.test.ts +88 -0
- package/src/clis/notebooklm/notes-get.ts +67 -0
- package/src/clis/notebooklm/rpc.test.ts +126 -0
- package/src/clis/notebooklm/rpc.ts +286 -0
- package/src/clis/notebooklm/shared.ts +98 -0
- package/src/clis/notebooklm/source-fulltext.test.ts +123 -0
- package/src/clis/notebooklm/source-fulltext.ts +69 -0
- package/src/clis/notebooklm/source-get.test.ts +100 -0
- package/src/clis/notebooklm/source-get.ts +60 -0
- package/src/clis/notebooklm/source-guide.test.ts +121 -0
- package/src/clis/notebooklm/source-guide.ts +69 -0
- package/src/clis/notebooklm/source-list.ts +45 -0
- package/src/clis/notebooklm/status.ts +34 -0
- package/src/clis/notebooklm/summary.test.ts +94 -0
- package/src/clis/notebooklm/summary.ts +45 -0
- package/src/clis/notebooklm/utils.test.ts +446 -0
- package/src/clis/notebooklm/utils.ts +893 -0
- package/src/clis/substack/utils.test.ts +54 -0
- package/src/clis/substack/utils.ts +10 -2
- package/src/clis/v2ex/hot.yaml +4 -1
- package/src/clis/v2ex/latest.yaml +4 -1
- package/src/clis/v2ex/topic.yaml +6 -1
- package/src/clis/weixin/download.ts +95 -6
- package/src/clis/weread/book.ts +142 -2
- package/src/clis/weread/commands.test.ts +314 -154
- package/src/clis/weread/utils.ts +33 -4
- package/src/clis/xiaohongshu/comments.test.ts +85 -9
- package/src/clis/xiaohongshu/comments.ts +76 -17
- package/src/clis/xiaohongshu/download.test.ts +96 -0
- package/src/clis/xiaohongshu/download.ts +83 -22
- package/src/clis/xiaohongshu/note-helpers.ts +25 -0
- package/src/clis/xiaohongshu/note.test.ts +164 -0
- package/src/clis/xiaohongshu/note.ts +86 -0
- package/src/clis/xiaohongshu/search.test.ts +11 -4
- package/src/clis/xiaohongshu/search.ts +13 -0
- package/src/clis/youtube/search.ts +57 -17
- package/src/clis/zhihu/question.test.ts +71 -0
- package/src/clis/zhihu/question.ts +27 -15
- package/src/commanderAdapter.test.ts +30 -0
- package/src/commanderAdapter.ts +7 -0
- package/src/commands/daemon.test.ts +238 -0
- package/src/commands/daemon.ts +135 -0
- package/src/completion.ts +2 -1
- package/src/constants.ts +3 -0
- package/src/daemon.test.ts +88 -0
- package/src/daemon.ts +26 -14
- package/src/discovery.ts +52 -2
- package/src/electron-apps.test.ts +50 -0
- package/src/electron-apps.ts +89 -0
- package/src/engine.test.ts +45 -9
- package/src/execution.ts +24 -19
- package/src/idle-manager.ts +60 -0
- package/src/launcher.test.ts +67 -0
- package/src/launcher.ts +185 -0
- package/src/main.ts +3 -2
- package/src/registry.test.ts +15 -0
- package/src/registry.ts +32 -3
- package/src/runtime.ts +13 -7
- package/src/serialization.test.ts +19 -1
- package/src/serialization.ts +2 -0
- package/src/tui.test.ts +23 -0
- package/src/tui.ts +65 -0
- package/src/weixin-download.test.ts +27 -0
- package/tests/e2e/browser-public-extended.test.ts +6 -2
- package/chatwise-opencli.ps1 +0 -82
- package/dist/clis/chatwise/shared.d.ts +0 -2
- package/dist/clis/chatwise/shared.js +0 -6
- package/src/clis/chatwise/shared.ts +0 -8
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const { browserFetchMock } = vi.hoisted(() => ({
|
|
4
|
+
browserFetchMock: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock('./_shared/browser-fetch.js', () => ({
|
|
8
|
+
browserFetch: browserFetchMock,
|
|
9
|
+
}));
|
|
10
|
+
|
|
2
11
|
import { getRegistry } from '../../registry.js';
|
|
3
12
|
import './hashtag.js';
|
|
4
13
|
|
|
5
|
-
describe('douyin hashtag
|
|
14
|
+
describe('douyin hashtag', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
browserFetchMock.mockReset();
|
|
17
|
+
});
|
|
18
|
+
|
|
6
19
|
it('registers the hashtag command', () => {
|
|
7
20
|
const registry = getRegistry();
|
|
8
21
|
const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'hashtag');
|
|
@@ -25,4 +38,31 @@ describe('douyin hashtag registration', () => {
|
|
|
25
38
|
const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'hashtag');
|
|
26
39
|
expect(cmd?.strategy).toBe('cookie');
|
|
27
40
|
});
|
|
41
|
+
|
|
42
|
+
it('parses the current hotspot recommendation shape', async () => {
|
|
43
|
+
const registry = getRegistry();
|
|
44
|
+
const command = [...registry.values()].find((cmd) => cmd.site === 'douyin' && cmd.name === 'hashtag');
|
|
45
|
+
expect(command?.func).toBeDefined();
|
|
46
|
+
if (!command?.func) throw new Error('douyin hashtag command not registered');
|
|
47
|
+
|
|
48
|
+
browserFetchMock.mockResolvedValueOnce({
|
|
49
|
+
all_sentences: [
|
|
50
|
+
{
|
|
51
|
+
word: '在公园花海里大晒一场',
|
|
52
|
+
hot_value: 12141172,
|
|
53
|
+
sentence_id: '2448416',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const rows = await command.func({} as any, { action: 'hot', keyword: '', limit: 5 });
|
|
59
|
+
|
|
60
|
+
expect(rows).toEqual([
|
|
61
|
+
{
|
|
62
|
+
name: '在公园花海里大晒一场',
|
|
63
|
+
id: '2448416',
|
|
64
|
+
view_count: 12141172,
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
28
68
|
});
|
|
@@ -42,11 +42,19 @@ cli({
|
|
|
42
42
|
const kw = kwargs.keyword as string;
|
|
43
43
|
const url = `https://creator.douyin.com/aweme/v1/hotspot/recommend/?${kw ? `keyword=${encodeURIComponent(kw)}&` : ''}aid=1128`;
|
|
44
44
|
const res = await browserFetch(page, 'GET', url) as {
|
|
45
|
-
hotspot_list
|
|
45
|
+
hotspot_list?: Array<{ sentence: string; hot_value: number }>;
|
|
46
|
+
all_sentences?: Array<{ sentence_id?: string; word?: string; hot_value: number }>;
|
|
46
47
|
};
|
|
47
|
-
|
|
48
|
+
const items = res.hotspot_list
|
|
49
|
+
?? res.all_sentences?.map(h => ({
|
|
50
|
+
sentence: h.word ?? '',
|
|
51
|
+
hot_value: h.hot_value,
|
|
52
|
+
sentence_id: h.sentence_id ?? '',
|
|
53
|
+
}))
|
|
54
|
+
?? [];
|
|
55
|
+
return items.slice(0, kwargs.limit as number).map(h => ({
|
|
48
56
|
name: h.sentence,
|
|
49
|
-
id: '',
|
|
57
|
+
id: 'sentence_id' in h ? h.sentence_id : '',
|
|
50
58
|
view_count: h.hot_value,
|
|
51
59
|
}));
|
|
52
60
|
}
|
|
@@ -1,12 +1,54 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const { browserFetchMock } = vi.hoisted(() => ({
|
|
4
|
+
browserFetchMock: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock('./_shared/browser-fetch.js', () => ({
|
|
8
|
+
browserFetch: browserFetchMock,
|
|
9
|
+
}));
|
|
10
|
+
|
|
2
11
|
import { getRegistry } from '../../registry.js';
|
|
3
12
|
import './profile.js';
|
|
4
13
|
|
|
5
14
|
describe('douyin profile registration', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
browserFetchMock.mockReset();
|
|
17
|
+
});
|
|
18
|
+
|
|
6
19
|
it('registers the profile command', () => {
|
|
7
20
|
const registry = getRegistry();
|
|
8
21
|
const values = [...registry.values()];
|
|
9
22
|
const cmd = values.find(c => c.site === 'douyin' && c.name === 'profile');
|
|
10
23
|
expect(cmd).toBeDefined();
|
|
11
24
|
});
|
|
25
|
+
|
|
26
|
+
it('maps the current user payload shape returned by creator center', async () => {
|
|
27
|
+
const registry = getRegistry();
|
|
28
|
+
const cmd = [...registry.values()].find(c => c.site === 'douyin' && c.name === 'profile');
|
|
29
|
+
expect(cmd?.func).toBeDefined();
|
|
30
|
+
if (!cmd?.func) throw new Error('douyin profile command not registered');
|
|
31
|
+
|
|
32
|
+
browserFetchMock.mockResolvedValueOnce({
|
|
33
|
+
user: {
|
|
34
|
+
uid: '100',
|
|
35
|
+
nickname: 'creator',
|
|
36
|
+
follower_count: 12,
|
|
37
|
+
following_count: 3,
|
|
38
|
+
aweme_count: 7,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const rows = await cmd.func({} as never, {});
|
|
43
|
+
|
|
44
|
+
expect(rows).toEqual([
|
|
45
|
+
{
|
|
46
|
+
uid: '100',
|
|
47
|
+
nickname: 'creator',
|
|
48
|
+
follower_count: 12,
|
|
49
|
+
following_count: 3,
|
|
50
|
+
aweme_count: 7,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
12
54
|
});
|
|
@@ -14,7 +14,14 @@ cli({
|
|
|
14
14
|
func: async (page: IPage, _kwargs) => {
|
|
15
15
|
const url = 'https://creator.douyin.com/web/api/media/user/info/?aid=1128';
|
|
16
16
|
const res = (await browserFetch(page, 'GET', url)) as {
|
|
17
|
-
user_info
|
|
17
|
+
user_info?: {
|
|
18
|
+
uid: string;
|
|
19
|
+
nickname: string;
|
|
20
|
+
follower_count: number;
|
|
21
|
+
following_count: number;
|
|
22
|
+
aweme_count: number;
|
|
23
|
+
};
|
|
24
|
+
user?: {
|
|
18
25
|
uid: string;
|
|
19
26
|
nickname: string;
|
|
20
27
|
follower_count: number;
|
|
@@ -22,7 +29,7 @@ cli({
|
|
|
22
29
|
aweme_count: number;
|
|
23
30
|
};
|
|
24
31
|
};
|
|
25
|
-
const u = res.user_info;
|
|
32
|
+
const u = res.user_info ?? res.user;
|
|
26
33
|
if (!u) throw new CommandExecutionError('用户信息获取失败,请确认已登录 creator.douyin.com');
|
|
27
34
|
return [
|
|
28
35
|
{
|
|
@@ -1,12 +1,62 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const { browserFetchMock } = vi.hoisted(() => ({
|
|
4
|
+
browserFetchMock: vi.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
vi.mock('./_shared/browser-fetch.js', () => ({
|
|
8
|
+
browserFetch: browserFetchMock,
|
|
9
|
+
}));
|
|
10
|
+
|
|
2
11
|
import { getRegistry } from '../../registry.js';
|
|
3
12
|
import './videos.js';
|
|
4
13
|
|
|
5
|
-
describe('douyin videos
|
|
14
|
+
describe('douyin videos', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
browserFetchMock.mockReset();
|
|
17
|
+
});
|
|
18
|
+
|
|
6
19
|
it('registers the videos command', () => {
|
|
7
20
|
const registry = getRegistry();
|
|
8
21
|
const values = [...registry.values()];
|
|
9
22
|
const cmd = values.find(c => c.site === 'douyin' && c.name === 'videos');
|
|
10
23
|
expect(cmd).toBeDefined();
|
|
11
24
|
});
|
|
25
|
+
|
|
26
|
+
it('parses the current creator work_list api shape', async () => {
|
|
27
|
+
const registry = getRegistry();
|
|
28
|
+
const command = [...registry.values()].find((cmd) => cmd.site === 'douyin' && cmd.name === 'videos');
|
|
29
|
+
expect(command?.func).toBeDefined();
|
|
30
|
+
if (!command?.func) throw new Error('douyin videos command not registered');
|
|
31
|
+
|
|
32
|
+
browserFetchMock.mockResolvedValueOnce({
|
|
33
|
+
aweme_list: [
|
|
34
|
+
{
|
|
35
|
+
aweme_id: '7000000000000000001',
|
|
36
|
+
desc: '测试视频标题',
|
|
37
|
+
create_time: 1581571130,
|
|
38
|
+
statistics: {
|
|
39
|
+
play_count: 0,
|
|
40
|
+
digg_count: 12,
|
|
41
|
+
},
|
|
42
|
+
status: {
|
|
43
|
+
is_private: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const rows = await command.func({} as any, { limit: 5, page: 1, status: 'all' });
|
|
50
|
+
|
|
51
|
+
expect(rows).toEqual([
|
|
52
|
+
{
|
|
53
|
+
aweme_id: '7000000000000000001',
|
|
54
|
+
title: '测试视频标题',
|
|
55
|
+
status: 'private',
|
|
56
|
+
play_count: 0,
|
|
57
|
+
digg_count: 12,
|
|
58
|
+
create_time: new Date(1581571130 * 1000).toLocaleString('zh-CN', { timeZone: 'Asia/Tokyo' }),
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
});
|
|
12
62
|
});
|
|
@@ -2,6 +2,48 @@ import { cli, Strategy } from '../../registry.js';
|
|
|
2
2
|
import { browserFetch } from './_shared/browser-fetch.js';
|
|
3
3
|
import type { IPage } from '../../types.js';
|
|
4
4
|
|
|
5
|
+
interface LegacyWorkItem {
|
|
6
|
+
aweme_id: string;
|
|
7
|
+
desc: string;
|
|
8
|
+
status: number;
|
|
9
|
+
public_time: number;
|
|
10
|
+
create_time: number;
|
|
11
|
+
statistics: { play_count: number; digg_count: number };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface CurrentWorkItem {
|
|
15
|
+
aweme_id: string;
|
|
16
|
+
desc?: string;
|
|
17
|
+
status?: {
|
|
18
|
+
in_reviewing?: boolean;
|
|
19
|
+
is_private?: boolean;
|
|
20
|
+
is_delete?: boolean;
|
|
21
|
+
is_prohibited?: boolean;
|
|
22
|
+
};
|
|
23
|
+
public_time?: number;
|
|
24
|
+
create_time?: number;
|
|
25
|
+
statistics?: { play_count?: number; digg_count?: number };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalizeVideoStatus(
|
|
29
|
+
status: number | {
|
|
30
|
+
in_reviewing?: boolean;
|
|
31
|
+
is_private?: boolean;
|
|
32
|
+
is_delete?: boolean;
|
|
33
|
+
is_prohibited?: boolean;
|
|
34
|
+
} | undefined,
|
|
35
|
+
publicTime: number | undefined,
|
|
36
|
+
): number | string {
|
|
37
|
+
if (typeof status === 'number') return status;
|
|
38
|
+
if (!status) return publicTime && publicTime > Date.now() / 1000 ? 'scheduled' : 'published';
|
|
39
|
+
if (status.is_delete) return 'deleted';
|
|
40
|
+
if (status.is_prohibited) return 'prohibited';
|
|
41
|
+
if (status.in_reviewing) return 'reviewing';
|
|
42
|
+
if (status.is_private) return 'private';
|
|
43
|
+
if (publicTime && publicTime > Date.now() / 1000) return 'scheduled';
|
|
44
|
+
return 'published';
|
|
45
|
+
}
|
|
46
|
+
|
|
5
47
|
cli({
|
|
6
48
|
site: 'douyin',
|
|
7
49
|
name: 'videos',
|
|
@@ -19,31 +61,23 @@ cli({
|
|
|
19
61
|
const statusNum = statusMap[kwargs.status as string] ?? 0;
|
|
20
62
|
const url = `https://creator.douyin.com/janus/douyin/creator/pc/work_list?page_size=${kwargs.limit}&page_num=${kwargs.page}&status=${statusNum}`;
|
|
21
63
|
const res = (await browserFetch(page, 'GET', url)) as {
|
|
22
|
-
data
|
|
23
|
-
|
|
24
|
-
aweme_id: string;
|
|
25
|
-
desc: string;
|
|
26
|
-
status: number;
|
|
27
|
-
public_time: number;
|
|
28
|
-
create_time: number;
|
|
29
|
-
statistics: { play_count: number; digg_count: number };
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
64
|
+
data?: { work_list?: LegacyWorkItem[] };
|
|
65
|
+
aweme_list?: CurrentWorkItem[];
|
|
32
66
|
};
|
|
33
|
-
let items = res.data?.work_list ?? [];
|
|
67
|
+
let items: Array<LegacyWorkItem | CurrentWorkItem> = res.data?.work_list ?? res.aweme_list ?? [];
|
|
34
68
|
|
|
35
69
|
// The API has a bug with status=16 for scheduled, so filter client-side
|
|
36
70
|
if (kwargs.status === 'scheduled') {
|
|
37
|
-
items = items.filter((v) => v.public_time > Date.now() / 1000);
|
|
71
|
+
items = items.filter((v) => (v.public_time ?? 0) > Date.now() / 1000);
|
|
38
72
|
}
|
|
39
73
|
|
|
40
74
|
return items.map((v) => ({
|
|
41
75
|
aweme_id: v.aweme_id,
|
|
42
|
-
title: v.desc,
|
|
43
|
-
status: v.status,
|
|
76
|
+
title: v.desc ?? '',
|
|
77
|
+
status: normalizeVideoStatus(v.status, v.public_time),
|
|
44
78
|
play_count: v.statistics?.play_count ?? 0,
|
|
45
79
|
digg_count: v.statistics?.digg_count ?? 0,
|
|
46
|
-
create_time: new Date(v.create_time * 1000).toLocaleString('zh-CN', { timeZone: 'Asia/Tokyo' }),
|
|
80
|
+
create_time: new Date((v.create_time ?? v.public_time ?? 0) * 1000).toLocaleString('zh-CN', { timeZone: 'Asia/Tokyo' }),
|
|
47
81
|
}));
|
|
48
82
|
},
|
|
49
83
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for issue #625.
|
|
3
|
+
* Facebook search must navigate in the pipeline before DOM extraction.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import yaml from 'js-yaml';
|
|
10
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import { executePipeline } from '../../pipeline/index.js';
|
|
12
|
+
import type { IPage } from '../../types.js';
|
|
13
|
+
|
|
14
|
+
interface YamlCommand {
|
|
15
|
+
pipeline?: Array<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Minimal browser mock for pipeline execution tests.
|
|
20
|
+
* Only methods touched by this adapter path are implemented.
|
|
21
|
+
*/
|
|
22
|
+
function createMockPage(): IPage {
|
|
23
|
+
return {
|
|
24
|
+
goto: vi.fn(),
|
|
25
|
+
evaluate: vi.fn().mockResolvedValue([]),
|
|
26
|
+
getCookies: vi.fn().mockResolvedValue([]),
|
|
27
|
+
snapshot: vi.fn().mockResolvedValue(''),
|
|
28
|
+
click: vi.fn(),
|
|
29
|
+
typeText: vi.fn(),
|
|
30
|
+
pressKey: vi.fn(),
|
|
31
|
+
scrollTo: vi.fn(),
|
|
32
|
+
getFormState: vi.fn().mockResolvedValue({}),
|
|
33
|
+
wait: vi.fn(),
|
|
34
|
+
tabs: vi.fn().mockResolvedValue([]),
|
|
35
|
+
closeTab: vi.fn(),
|
|
36
|
+
newTab: vi.fn(),
|
|
37
|
+
selectTab: vi.fn(),
|
|
38
|
+
networkRequests: vi.fn().mockResolvedValue([]),
|
|
39
|
+
consoleMessages: vi.fn().mockResolvedValue(''),
|
|
40
|
+
scroll: vi.fn(),
|
|
41
|
+
autoScroll: vi.fn(),
|
|
42
|
+
installInterceptor: vi.fn(),
|
|
43
|
+
getInterceptedRequests: vi.fn().mockResolvedValue([]),
|
|
44
|
+
waitForCapture: vi.fn().mockResolvedValue(undefined),
|
|
45
|
+
screenshot: vi.fn().mockResolvedValue(''),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('facebook search pipeline', () => {
|
|
50
|
+
it('navigates to search results before extracting DOM data', async () => {
|
|
51
|
+
// Load the YAML adapter directly so the regression test covers the shipped command definition.
|
|
52
|
+
const filePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'search.yaml');
|
|
53
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
54
|
+
const command = yaml.load(raw) as YamlCommand;
|
|
55
|
+
const pipeline = command.pipeline ?? [];
|
|
56
|
+
const page = createMockPage();
|
|
57
|
+
|
|
58
|
+
await executePipeline(page, pipeline, {
|
|
59
|
+
args: { query: 'AI agent', limit: 3 },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(page.goto).toHaveBeenNthCalledWith(1, 'https://www.facebook.com');
|
|
63
|
+
expect(page.goto).toHaveBeenNthCalledWith(2, 'https://www.facebook.com/search/top?q=AI%20agent', {
|
|
64
|
+
waitUntil: undefined,
|
|
65
|
+
settleMs: 4000,
|
|
66
|
+
});
|
|
67
|
+
expect(page.evaluate).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(String((page.evaluate as ReturnType<typeof vi.fn>).mock.calls[0]?.[0] ?? '')).not.toContain('window.location.href');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -17,12 +17,13 @@ args:
|
|
|
17
17
|
pipeline:
|
|
18
18
|
- navigate: https://www.facebook.com
|
|
19
19
|
|
|
20
|
+
- navigate:
|
|
21
|
+
url: https://www.facebook.com/search/top?q=${{ args.query | urlencode }}
|
|
22
|
+
settleMs: 4000
|
|
23
|
+
|
|
20
24
|
- evaluate: |
|
|
21
25
|
(async () => {
|
|
22
|
-
const query = ${{ args.query | json }};
|
|
23
26
|
const limit = ${{ args.limit }};
|
|
24
|
-
window.location.href = 'https://www.facebook.com/search/top?q=' + encodeURIComponent(query);
|
|
25
|
-
await new Promise(r => setTimeout(r, 4000));
|
|
26
27
|
// Search results are typically in role="article" or role="listitem"
|
|
27
28
|
let items = document.querySelectorAll('[role="article"]');
|
|
28
29
|
if (items.length === 0) {
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as os from 'node:os';
|
|
2
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import type { CliCommand } from '../../registry.js';
|
|
4
|
+
import { getRegistry } from '../../registry.js';
|
|
5
|
+
import { ArgumentError, AuthRequiredError, CliError, CommandExecutionError } from '../../errors.js';
|
|
6
|
+
import type { IPage } from '../../types.js';
|
|
7
|
+
|
|
8
|
+
const { mockHttpDownload, logSpy } = vi.hoisted(() => ({
|
|
9
|
+
mockHttpDownload: vi.fn(),
|
|
10
|
+
logSpy: vi.spyOn(console, 'log').mockImplementation(() => undefined),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
vi.mock('../../download/index.js', async () => {
|
|
14
|
+
const actual = await vi.importActual<object>('../../download/index.js');
|
|
15
|
+
return { ...actual, httpDownload: mockHttpDownload };
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
buildInstagramDownloadItems,
|
|
20
|
+
parseInstagramMediaTarget,
|
|
21
|
+
} = await import('./download.js');
|
|
22
|
+
|
|
23
|
+
let cmd: CliCommand;
|
|
24
|
+
|
|
25
|
+
beforeAll(() => {
|
|
26
|
+
cmd = getRegistry().get('instagram/download')!;
|
|
27
|
+
expect(cmd?.func).toBeTypeOf('function');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function createPageMock(evaluateResult: unknown): IPage {
|
|
31
|
+
return {
|
|
32
|
+
goto: vi.fn().mockResolvedValue(undefined),
|
|
33
|
+
evaluate: vi.fn().mockResolvedValue(evaluateResult),
|
|
34
|
+
} as unknown as IPage;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('instagram download helpers', () => {
|
|
38
|
+
it('parses canonical and username-prefixed Instagram media URLs', () => {
|
|
39
|
+
expect(parseInstagramMediaTarget('https://www.instagram.com/reel/DWg8NuZEj9p/?utm_source=ig_web_copy_link')).toEqual({
|
|
40
|
+
kind: 'reel',
|
|
41
|
+
shortcode: 'DWg8NuZEj9p',
|
|
42
|
+
canonicalUrl: 'https://www.instagram.com/reel/DWg8NuZEj9p/',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(parseInstagramMediaTarget('https://www.instagram.com/nasa/p/DWUR_azCWbN/?img_index=1')).toEqual({
|
|
46
|
+
kind: 'p',
|
|
47
|
+
shortcode: 'DWUR_azCWbN',
|
|
48
|
+
canonicalUrl: 'https://www.instagram.com/p/DWUR_azCWbN/',
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('rejects unsupported URLs early', () => {
|
|
53
|
+
expect(() => parseInstagramMediaTarget('https://example.com/p/abc')).toThrow(ArgumentError);
|
|
54
|
+
expect(() => parseInstagramMediaTarget('https://www.instagram.com/stories/abc/123')).toThrow(ArgumentError);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('builds padded filenames and preserves known file extensions', () => {
|
|
58
|
+
expect(buildInstagramDownloadItems('DWUR_azCWbN', [
|
|
59
|
+
{ type: 'image', url: 'https://cdn.example.com/photo.webp?foo=1' },
|
|
60
|
+
{ type: 'video', url: 'https://cdn.example.com/video.mp4?bar=2' },
|
|
61
|
+
{ type: 'image', url: 'not-a-valid-url' },
|
|
62
|
+
])).toEqual([
|
|
63
|
+
{ type: 'image', url: 'https://cdn.example.com/photo.webp?foo=1', filename: 'DWUR_azCWbN_01.webp' },
|
|
64
|
+
{ type: 'video', url: 'https://cdn.example.com/video.mp4?bar=2', filename: 'DWUR_azCWbN_02.mp4' },
|
|
65
|
+
{ type: 'image', url: 'not-a-valid-url', filename: 'DWUR_azCWbN_03.jpg' },
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('instagram download command', () => {
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
mockHttpDownload.mockReset();
|
|
73
|
+
logSpy.mockClear();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('rejects invalid URLs before browser work', async () => {
|
|
77
|
+
const page = createPageMock({ ok: true, items: [] });
|
|
78
|
+
await expect(cmd.func!(page, { url: 'https://example.com/not-instagram' })).rejects.toThrow(ArgumentError);
|
|
79
|
+
expect((page.goto as any).mock.calls).toHaveLength(0);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('maps auth failures to AuthRequiredError', async () => {
|
|
83
|
+
const page = createPageMock({ ok: false, errorCode: 'AUTH_REQUIRED', error: 'Instagram login required' });
|
|
84
|
+
await expect(cmd.func!(page, { url: 'https://www.instagram.com/p/DWUR_azCWbN/' })).rejects.toThrow(AuthRequiredError);
|
|
85
|
+
expect(mockHttpDownload).not.toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('maps rate limit failures to CliError with RATE_LIMITED code', async () => {
|
|
89
|
+
const page = createPageMock({ ok: false, errorCode: 'RATE_LIMITED', error: 'Please wait a few minutes' });
|
|
90
|
+
await expect(cmd.func!(page, { url: 'https://www.instagram.com/p/DWUR_azCWbN/' })).rejects.toMatchObject({ code: 'RATE_LIMITED' } satisfies Partial<CliError>);
|
|
91
|
+
expect(mockHttpDownload).not.toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('maps private/unavailable failures to CommandExecutionError', async () => {
|
|
95
|
+
const page = createPageMock({ ok: false, errorCode: 'PRIVATE_OR_UNAVAILABLE', error: 'Post may be private' });
|
|
96
|
+
await expect(cmd.func!(page, { url: 'https://www.instagram.com/p/DWUR_azCWbN/' })).rejects.toThrow(CommandExecutionError);
|
|
97
|
+
expect(mockHttpDownload).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('throws when no downloadable media is found', async () => {
|
|
101
|
+
const page = createPageMock({ ok: true, shortcode: 'DWUR_azCWbN', items: [] });
|
|
102
|
+
await expect(cmd.func!(page, { url: 'https://www.instagram.com/p/DWUR_azCWbN/' })).rejects.toThrow(CommandExecutionError);
|
|
103
|
+
expect(mockHttpDownload).not.toHaveBeenCalled();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('downloads media and prints saved directory', async () => {
|
|
107
|
+
mockHttpDownload
|
|
108
|
+
.mockResolvedValueOnce({ success: true, size: 120_000 })
|
|
109
|
+
.mockResolvedValueOnce({ success: true, size: 8_200_000 });
|
|
110
|
+
|
|
111
|
+
const page = createPageMock({
|
|
112
|
+
ok: true,
|
|
113
|
+
shortcode: 'DWUR_azCWbN',
|
|
114
|
+
items: [
|
|
115
|
+
{ type: 'image', url: 'https://cdn.example.com/photo.webp?foo=1' },
|
|
116
|
+
{ type: 'video', url: 'https://cdn.example.com/video.mp4?bar=2' },
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const result = await cmd.func!(page, {
|
|
121
|
+
url: 'https://www.instagram.com/nasa/p/DWUR_azCWbN/?img_index=1',
|
|
122
|
+
path: './instagram-test',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(result).toBeNull();
|
|
126
|
+
expect((page.goto as any).mock.calls[0]?.[0]).toBe('https://www.instagram.com/p/DWUR_azCWbN/');
|
|
127
|
+
expect(mockHttpDownload).toHaveBeenNthCalledWith(1,
|
|
128
|
+
'https://cdn.example.com/photo.webp?foo=1',
|
|
129
|
+
expect.stringContaining('instagram-test/DWUR_azCWbN/DWUR_azCWbN_01.webp'),
|
|
130
|
+
expect.objectContaining({ timeout: 60000 }),
|
|
131
|
+
);
|
|
132
|
+
expect(mockHttpDownload).toHaveBeenNthCalledWith(2,
|
|
133
|
+
'https://cdn.example.com/video.mp4?bar=2',
|
|
134
|
+
expect.stringContaining('instagram-test/DWUR_azCWbN/DWUR_azCWbN_02.mp4'),
|
|
135
|
+
expect.objectContaining({ timeout: 120000 }),
|
|
136
|
+
);
|
|
137
|
+
expect(logSpy).toHaveBeenCalledWith('📁 saved: instagram-test/DWUR_azCWbN');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('uses a cross-platform Downloads default when path is omitted', async () => {
|
|
141
|
+
mockHttpDownload.mockResolvedValueOnce({ success: true, size: 120_000 });
|
|
142
|
+
|
|
143
|
+
const page = createPageMock({
|
|
144
|
+
ok: true,
|
|
145
|
+
shortcode: 'DWUR_azCWbN',
|
|
146
|
+
items: [
|
|
147
|
+
{ type: 'image', url: 'https://cdn.example.com/photo.webp?foo=1' },
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
await cmd.func!(page, { url: 'https://www.instagram.com/p/DWUR_azCWbN/' });
|
|
152
|
+
|
|
153
|
+
expect(mockHttpDownload).toHaveBeenCalledWith(
|
|
154
|
+
'https://cdn.example.com/photo.webp?foo=1',
|
|
155
|
+
expect.stringContaining(`${os.homedir()}/Downloads/Instagram/DWUR_azCWbN/DWUR_azCWbN_01.webp`),
|
|
156
|
+
expect.objectContaining({ timeout: 60000 }),
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
});
|