@sovovs/bycli 2.1.57 → 2.1.58
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/clis/ima/download.js +2 -1
- package/clis/ima/native-client.js +21 -0
- package/package.json +1 -1
package/clis/ima/download.js
CHANGED
|
@@ -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,23 @@ 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 (!page || typeof page.fetchJson !== 'function') {
|
|
91
|
+
throw codedError('IMA_ORIGINAL_URL_UNAVAILABLE', 'IMA browser page cannot call get_media');
|
|
92
|
+
}
|
|
93
|
+
const response = await page.fetchJson(IMA_GET_MEDIA_URL, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
body: {
|
|
96
|
+
knowledgeBaseId: String(item?.knowledgeBaseId ?? item?.knowledge_base_id ?? ''),
|
|
97
|
+
mediaId: String(item?.mediaId ?? item?.media_id ?? ''),
|
|
98
|
+
scene: dependencies.scene ?? 4,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const data = response && typeof response === 'object' ? response : {};
|
|
102
|
+
const url = data.jumpUrlInfo?.url ?? data.jump_url_info?.url;
|
|
103
|
+
if (Number(data.action) !== 1 || typeof url !== 'string' || !url) {
|
|
104
|
+
throw codedError('IMA_ORIGINAL_URL_UNAVAILABLE', data.toastText || data.toast_text || 'IMA did not return an exportable file URL');
|
|
105
|
+
}
|
|
106
|
+
return url;
|
|
107
|
+
}
|