@sovovs/bycli 2.1.57 → 2.1.59

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.
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import { httpDownload } from '@sovovs/bycli/download';
4
4
  import { cli, Strategy } from '@sovovs/bycli/registry';
5
5
  import { CommandExecutionError, EmptyResultError } from '@sovovs/bycli/errors';
6
- import { readKnowledgeBaseFromChrome } from './native-client.js';
6
+ import { readImaMediaUrl, readKnowledgeBaseFromChrome } from './native-client.js';
7
7
  import { extractOriginUrl, resolveOutputPath, sha256File } from './download-utils.js';
8
8
 
9
9
  function countPdfPages(filePath) {
@@ -31,6 +31,7 @@ export async function runDownloadCommand(page, kwargs, deps = {}) {
31
31
  if (currentUrl?.includes('originUrl=')) originUrl = extractOriginUrl(currentUrl);
32
32
  }
33
33
  if (!originUrl && deps.readOriginalUrl) originUrl = await deps.readOriginalUrl(item);
34
+ if (!originUrl && page.fetchJson) originUrl = await readImaMediaUrl(page, { ...item, knowledgeBaseId: item.knowledgeBaseId || envelope.knowledgeBaseId });
34
35
  if (!originUrl && process.platform === 'darwin') {
35
36
  const { readKnowledgeBase: readKnowledgeBaseFromDesktop } = await import('./ax.js');
36
37
  const desktop = await Promise.resolve(readKnowledgeBaseFromDesktop(kb));
@@ -1,6 +1,7 @@
1
1
  import { listKnowledgeBases, readKnowledgeBaseFromApi } from './native-api.js';
2
2
 
3
3
  const IMA_WIKIS_URL = 'https://ima.qq.com/wikis';
4
+ const IMA_GET_MEDIA_URL = 'https://ima.qq.com/cgi-bin/file_manager/get_media';
4
5
 
5
6
  function codedError(code, message) {
6
7
  return Object.assign(new Error(message), { code });
@@ -84,3 +85,43 @@ export async function readKnowledgeBaseFromChrome(page, query, dependencies = {}
84
85
  await releaseImaAuth(page, authId);
85
86
  }
86
87
  }
88
+
89
+ export async function readImaMediaUrl(page, item, dependencies = {}) {
90
+ if (typeof page.requestImaMedia === 'function' && typeof page.startImaAuthCapture === 'function') {
91
+ const authId = await acquireImaChromeAuth(page, item?.knowledgeBaseId, dependencies);
92
+ try {
93
+ const response = await page.requestImaMedia(authId, {
94
+ knowledgeBaseId: String(item?.knowledgeBaseId ?? ''),
95
+ mediaId: String(item?.mediaId ?? ''),
96
+ scene: dependencies.scene ?? 4,
97
+ ...(item?.shareId ? { shareId: String(item.shareId) } : {}),
98
+ ...(item?.sourceKnowledgeBaseId ? { sourceKnowledgeBaseId: String(item.sourceKnowledgeBaseId) } : {}),
99
+ });
100
+ const data = response && typeof response === 'object' ? response : {};
101
+ const url = data.jumpUrlInfo?.url ?? data.jump_url_info?.url;
102
+ if (Number(data.action) !== 1 || typeof url !== 'string' || !url) {
103
+ throw codedError('IMA_ORIGINAL_URL_UNAVAILABLE', data.toastText || data.toast_text || 'IMA did not return an exportable file URL');
104
+ }
105
+ return url;
106
+ } finally {
107
+ await releaseImaAuth(page, authId);
108
+ }
109
+ }
110
+ if (!page || typeof page.fetchJson !== 'function') {
111
+ throw codedError('IMA_ORIGINAL_URL_UNAVAILABLE', 'IMA browser page cannot call get_media');
112
+ }
113
+ const response = await page.fetchJson(IMA_GET_MEDIA_URL, {
114
+ method: 'POST',
115
+ body: {
116
+ knowledgeBaseId: String(item?.knowledgeBaseId ?? item?.knowledge_base_id ?? ''),
117
+ mediaId: String(item?.mediaId ?? item?.media_id ?? ''),
118
+ scene: dependencies.scene ?? 4,
119
+ },
120
+ });
121
+ const data = response && typeof response === 'object' ? response : {};
122
+ const url = data.jumpUrlInfo?.url ?? data.jump_url_info?.url;
123
+ if (Number(data.action) !== 1 || typeof url !== 'string' || !url) {
124
+ throw codedError('IMA_ORIGINAL_URL_UNAVAILABLE', data.toastText || data.toast_text || 'IMA did not return an exportable file URL');
125
+ }
126
+ return url;
127
+ }
@@ -6,7 +6,7 @@
6
6
  import type { AdapterLease, AdapterLeaseRelease, AdapterLeaseRequest, AdapterResourceGrant } from '../adapter-scheduler.js';
7
7
  export interface DaemonCommand {
8
8
  id: string;
9
- action: 'exec' | 'navigate' | 'tabs' | 'cookies' | 'screenshot' | 'close-window' | 'set-file-input' | 'insert-text' | 'bind' | 'network-capture-start' | 'network-capture-read' | 'ima-auth-start' | 'ima-auth-read' | 'ima-reader-request' | 'ima-auth-release' | 'wait-download' | 'cdp' | 'frames';
9
+ action: 'exec' | 'navigate' | 'tabs' | 'cookies' | 'screenshot' | 'close-window' | 'set-file-input' | 'insert-text' | 'bind' | 'network-capture-start' | 'network-capture-read' | 'ima-auth-start' | 'ima-auth-read' | 'ima-reader-request' | 'ima-media-request' | 'ima-auth-release' | 'wait-download' | 'cdp' | 'frames';
10
10
  /** Target page identity (targetId). Cross-layer contract with the extension. */
11
11
  page?: string;
12
12
  code?: string;
@@ -36,6 +36,7 @@ export interface DaemonCommand {
36
36
  authId?: string;
37
37
  readerPath?: string;
38
38
  readerBody?: Record<string, unknown>;
39
+ mediaBody?: Record<string, unknown>;
39
40
  /** Download wait timeout in milliseconds */
40
41
  timeoutMs?: number;
41
42
  cdpMethod?: string;
@@ -6,6 +6,7 @@ const IMA_READER_ACTIONS = new Set([
6
6
  'ima-auth-start',
7
7
  'ima-auth-read',
8
8
  'ima-reader-request',
9
+ 'ima-media-request',
9
10
  'ima-auth-release',
10
11
  ]);
11
12
  export function normalizeExtensionCapabilities(value) {
@@ -64,6 +64,7 @@ export declare class Page extends BasePage {
64
64
  authId: string;
65
65
  } | null>;
66
66
  requestImaReader(authId: string, path: string, body: Record<string, unknown>): Promise<unknown>;
67
+ requestImaMedia(authId: string, body: Record<string, unknown>): Promise<unknown>;
67
68
  releaseImaAuth(authId: string): Promise<void>;
68
69
  waitForDownload(pattern?: string, timeoutMs?: number, options?: BrowserDownloadWaitOptions): Promise<BrowserDownloadWaitResult>;
69
70
  /**
@@ -325,6 +325,9 @@ export class Page extends BasePage {
325
325
  ...this._cmdOpts(),
326
326
  });
327
327
  }
328
+ async requestImaMedia(authId, body) {
329
+ return sendCommand('ima-media-request', { authId, mediaBody: body, ...this._cmdOpts() });
330
+ }
328
331
  async releaseImaAuth(authId) {
329
332
  await sendCommand('ima-auth-release', { authId, ...this._cmdOpts() });
330
333
  }
@@ -208,6 +208,7 @@ export interface IPage {
208
208
  authId: string;
209
209
  } | null>;
210
210
  requestImaReader?(authId: string, path: string, body: Record<string, unknown>): Promise<unknown>;
211
+ requestImaMedia?(authId: string, body: Record<string, unknown>): Promise<unknown>;
211
212
  releaseImaAuth?(authId: string): Promise<void>;
212
213
  /**
213
214
  * Set local file paths on a file input element via CDP DOM.setFileInputFiles.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovovs/bycli",
3
- "version": "2.1.57",
3
+ "version": "2.1.59",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },