koishi-plugin-checkgal 1.1.0 → 1.1.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 +1 -2
- package/lib/api.js +1 -47
- package/package.json +1 -1
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<
|
|
10
|
+
downloadAndConvertImage(url: string): Promise<Buffer | null>;
|
|
12
11
|
}
|
package/lib/api.js
CHANGED
|
@@ -1,55 +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
|
-
// 确保临时目录存在
|
|
50
|
-
ctx.on('ready', async () => {
|
|
51
|
-
await fs_1.promises.mkdir(this.tempDir, { recursive: true });
|
|
52
|
-
});
|
|
53
12
|
}
|
|
54
13
|
async searchGame(keyword, config) {
|
|
55
14
|
const url = 'https://www.touchgal.us/api/search';
|
|
@@ -113,12 +72,7 @@ class TouchGalAPI {
|
|
|
113
72
|
// 类型守卫,确保 response 是 ArrayBuffer
|
|
114
73
|
if (!(response instanceof ArrayBuffer))
|
|
115
74
|
return null;
|
|
116
|
-
|
|
117
|
-
// 生成唯一文件名并写入临时目录
|
|
118
|
-
const hash = crypto.createHash('md5').update(url).digest('hex');
|
|
119
|
-
const filePath = path.join(this.tempDir, `${hash}.jpg`);
|
|
120
|
-
await fs_1.promises.writeFile(filePath, imageBuffer);
|
|
121
|
-
return filePath;
|
|
75
|
+
return (0, sharp_1.default)(Buffer.from(response)).jpeg().toBuffer();
|
|
122
76
|
}
|
|
123
77
|
catch (error) {
|
|
124
78
|
this.logger.error(`Failed to download or convert image from ${url}:`, error);
|