koishi-plugin-jryspro-fast 2.2.1 → 2.2.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/CHANGELOG.md +6 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +31 -52
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
40
40
|
var import_node_fs = __toESM(require("node:fs"));
|
|
41
41
|
var import_node_path = __toESM(require("node:path"));
|
|
42
42
|
var import_node_crypto = __toESM(require("node:crypto"));
|
|
43
|
-
var
|
|
43
|
+
var import_wasm_vips = __toESM(require("wasm-vips"));
|
|
44
44
|
var import_koishi = require("koishi");
|
|
45
45
|
var name = "jryspro-fast";
|
|
46
46
|
var logger = new import_koishi.Logger(name);
|
|
@@ -89,13 +89,14 @@ var schema = import_koishi.Schema.object({
|
|
|
89
89
|
avatarUrl: import_koishi.Schema.string().role("link").description("默认头像URL(https?://或者file:///)")
|
|
90
90
|
});
|
|
91
91
|
var inject = ["vercelSatoriPngService", "database"];
|
|
92
|
-
function apply(ctx, config) {
|
|
93
|
-
let fileType;
|
|
92
|
+
async function apply(ctx, config) {
|
|
93
|
+
let fileType = await import("file-type");
|
|
94
|
+
const vips = await (0, import_wasm_vips.default)();
|
|
94
95
|
const template = import_node_fs.default.readFileSync(import_node_path.default.join(__dirname, "../assets/template.html"), "utf8").replace(/[\s\S]*<body[^>]*>([\s\S]*)<\/body>[\s\S]*/, "$1").trim();
|
|
95
96
|
const template2 = import_node_fs.default.readFileSync(import_node_path.default.join(__dirname, "../assets/template2.html"), "utf8").replace(/[\s\S]*<body[^>]*>([\s\S]*)<\/body>[\s\S]*/, "$1").trim();
|
|
96
|
-
const defaultAvatar = `data:image/png;base64,` + Buffer.from(
|
|
97
|
-
"
|
|
98
|
-
);
|
|
97
|
+
const defaultAvatar = `data:image/png;base64,` + Buffer.from(
|
|
98
|
+
import_node_fs.default.readFileSync(import_node_path.default.join(__dirname, "../assets/avatar.png"))
|
|
99
|
+
).toString("base64");
|
|
99
100
|
const jrysJson = JSON.parse(
|
|
100
101
|
import_node_fs.default.readFileSync(import_node_path.default.join(__dirname, "../assets/jrys.json"), "utf8")
|
|
101
102
|
);
|
|
@@ -218,7 +219,7 @@ function apply(ctx, config) {
|
|
|
218
219
|
needMetadata: true
|
|
219
220
|
});
|
|
220
221
|
width += Math.round(
|
|
221
|
-
(height - 14) / background.
|
|
222
|
+
(height - 14) / background.metaData.height * background.metaData.width
|
|
222
223
|
);
|
|
223
224
|
const replacedContent = template2.replace(
|
|
224
225
|
/rgba\(255, 255, 255, 0\.6\)/g,
|
|
@@ -278,13 +279,6 @@ function apply(ctx, config) {
|
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
});
|
|
281
|
-
async function loadFileType() {
|
|
282
|
-
if (!fileType) {
|
|
283
|
-
fileType = await import("file-type");
|
|
284
|
-
}
|
|
285
|
-
return fileType;
|
|
286
|
-
}
|
|
287
|
-
__name(loadFileType, "loadFileType");
|
|
288
282
|
function getUserKey(session) {
|
|
289
283
|
let etime = (/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0);
|
|
290
284
|
let userId;
|
|
@@ -311,8 +305,11 @@ function apply(ctx, config) {
|
|
|
311
305
|
return jrysJson[getUserKey(session).key];
|
|
312
306
|
}
|
|
313
307
|
__name(getJrys, "getJrys");
|
|
314
|
-
async function downloadUrl(
|
|
315
|
-
|
|
308
|
+
async function downloadUrl({
|
|
309
|
+
url,
|
|
310
|
+
cover,
|
|
311
|
+
needMetadata
|
|
312
|
+
}) {
|
|
316
313
|
if (/^data:/i.test(url)) {
|
|
317
314
|
return { base64: url };
|
|
318
315
|
}
|
|
@@ -325,57 +322,39 @@ function apply(ctx, config) {
|
|
|
325
322
|
logger.error("未知url类型");
|
|
326
323
|
throw "渲染失败,不知道发生了啥";
|
|
327
324
|
}
|
|
328
|
-
await loadFileType();
|
|
329
325
|
const imgType = await fileType.fileTypeFromBuffer(imgData);
|
|
330
|
-
let
|
|
331
|
-
let
|
|
332
|
-
const
|
|
333
|
-
if (!
|
|
334
|
-
|
|
326
|
+
let img;
|
|
327
|
+
let metaData;
|
|
328
|
+
const touchImg = /* @__PURE__ */ __name(() => {
|
|
329
|
+
if (!img) {
|
|
330
|
+
img = vips.Image.newFromBuffer(imgData);
|
|
335
331
|
}
|
|
336
|
-
}, "
|
|
332
|
+
}, "touchImg");
|
|
337
333
|
if (needMetadata) {
|
|
338
|
-
|
|
339
|
-
|
|
334
|
+
touchImg();
|
|
335
|
+
metaData = {
|
|
336
|
+
width: img.width,
|
|
337
|
+
height: img.height
|
|
338
|
+
};
|
|
340
339
|
}
|
|
341
340
|
if (cover) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
const newWh = {
|
|
347
|
-
width: cover.width,
|
|
348
|
-
height: cover.height
|
|
349
|
-
};
|
|
350
|
-
if (metadata.height * (cover.width / metadata.width) < cover.height) {
|
|
351
|
-
newWh.width = Math.round(
|
|
352
|
-
metadata.width * (cover.height / metadata.height)
|
|
353
|
-
);
|
|
354
|
-
} else {
|
|
355
|
-
newWh.height = Math.round(
|
|
356
|
-
metadata.height * (cover.width / metadata.width)
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
imgSharp.resize(newWh);
|
|
360
|
-
imgSharp.extract({
|
|
361
|
-
left: Math.round((newWh.width - cover.width) / 2),
|
|
362
|
-
width: cover.width,
|
|
363
|
-
top: Math.round((newWh.height - cover.height) / 2),
|
|
364
|
-
height: cover.height
|
|
341
|
+
img = vips.Image.thumbnailBuffer(imgData, cover.width, {
|
|
342
|
+
height: cover.height,
|
|
343
|
+
crop: vips.Interesting.centre
|
|
365
344
|
});
|
|
366
345
|
if (imgType.ext !== "webp") {
|
|
367
|
-
imgData =
|
|
346
|
+
imgData = Buffer.from(img.pngsaveBuffer());
|
|
368
347
|
}
|
|
369
348
|
}
|
|
370
349
|
let mime = imgType.mime;
|
|
371
350
|
if (imgType.ext === "webp") {
|
|
372
|
-
|
|
373
|
-
imgData =
|
|
351
|
+
touchImg();
|
|
352
|
+
imgData = Buffer.from(img.pngsaveBuffer());
|
|
374
353
|
mime = "image/png";
|
|
375
354
|
}
|
|
376
355
|
return {
|
|
377
356
|
base64: `data:${mime};base64,` + imgData.toString("base64"),
|
|
378
|
-
|
|
357
|
+
metaData
|
|
379
358
|
};
|
|
380
359
|
}
|
|
381
360
|
__name(downloadUrl, "downloadUrl");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-jryspro-fast",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/pgnqukezrdxmhjso/koishi-plugin-jryspro-fast",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"koishi": "^4.16.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"koishi-plugin-vercel-satori-png-service": "^0.1.
|
|
55
|
+
"koishi-plugin-vercel-satori-png-service": "^0.1.7"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"file-type": "^21.0.0",
|
|
59
|
-
"
|
|
59
|
+
"wasm-vips": "^0.0.16"
|
|
60
60
|
}
|
|
61
61
|
}
|