@cnbcool/cnb-cli 1.1.0 → 1.2.0
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/package.json +4 -2
- package/skills/cnb-api/scripts/core/flat-options.json +8909 -0
- package/skills/cnb-api/scripts/core/help.json +704 -704
- package/skills/cnb-api/scripts/core/index.js +33 -455
- package/skills/cnb-api/scripts/core/key-mapping.json +538 -0
- package/skills/cnb-api/scripts/core/lib/execute-action.js +97 -0
- package/skills/cnb-api/scripts/core/lib/extra-help.js +20 -0
- package/skills/cnb-api/scripts/core/lib/flat-options-data.js +16 -0
- package/skills/cnb-api/scripts/core/lib/format-output.js +85 -0
- package/skills/cnb-api/scripts/core/lib/format-params.js +211 -0
- package/skills/cnb-api/scripts/core/lib/help-data.js +15 -0
- package/skills/cnb-api/scripts/core/lib/key-mapping-data.js +16 -0
- package/skills/cnb-api/scripts/core/lib/parsers.js +126 -0
- package/skills/cnb-api/scripts/core/lib/print-json.js +15 -0
- package/skills/cnb-api/scripts/core/lib/register-fallback.js +15 -0
- package/skills/cnb-api/scripts/core/lib/register-modules.js +91 -0
- package/skills/cnb-api/scripts/core/lib/summary-extractors.js +181 -0
- package/skills/cnb-api/scripts/core/lib/trim-summary.js +17 -0
- package/skills/cnb-api/scripts/core/shortcuts.js +10 -186
- package/skills/cnb-api/scripts/core/utils/build-nested-field-map.js +35 -0
- package/skills/cnb-api/scripts/core/utils/flat-key-from-segments.js +14 -0
- package/skills/cnb-api/scripts/core/utils/match-array-object-field.js +25 -0
- package/skills/cnb-api/scripts/core/utils/restore-original-keys.js +24 -0
- package/skills/cnb-api/scripts/core/utils/upload.js +107 -15
- package/skills/cnb-api/scripts/modules/knowledge-base/search-npc.js +5 -5
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.handleUpload = handleUpload;
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _mimeTypes = require("mime-types");
|
|
10
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
10
|
/**
|
|
12
11
|
* 完整上传流程
|
|
@@ -16,19 +15,105 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
16
15
|
* 4. 返回最终结果
|
|
17
16
|
*/
|
|
18
17
|
|
|
18
|
+
/** 常见文件扩展名 → MIME 类型映射(仅用于上传场景,不引入外部依赖) */
|
|
19
|
+
const MIME_MAP = {
|
|
20
|
+
'.txt': 'text/plain',
|
|
21
|
+
'.html': 'text/html',
|
|
22
|
+
'.htm': 'text/html',
|
|
23
|
+
'.css': 'text/css',
|
|
24
|
+
'.csv': 'text/csv',
|
|
25
|
+
'.js': 'application/javascript',
|
|
26
|
+
'.mjs': 'application/javascript',
|
|
27
|
+
'.json': 'application/json',
|
|
28
|
+
'.xml': 'application/xml',
|
|
29
|
+
'.pdf': 'application/pdf',
|
|
30
|
+
'.zip': 'application/zip',
|
|
31
|
+
'.gz': 'application/gzip',
|
|
32
|
+
'.gzip': 'application/gzip',
|
|
33
|
+
'.tar': 'application/x-tar',
|
|
34
|
+
'.7z': 'application/x-7z-compressed',
|
|
35
|
+
'.rar': 'application/vnd.rar',
|
|
36
|
+
'.doc': 'application/msword',
|
|
37
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
38
|
+
'.xls': 'application/vnd.ms-excel',
|
|
39
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
40
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
41
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
42
|
+
'.png': 'image/png',
|
|
43
|
+
'.jpg': 'image/jpeg',
|
|
44
|
+
'.jpeg': 'image/jpeg',
|
|
45
|
+
'.gif': 'image/gif',
|
|
46
|
+
'.svg': 'image/svg+xml',
|
|
47
|
+
'.webp': 'image/webp',
|
|
48
|
+
'.ico': 'image/x-icon',
|
|
49
|
+
'.bmp': 'image/bmp',
|
|
50
|
+
'.mp3': 'audio/mpeg',
|
|
51
|
+
'.wav': 'audio/wav',
|
|
52
|
+
'.ogg': 'audio/ogg',
|
|
53
|
+
'.mp4': 'video/mp4',
|
|
54
|
+
'.webm': 'video/webm',
|
|
55
|
+
'.avi': 'video/x-msvideo',
|
|
56
|
+
'.mov': 'video/quicktime',
|
|
57
|
+
'.woff': 'font/woff',
|
|
58
|
+
'.woff2': 'font/woff2',
|
|
59
|
+
'.ttf': 'font/ttf',
|
|
60
|
+
'.otf': 'font/otf',
|
|
61
|
+
'.md': 'text/markdown',
|
|
62
|
+
'.yaml': 'text/yaml',
|
|
63
|
+
'.yml': 'text/yaml',
|
|
64
|
+
'.sh': 'application/x-sh',
|
|
65
|
+
'.py': 'text/x-python',
|
|
66
|
+
'.rb': 'text/x-ruby',
|
|
67
|
+
'.go': 'text/x-go',
|
|
68
|
+
'.rs': 'text/x-rust',
|
|
69
|
+
'.ts': 'text/typescript',
|
|
70
|
+
'.tsx': 'text/typescript',
|
|
71
|
+
'.jsx': 'text/jsx',
|
|
72
|
+
'.java': 'text/x-java-source',
|
|
73
|
+
'.c': 'text/x-c',
|
|
74
|
+
'.h': 'text/x-c',
|
|
75
|
+
'.cpp': 'text/x-c++src',
|
|
76
|
+
'.hpp': 'text/x-c++hdr',
|
|
77
|
+
'.log': 'text/plain',
|
|
78
|
+
'.patch': 'text/x-diff',
|
|
79
|
+
'.diff': 'text/x-diff'
|
|
80
|
+
};
|
|
81
|
+
function mimeLookup(filePath) {
|
|
82
|
+
const ext = _path.default.extname(filePath).toLowerCase();
|
|
83
|
+
return MIME_MAP[ext] || 'application/octet-stream';
|
|
84
|
+
}
|
|
85
|
+
|
|
19
86
|
// 上传文件大小上限:100MB
|
|
20
87
|
const MAX_FILE_SIZE = 100 * 1024 * 1024;
|
|
21
88
|
|
|
89
|
+
/** 上传 API 的 path 参数 */
|
|
90
|
+
|
|
91
|
+
/** Issue 上传请求体 */
|
|
92
|
+
|
|
93
|
+
/** Pull 上传请求体 */
|
|
94
|
+
|
|
95
|
+
/** 上传 API 函数签名 */
|
|
96
|
+
|
|
97
|
+
/** 上传 API 响应 */
|
|
98
|
+
|
|
99
|
+
/** 上传失败时的 data */
|
|
100
|
+
|
|
101
|
+
/** Issue 上传成功时的 data */
|
|
102
|
+
|
|
103
|
+
/** Pull 上传成功时的 data */
|
|
104
|
+
|
|
105
|
+
/** handleUpload 的返回值 */
|
|
106
|
+
|
|
22
107
|
/**
|
|
23
108
|
* 处理完整上传流程
|
|
24
109
|
* @param shortcut 解析后的快捷命令
|
|
25
110
|
* @param filePath 本地文件路径
|
|
26
111
|
* @param toolFunction 原始上传 API 函数(获取 upload_url)
|
|
27
|
-
* @param
|
|
112
|
+
* @param pathParams API 调用的 path 参数(repo 或 {repo, number})
|
|
28
113
|
*/
|
|
29
|
-
async function handleUpload(shortcut, filePath, toolFunction,
|
|
114
|
+
async function handleUpload(shortcut, filePath, toolFunction, pathParams) {
|
|
30
115
|
// 校验 file 参数
|
|
31
|
-
if (!filePath
|
|
116
|
+
if (!filePath) {
|
|
32
117
|
return {
|
|
33
118
|
status: 400,
|
|
34
119
|
data: {
|
|
@@ -73,7 +158,7 @@ async function handleUpload(shortcut, filePath, toolFunction, toolsParam) {
|
|
|
73
158
|
}
|
|
74
159
|
};
|
|
75
160
|
}
|
|
76
|
-
const contentType = (
|
|
161
|
+
const contentType = mimeLookup(filePath);
|
|
77
162
|
|
|
78
163
|
// 2. 调用上传 API 获取 upload_url
|
|
79
164
|
const isIssueUpload = shortcut.module === 'issues';
|
|
@@ -85,10 +170,10 @@ async function handleUpload(shortcut, filePath, toolFunction, toolsParam) {
|
|
|
85
170
|
name: fileName,
|
|
86
171
|
size: fileSize
|
|
87
172
|
};
|
|
88
|
-
const uploadResponse = await toolFunction(
|
|
173
|
+
const uploadResponse = await toolFunction(pathParams, requestBody);
|
|
89
174
|
|
|
90
|
-
// 提取 upload_url
|
|
91
|
-
const responseData = uploadResponse?.data
|
|
175
|
+
// 提取 upload_url
|
|
176
|
+
const responseData = uploadResponse?.data;
|
|
92
177
|
const uploadUrl = responseData?.upload_url;
|
|
93
178
|
if (!uploadUrl) {
|
|
94
179
|
return uploadResponse; // 获取 URL 失败,直接返回原始错误
|
|
@@ -100,14 +185,21 @@ async function handleUpload(shortcut, filePath, toolFunction, toolsParam) {
|
|
|
100
185
|
'Content-Type': contentType,
|
|
101
186
|
'Content-Length': String(fileSize)
|
|
102
187
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
188
|
+
let putResponse;
|
|
189
|
+
try {
|
|
190
|
+
putResponse = await fetch(uploadUrl, {
|
|
191
|
+
method: 'PUT',
|
|
192
|
+
headers: putHeaders,
|
|
193
|
+
body: fileStream,
|
|
194
|
+
// @ts-ignore duplex required for streaming body in Node.js fetch
|
|
195
|
+
duplex: 'half'
|
|
196
|
+
});
|
|
197
|
+
} catch (e) {
|
|
198
|
+
fileStream.destroy();
|
|
199
|
+
throw e;
|
|
200
|
+
}
|
|
110
201
|
if (!putResponse.ok) {
|
|
202
|
+
fileStream.destroy();
|
|
111
203
|
const errText = await putResponse.text().catch(() => '');
|
|
112
204
|
return {
|
|
113
205
|
status: putResponse.status,
|
|
@@ -16,7 +16,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
16
16
|
* ## AUTHOR: bapelin ##
|
|
17
17
|
* ## SOURCE: https://cnb.cool/cnb/skills/cnb-api-generate ##
|
|
18
18
|
* -------------------------------------------------------------------------
|
|
19
|
-
* @Source /npc
|
|
19
|
+
* @Source /search/npc
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -41,7 +41,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
41
41
|
* @tags KnowledgeBase
|
|
42
42
|
* @name searchNpc
|
|
43
43
|
* @summary 全局语义搜索 NPC 角色
|
|
44
|
-
* @request get:/npc
|
|
44
|
+
* @request get:/search/npc
|
|
45
45
|
|
|
46
46
|
----------------------------------
|
|
47
47
|
* @param {SearchNpcParams} arg0 - searchNpc request params
|
|
@@ -58,13 +58,13 @@ async function _default({
|
|
|
58
58
|
...axiosConfig,
|
|
59
59
|
_next_req: req,
|
|
60
60
|
options: options,
|
|
61
|
-
url: "/npc
|
|
62
|
-
_apiTag: "/npc
|
|
61
|
+
url: "/search/npc",
|
|
62
|
+
_apiTag: "/search/npc",
|
|
63
63
|
method: "get",
|
|
64
64
|
params: query,
|
|
65
65
|
_originParams: {
|
|
66
66
|
method: "get",
|
|
67
|
-
_apiTag: "/npc
|
|
67
|
+
_apiTag: "/search/npc",
|
|
68
68
|
query: query
|
|
69
69
|
}
|
|
70
70
|
});
|