koishi-plugin-checkgal 1.0.0 → 1.0.1

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/lib/api.d.ts CHANGED
@@ -7,4 +7,5 @@ export declare class TouchGalAPI {
7
7
  constructor(ctx: Context);
8
8
  searchGame(keyword: string, config: Config): Promise<GameInfo[]>;
9
9
  getDownloads(patchId: number): Promise<DownloadResource[]>;
10
+ downloadAndConvertImage(url: string): Promise<Buffer | null>;
10
11
  }
package/lib/api.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TouchGalAPI = void 0;
7
+ const sharp_1 = __importDefault(require("sharp"));
4
8
  class TouchGalAPI {
5
9
  constructor(ctx) {
6
10
  this.http = ctx.http;
@@ -58,5 +62,22 @@ class TouchGalAPI {
58
62
  return [];
59
63
  }
60
64
  }
65
+ async downloadAndConvertImage(url) {
66
+ if (!url)
67
+ return null;
68
+ try {
69
+ const response = await this.http.get(url, {
70
+ responseType: 'arraybuffer',
71
+ });
72
+ // 类型守卫,确保 response 是 ArrayBuffer
73
+ if (!(response instanceof ArrayBuffer))
74
+ return null;
75
+ return (0, sharp_1.default)(Buffer.from(response)).jpeg().toBuffer();
76
+ }
77
+ catch (error) {
78
+ this.logger.error(`Failed to download or convert image from ${url}:`, error);
79
+ return null;
80
+ }
81
+ }
61
82
  }
62
83
  exports.TouchGalAPI = TouchGalAPI;
package/lib/commands.js CHANGED
@@ -16,9 +16,12 @@ function apply(ctx, config) {
16
16
  }
17
17
  // 缓存结果
18
18
  results.forEach(game => ctx.gameCache.set(game.id, game));
19
- const forwardMessages = results.map(game => {
19
+ // 并发下载并转换所有图片
20
+ const imageBuffers = await Promise.all(results.map(game => ctx.touchgal.downloadAndConvertImage(game.banner)));
21
+ const forwardMessages = results.map((game, index) => {
22
+ const imageBuffer = imageBuffers[index];
20
23
  const content = [
21
- (0, koishi_1.h)('image', { url: game.banner }),
24
+ imageBuffer ? (0, koishi_1.h)('image', { buffer: imageBuffer, mime: 'image/jpeg' }) : '封面图加载失败',
22
25
  `ID: ${game.id}`,
23
26
  `名称: ${game.name}`,
24
27
  `平台: ${game.platform.join(', ')}`,
@@ -55,8 +58,9 @@ function apply(ctx, config) {
55
58
  return `未找到ID为 ${id} 的下载资源。`;
56
59
  }
57
60
  const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
61
+ const imageBuffer = gameInfo ? await ctx.touchgal.downloadAndConvertImage(gameInfo.banner) : null;
58
62
  const header = [
59
- gameInfo ? (0, koishi_1.h)('image', { url: gameInfo.banner }) : '',
63
+ imageBuffer ? (0, koishi_1.h)('image', { buffer: imageBuffer, mime: 'image/jpeg' }) : (gameInfo ? '封面图加载失败' : ''),
60
64
  gameTitle,
61
65
  `共找到 ${downloads.length} 个下载资源:`,
62
66
  ].filter(Boolean).join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-checkgal",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "个人测试请勿使用",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -24,5 +24,8 @@
24
24
  "devDependencies": {
25
25
  "koishi": "^4.18.9",
26
26
  "typescript": "^5.9.3"
27
+ },
28
+ "dependencies": {
29
+ "sharp": "^0.34.4"
27
30
  }
28
31
  }