koishi-plugin-checkgal 1.3.3 → 1.3.5

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/LICENSE ADDED
@@ -0,0 +1 @@
1
+ AGPL-3.0 license text...
package/lib/api.d.ts CHANGED
@@ -4,9 +4,8 @@ import { Config } from './config';
4
4
  export declare class TouchGalAPI {
5
5
  private http;
6
6
  private logger;
7
- private tempDir;
8
7
  constructor(ctx: Context);
9
8
  searchGame(keyword: string, config: Config): Promise<GameInfo[]>;
10
9
  getDownloads(patchId: number): Promise<DownloadResource[]>;
11
- downloadAndConvertImage(url: string): Promise<string | null>;
10
+ downloadAndConvertImage(url: string): Promise<Buffer | null>;
12
11
  }
package/lib/api.js CHANGED
@@ -1,54 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.TouchGalAPI = void 0;
40
7
  const sharp_1 = __importDefault(require("sharp"));
41
- const path = __importStar(require("path"));
42
- const crypto = __importStar(require("crypto"));
43
- const fs_1 = require("fs");
44
8
  class TouchGalAPI {
45
9
  constructor(ctx) {
46
10
  this.http = ctx.http;
47
11
  this.logger = ctx.logger('checkgal-api');
48
- this.tempDir = path.join(ctx.app.baseDir, 'data', 'temp', 'checkgal');
49
- ctx.on('ready', async () => {
50
- await fs_1.promises.mkdir(this.tempDir, { recursive: true });
51
- });
52
12
  }
53
13
  async searchGame(keyword, config) {
54
14
  const url = 'https://www.touchgal.us/api/search';
@@ -111,13 +71,7 @@ class TouchGalAPI {
111
71
  });
112
72
  if (!(response instanceof ArrayBuffer))
113
73
  return null;
114
- const imageBuffer = await (0, sharp_1.default)(Buffer.from(response)).jpeg().toBuffer();
115
- const hash = crypto.createHash('md5').update(url).digest('hex');
116
- const fileName = `${hash}.jpg`;
117
- const filePath = path.join(this.tempDir, fileName);
118
- await fs_1.promises.writeFile(filePath, imageBuffer);
119
- // 返回绝对文件路径的 file:// URL
120
- return `file://${filePath}`;
74
+ return (0, sharp_1.default)(Buffer.from(response)).jpeg().toBuffer();
121
75
  }
122
76
  catch (error) {
123
77
  this.logger.error(`Failed to download or convert image from ${url}:`, error);
package/lib/commands.js CHANGED
@@ -18,15 +18,9 @@ function apply(ctx, config) {
18
18
  }
19
19
  // 缓存结果
20
20
  results.forEach(game => ctx.gameCache.set(game.id, game));
21
- // 并发下载并转换所有图片
22
- const imagePaths = await Promise.all(results.map(game => ctx.touchgal.downloadAndConvertImage(game.banner)));
23
- const forwardMessages = results.map((game, index) => {
24
- const imagePath = imagePaths[index];
25
- const imageElement = imagePath
26
- ? (0, koishi_1.h)('image', { url: imagePath })
27
- : (0, koishi_1.h)('text', { content: '封面图加载失败' });
21
+ // 仅在合并转发中发送文本信息
22
+ const forwardMessages = results.map(game => {
28
23
  const content = [
29
- imageElement,
30
24
  `ID: ${game.id}`,
31
25
  `名称: ${game.name}`,
32
26
  `平台: ${game.platform.join(', ')}`,
@@ -35,6 +29,14 @@ function apply(ctx, config) {
35
29
  return (0, koishi_1.h)('message', { userId: session.bot.selfId, nickname: 'CheckGal Bot' }, content);
36
30
  });
37
31
  await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
32
+ await session.send('封面图将单独发送:');
33
+ // 单独逐张发送图片
34
+ for (const game of results) {
35
+ const imageBuffer = await ctx.touchgal.downloadAndConvertImage(game.banner);
36
+ if (imageBuffer) {
37
+ await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
38
+ }
39
+ }
38
40
  });
39
41
  ctx.command('下载gal <id:number>', '获取Galgame下载地址')
40
42
  .action(async ({ session }, id) => {
@@ -61,12 +63,12 @@ function apply(ctx, config) {
61
63
  return `未找到ID为 ${id} 的下载资源。`;
62
64
  }
63
65
  const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
64
- const imagePath = gameInfo ? await ctx.touchgal.downloadAndConvertImage(gameInfo.banner) : null;
65
- const imageElement = imagePath
66
- ? (0, koishi_1.h)('image', { url: imagePath })
67
- : (0, koishi_1.h)('text', { content: gameInfo ? '封面图加载失败' : '' });
66
+ const imageBuffer = gameInfo ? await ctx.touchgal.downloadAndConvertImage(gameInfo.banner) : null;
67
+ // 对于单条消息,直接发送 Buffer 是最高效的
68
+ if (imageBuffer) {
69
+ await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
70
+ }
68
71
  const header = [
69
- imageElement,
70
72
  gameTitle,
71
73
  `共找到 ${downloads.length} 个下载资源:`,
72
74
  ].filter(Boolean).join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-checkgal",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "个人测试请勿使用",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "lib"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsc"
11
+ "build": "node --max-old-space-size=4096 ./node_modules/typescript/bin/tsc"
12
12
  },
13
13
  "keywords": [
14
14
  "chatbot",
@@ -17,7 +17,7 @@
17
17
  "galgame"
18
18
  ],
19
19
  "author": "Roo",
20
- "license": "MIT",
20
+ "license": "AGPL-3.0",
21
21
  "koishi": {
22
22
  "name": "checkgal"
23
23
  },