ai-yuca 1.3.3 → 1.3.4

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-yuca",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "一个用AI生成的开发辅助工具",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -32,9 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
36
  exports.createGCPClient = createGCPClient;
40
37
  exports.getFilesOnline = getFilesOnline;
@@ -49,7 +46,6 @@ const fs = __importStar(require("fs"));
49
46
  const path = __importStar(require("path"));
50
47
  const storage_1 = require("@google-cloud/storage");
51
48
  const glob = __importStar(require("fast-glob"));
52
- const axios_1 = __importDefault(require("axios"));
53
49
  const zlib_1 = require("zlib");
54
50
  const stream_1 = require("stream");
55
51
  const util_1 = require("util");
@@ -324,41 +320,19 @@ async function getTransLateFiles(gcpClient, config) {
324
320
  console.log('langFiles', langFiles);
325
321
  for (const file of langFiles) {
326
322
  try {
327
- // 处理文件Key(编码路径)
328
- const fileKey = encodeURIComponent(file.name);
329
- const hostName = config.crowdin.HostName || config.aws.HostName;
330
- if (hostName) {
331
- // 从CDN获取文件数据
332
- const fileUrl = `${hostName}/${fileKey}`;
333
- const response = await axios_1.default.get(fileUrl, { timeout: 30000 });
334
- const obj = response.data;
335
- // 计算本地文件路径
336
- const relativePath = file.name.replace(langPrefix, '');
337
- const filePath = path.join(langDir, lang, relativePath);
338
- // 合并到语言对象
339
- Object.assign(langObj, obj);
340
- // 创建目录并写入文件
341
- const fileDir = path.dirname(filePath);
342
- if (mkDirs(fileDir)) {
343
- fs.writeFileSync(filePath, JSON.stringify(obj, null, 2), 'utf-8');
344
- downloadedFiles.push(1);
345
- }
346
- }
347
- else {
348
- // 直接从GCP下载
349
- const [fileContent] = await file.download();
350
- const obj = JSON.parse(fileContent.toString('utf-8'));
351
- // 计算本地文件路径
352
- const relativePath = file.name.replace(langPrefix, '');
353
- const filePath = path.join(langDir, lang, relativePath);
354
- // 合并到语言对象
355
- Object.assign(langObj, obj);
356
- // 创建目录并写入文件
357
- const fileDir = path.dirname(filePath);
358
- if (mkDirs(fileDir)) {
359
- fs.writeFileSync(filePath, JSON.stringify(obj, null, 2), 'utf-8');
360
- downloadedFiles.push(1);
361
- }
323
+ // 直接从GCP下载
324
+ const [fileContent] = await file.download();
325
+ const obj = JSON.parse(fileContent.toString('utf-8'));
326
+ // 计算本地文件路径
327
+ const relativePath = file.name.replace(langPrefix, '');
328
+ const filePath = path.join(langDir, lang, relativePath);
329
+ // 合并到语言对象
330
+ Object.assign(langObj, obj);
331
+ // 创建目录并写入文件
332
+ const fileDir = path.dirname(filePath);
333
+ if (mkDirs(fileDir)) {
334
+ fs.writeFileSync(filePath, JSON.stringify(obj, null, 2), 'utf-8');
335
+ downloadedFiles.push(1);
362
336
  }
363
337
  }
364
338
  catch (error) {
@@ -291,7 +291,7 @@ async function uploadFiles(options) {
291
291
  // 实时处理上传结果
292
292
  if (result.success) {
293
293
  results.success.push(result);
294
- console.log(` ✅ [${currentIndex + 1}/${uploadQueue.length}] ${path.basename(filePath)}: 上传成功`);
294
+ // console.log(` ✅ [${currentIndex + 1}/${uploadQueue.length}] ${path.basename(filePath)}: 上传成功`);
295
295
  }
296
296
  else {
297
297
  results.failed.push(result);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 存储相关工具函数
3
+ */
4
+ import { Storage } from '@google-cloud/storage';
5
+ /**
6
+ * 从 GCP 存储桶获取 JSON 文件内容
7
+ * @param client - GCP 存储客户端实例
8
+ * @param filePath - 文件路径(存储桶中的路径)
9
+ * @param bucketName - 存储桶名称
10
+ * @returns 解析后的 JSON 对象,如果不是有效的 JSON 或发生错误则返回空对象
11
+ */
12
+ export declare function getJsonFile(client: Storage, filePath: string, bucketName: string): Promise<Record<string, any>>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJsonFile = getJsonFile;
4
+ /**
5
+ * 从 GCP 存储桶获取 JSON 文件内容
6
+ * @param client - GCP 存储客户端实例
7
+ * @param filePath - 文件路径(存储桶中的路径)
8
+ * @param bucketName - 存储桶名称
9
+ * @returns 解析后的 JSON 对象,如果不是有效的 JSON 或发生错误则返回空对象
10
+ */
11
+ async function getJsonFile(client, filePath, bucketName) {
12
+ console.log(`📥 正在获取 JSON 文件: ${filePath} (从存储桶: ${bucketName})`);
13
+ try {
14
+ // 获取存储桶
15
+ const bucket = client.bucket(bucketName);
16
+ const file = bucket.file(filePath);
17
+ // 检查文件是否存在
18
+ const [exists] = await file.exists();
19
+ if (!exists) {
20
+ console.error(`❌ 文件不存在: ${filePath}`);
21
+ return {};
22
+ }
23
+ // 下载文件内容
24
+ const [content] = await file.download();
25
+ // 尝试解析 JSON
26
+ try {
27
+ const jsonContent = JSON.parse(content.toString('utf-8'));
28
+ console.log(`✅ 成功获取并解析 JSON 文件: ${filePath}`);
29
+ return jsonContent;
30
+ }
31
+ catch (parseError) {
32
+ console.error(`❌ 文件不是有效的 JSON 格式: ${filePath}`);
33
+ console.error(` 错误详情: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
34
+ return {};
35
+ }
36
+ }
37
+ catch (error) {
38
+ console.error(`❌ 获取文件失败: ${filePath}`);
39
+ console.error(` 错误详情: ${error instanceof Error ? error.message : String(error)}`);
40
+ return {};
41
+ }
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-yuca",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "一个用AI生成的开发辅助工具",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",