koishi-plugin-starfx-bot 0.19.8 → 0.19.9
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 +24 -3
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/index.js
CHANGED
|
@@ -970,7 +970,7 @@ var package_default = {
|
|
|
970
970
|
contributors: [
|
|
971
971
|
"StarFreedomX <starfreedomx@outlook.com>"
|
|
972
972
|
],
|
|
973
|
-
version: "0.19.
|
|
973
|
+
version: "0.19.9",
|
|
974
974
|
main: "lib/index.js",
|
|
975
975
|
typings: "lib/index.d.ts",
|
|
976
976
|
files: [
|
|
@@ -1296,8 +1296,24 @@ function apply(ctx, cfg) {
|
|
|
1296
1296
|
const LOCAL_PATH_REGEX = /^(\/|\\|file:\/\/\/|\.|[A-Za-z]:\\|\/home\/|\/root\/|\.\.\/|\.\/)/;
|
|
1297
1297
|
return LOCAL_PATH_REGEX.test(src);
|
|
1298
1298
|
}, convertUriToLocalPath = function(uri) {
|
|
1299
|
-
if (uri.startsWith("file
|
|
1300
|
-
|
|
1299
|
+
if (uri.startsWith("file://")) {
|
|
1300
|
+
try {
|
|
1301
|
+
const url = new URL(uri);
|
|
1302
|
+
let filePath = url.pathname;
|
|
1303
|
+
if (process.platform === "win32") {
|
|
1304
|
+
if (filePath.match(/^\/[A-Za-z]:\//)) {
|
|
1305
|
+
filePath = filePath.substring(1);
|
|
1306
|
+
} else {
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return import_node_path3.default.normalize(filePath);
|
|
1310
|
+
} catch (e) {
|
|
1311
|
+
starfxLogger.error("URL解析失败:", e);
|
|
1312
|
+
return uri;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
if (import_node_path3.default.isAbsolute(uri) || uri.startsWith(".") || uri.startsWith("..")) {
|
|
1316
|
+
return import_node_path3.default.normalize(uri);
|
|
1301
1317
|
}
|
|
1302
1318
|
return uri;
|
|
1303
1319
|
}, toBase64String = function(src) {
|
|
@@ -1327,9 +1343,11 @@ function apply(ctx, cfg) {
|
|
|
1327
1343
|
__name(guessTypeFromElement, "guessTypeFromElement");
|
|
1328
1344
|
ctx.before("send", (session, options) => {
|
|
1329
1345
|
for (const element of session.elements) {
|
|
1346
|
+
console.log(element);
|
|
1330
1347
|
const src = element.attrs?.src;
|
|
1331
1348
|
if (!src || !isLocalPath(src)) continue;
|
|
1332
1349
|
const filePath = convertUriToLocalPath(src);
|
|
1350
|
+
console.log(filePath);
|
|
1333
1351
|
const mimeType = import_mime_types.default.lookup(filePath) || guessTypeFromElement(element.type) || "application/octet-stream";
|
|
1334
1352
|
const base64 = toBase64String(filePath);
|
|
1335
1353
|
if (base64) element.attrs.src = `data:${mimeType};base64,${base64}`;
|
|
@@ -1360,6 +1378,9 @@ function apply(ctx, cfg) {
|
|
|
1360
1378
|
});
|
|
1361
1379
|
if (process.env.NODE_ENV === "development") {
|
|
1362
1380
|
ctx.command("test [params]").action(async ({ session, options }, params) => {
|
|
1381
|
+
const mess = import_koishi5.h.image("file:///E:/TEMP/saaya-birthday1.png");
|
|
1382
|
+
console.log(mess);
|
|
1383
|
+
await session.send(mess);
|
|
1363
1384
|
});
|
|
1364
1385
|
ctx.middleware(async (session, next) => {
|
|
1365
1386
|
return next();
|
package/package.json
CHANGED
package/readme.md
CHANGED