koishi-plugin-checkgal 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/lib/api.js CHANGED
@@ -45,8 +45,8 @@ class TouchGalAPI {
45
45
  constructor(ctx) {
46
46
  this.http = ctx.http;
47
47
  this.logger = ctx.logger('checkgal-api');
48
- this.tempDir = path.join(ctx.app.baseDir, 'data', 'temp', 'checkgal');
49
- // 确保临时目录存在
48
+ // 直接使用 koishi/temp 目录
49
+ this.tempDir = path.join(ctx.app.baseDir, 'temp');
50
50
  ctx.on('ready', async () => {
51
51
  await fs_1.promises.mkdir(this.tempDir, { recursive: true });
52
52
  });
@@ -110,15 +110,15 @@ class TouchGalAPI {
110
110
  const response = await this.http.get(url, {
111
111
  responseType: 'arraybuffer',
112
112
  });
113
- // 类型守卫,确保 response 是 ArrayBuffer
114
113
  if (!(response instanceof ArrayBuffer))
115
114
  return null;
116
115
  const imageBuffer = await (0, sharp_1.default)(Buffer.from(response)).jpeg().toBuffer();
117
- // 生成唯一文件名并写入临时目录
118
116
  const hash = crypto.createHash('md5').update(url).digest('hex');
119
- const filePath = path.join(this.tempDir, `${hash}.jpg`);
117
+ const fileName = `${hash}.jpg`;
118
+ const filePath = path.join(this.tempDir, fileName);
120
119
  await fs_1.promises.writeFile(filePath, imageBuffer);
121
- return filePath;
120
+ // 返回相对于 koishi 根目录的相对路径
121
+ return `temp/${fileName}`;
122
122
  }
123
123
  catch (error) {
124
124
  this.logger.error(`Failed to download or convert image from ${url}:`, error);
package/lib/commands.js CHANGED
@@ -23,7 +23,7 @@ function apply(ctx, config) {
23
23
  const forwardMessages = results.map((game, index) => {
24
24
  const imagePath = imagePaths[index];
25
25
  const imageElement = imagePath
26
- ? (0, koishi_1.h)('image', { url: `file://${imagePath}` })
26
+ ? (0, koishi_1.h)('image', { url: imagePath })
27
27
  : (0, koishi_1.h)('text', { content: '封面图加载失败' });
28
28
  const content = [
29
29
  imageElement,
@@ -32,7 +32,6 @@ function apply(ctx, config) {
32
32
  `平台: ${game.platform.join(', ')}`,
33
33
  `语言: ${game.language.join(', ')}`,
34
34
  ].join('\n');
35
- // 使用固定的机器人名称和 ID,避免 bot.username 可能不存在的问题
36
35
  return (0, koishi_1.h)('message', { userId: session.bot.selfId, nickname: 'CheckGal Bot' }, content);
37
36
  });
38
37
  await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
@@ -44,7 +43,7 @@ function apply(ctx, config) {
44
43
  if (!id)
45
44
  return '请输入游戏ID。';
46
45
  let gameInfo = ctx.gameCache.get(id);
47
- // 如果缓存中没有,尝试重新获取(这可能发生在机器人重启后)
46
+ // 如果缓存中没有,尝试重新获取
48
47
  if (!gameInfo) {
49
48
  await session.send('缓存中未找到该游戏信息,正在尝试重新搜索...');
50
49
  const results = await ctx.touchgal.searchGame(String(id), config);
@@ -54,7 +53,6 @@ function apply(ctx, config) {
54
53
  ctx.gameCache.set(id, gameInfo);
55
54
  }
56
55
  else {
57
- // 如果通过ID也搜不到,就直接获取下载链接
58
56
  await session.send(`无法获取游戏“${id}”的详细信息,但仍会尝试获取下载链接...`);
59
57
  }
60
58
  }
@@ -65,7 +63,7 @@ function apply(ctx, config) {
65
63
  const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
66
64
  const imagePath = gameInfo ? await ctx.touchgal.downloadAndConvertImage(gameInfo.banner) : null;
67
65
  const imageElement = imagePath
68
- ? (0, koishi_1.h)('image', { url: `file://${imagePath}` })
66
+ ? (0, koishi_1.h)('image', { url: imagePath })
69
67
  : (0, koishi_1.h)('text', { content: gameInfo ? '封面图加载失败' : '' });
70
68
  const header = [
71
69
  imageElement,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-checkgal",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "个人测试请勿使用",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",