koishi-plugin-ggcevo 1.3.1 → 1.3.2
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/index.js +34 -4
- package/package.json +1 -1
- package/readme.md +7 -0
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -30,6 +40,10 @@ __export(src_exports, {
|
|
|
30
40
|
});
|
|
31
41
|
module.exports = __toCommonJS(src_exports);
|
|
32
42
|
var import_koishi = require("koishi");
|
|
43
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
44
|
+
var import_node_path = __toESM(require("node:path"));
|
|
45
|
+
var import_node_crypto = require("node:crypto");
|
|
46
|
+
var import_promises = require("node:fs/promises");
|
|
33
47
|
var name = "ggcevo";
|
|
34
48
|
var Config = import_koishi.Schema.intersect([
|
|
35
49
|
import_koishi.Schema.object({
|
|
@@ -2423,10 +2437,10 @@ ${rewardLines.join("\n")}` : "";
|
|
|
2423
2437
|
return record || null;
|
|
2424
2438
|
}
|
|
2425
2439
|
}, "getValidDocsToken");
|
|
2426
|
-
const docsApiRequest = /* @__PURE__ */ __name(async (method,
|
|
2440
|
+
const docsApiRequest = /* @__PURE__ */ __name(async (method, path2, data) => {
|
|
2427
2441
|
const token = await getValidDocsToken();
|
|
2428
2442
|
if (!token) throw new Error("腾讯文档应用级账号不可用, 请检查插件配置(Client ID / Client Secret)");
|
|
2429
|
-
const url = `https://docs.qq.com/openapi${
|
|
2443
|
+
const url = `https://docs.qq.com/openapi${path2}`;
|
|
2430
2444
|
const headers = {
|
|
2431
2445
|
"Access-Token": token.access_token,
|
|
2432
2446
|
"Client-Id": config.tencentDocsClientId,
|
|
@@ -2952,18 +2966,34 @@ ${rewardLines.join("\n")}` : "";
|
|
|
2952
2966
|
</body>
|
|
2953
2967
|
</html>`;
|
|
2954
2968
|
}, "buildMenuHtml");
|
|
2969
|
+
const menuCacheDir = import_node_path.default.resolve(ctx.baseDir, "data/ggcevo/menu");
|
|
2955
2970
|
const renderMenuImage = /* @__PURE__ */ __name(async (html) => {
|
|
2956
2971
|
const logger = ctx.logger("ggcevo");
|
|
2972
|
+
const hash = (0, import_node_crypto.createHash)("sha256").update(html).digest("hex");
|
|
2973
|
+
const cachePath = import_node_path.default.resolve(menuCacheDir, `${hash}.jpg`);
|
|
2974
|
+
if (import_node_fs.default.existsSync(cachePath)) {
|
|
2975
|
+
const cached = await (0, import_promises.readFile)(cachePath);
|
|
2976
|
+
return import_koishi.h.image(`data:image/jpeg;base64,${cached.toString("base64")}`);
|
|
2977
|
+
}
|
|
2957
2978
|
if (!ctx.puppeteer) {
|
|
2958
2979
|
logger.warn("[menu-render] 未启用 puppeteer 服务");
|
|
2959
2980
|
return "⚠️ 未启用 puppeteer 服务,无法渲染图片菜单。请安装并启用 `koishi-plugin-puppeteer` 或 `@shangxueink/puppeteer-without-canvas`。";
|
|
2960
2981
|
}
|
|
2961
2982
|
const page = await ctx.puppeteer.page();
|
|
2962
2983
|
try {
|
|
2963
|
-
await page.setViewport({ width:
|
|
2964
|
-
await page.setContent(html
|
|
2984
|
+
await page.setViewport({ width: 1280, height: 100, deviceScaleFactor: 1 });
|
|
2985
|
+
await page.setContent(html);
|
|
2986
|
+
await page.waitForNetworkIdle();
|
|
2965
2987
|
const img = await page.screenshot({ type: "jpeg", quality: 85, fullPage: true, encoding: "binary" });
|
|
2966
2988
|
logger.info("[menu-render] 菜单图渲染完成, 体积 %s KB", (img.length / 1024).toFixed(1));
|
|
2989
|
+
try {
|
|
2990
|
+
await (0, import_promises.mkdir)(menuCacheDir, { recursive: true });
|
|
2991
|
+
const files = await (0, import_promises.readdir)(menuCacheDir);
|
|
2992
|
+
for (const file of files) await (0, import_promises.unlink)(import_node_path.default.resolve(menuCacheDir, file));
|
|
2993
|
+
await (0, import_promises.writeFile)(cachePath, img);
|
|
2994
|
+
} catch (e) {
|
|
2995
|
+
logger.error("[menu-render] 写入菜单图缓存失败: %o", e);
|
|
2996
|
+
}
|
|
2967
2997
|
return import_koishi.h.image(`data:image/jpeg;base64,${img.toString("base64")}`);
|
|
2968
2998
|
} catch (e) {
|
|
2969
2999
|
logger.warn("[menu-render] 渲染菜单图片失败: %o", e);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -179,6 +179,13 @@ npm install koishi-plugin-ggcevo
|
|
|
179
179
|
|
|
180
180
|
## 更新日志
|
|
181
181
|
|
|
182
|
+
### v1.3.2
|
|
183
|
+
|
|
184
|
+
图片菜单渲染对齐 preview-help 方案,新增磁盘缓存。
|
|
185
|
+
|
|
186
|
+
- **新增图片菜单磁盘缓存**:`咕咕之战` 图片菜单按 HTML 内容 hash 缓存到 `data/ggcevo/menu/`,命中缓存直接读回图片(免去重复渲染、无需 puppeteer 也可返回缓存图),渲染成功后会清理旧缓存文件
|
|
187
|
+
- **渲染参数对齐 preview-help**:viewport 由 900×DPR2 调整为 1280×DPR1,`setContent` 后改用 `waitForNetworkIdle()` 等待页面网络空闲
|
|
188
|
+
|
|
182
189
|
### v1.3.1
|
|
183
190
|
|
|
184
191
|
取消 Markdown 按钮菜单,改为可配置的文字/图片菜单。
|