koishi-plugin-p-draw 1.3.0 → 1.3.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.
Files changed (3) hide show
  1. package/index.js +7 -3
  2. package/lib/media.js +22 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -150,6 +150,7 @@ const {
150
150
  animaOotdI2IWorkflow, buildI2IWorkflow, customWorkflow,
151
151
  } = require('./lib/workflows')
152
152
  const { outputImages, waitComfyResult } = require('./lib/comfy')
153
+ const { materializeImageSource } = require('./lib/media')
153
154
  const {
154
155
  MULTI_PERSON_NEGATIVE_TAGS, buildMultiPersonPlanPrompt, parseMultiPersonPlan,
155
156
  renderMultiPersonCharacter, multiPersonAutoSize,
@@ -484,9 +485,12 @@ exports.apply = async function apply(ctx, cfg) {
484
485
  }
485
486
  }
486
487
 
487
- // 发图:引用用户触发指令的原消息,失败回退普通发送
488
- async function sendImagesWithQuote(session, outputs) {
489
- const imageElements = outputs.map(src => h.image(src))
488
+ // 发图:引用用户触发指令的原消息,失败回退普通发送
489
+ async function sendImagesWithQuote(session, outputs) {
490
+ const imageElements = await Promise.all(outputs.map(async (src) => {
491
+ const materialized = await materializeImageSource(src)
492
+ return Buffer.isBuffer(materialized) ? h.image(materialized) : h.image(src)
493
+ }))
490
494
  try {
491
495
  await session.send(h.quote(session.messageId) + imageElements.join(''))
492
496
  } catch (e) {
package/lib/media.js ADDED
@@ -0,0 +1,22 @@
1
+ // 消息媒体来源处理。
2
+ // OneBot 不一定能读取机器人进程本地的 file:// 路径,因此发送前转换为 Buffer。
3
+
4
+ const fsp = require('fs/promises')
5
+ const { fileURLToPath } = require('url')
6
+
7
+ async function materializeImageSource(source, readFile = fsp.readFile) {
8
+ if (typeof source !== 'string' || !/^file:\/\//i.test(source)) return source
9
+ let filePath
10
+ try {
11
+ filePath = fileURLToPath(source)
12
+ } catch (e) {
13
+ return source
14
+ }
15
+ try {
16
+ return await readFile(filePath)
17
+ } catch (e) {
18
+ return source
19
+ }
20
+ }
21
+
22
+ module.exports = { materializeImageSource }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-p-draw",
3
3
  "description": "p点-绘图,连接本地 ComfyUI 生图。支持自然语言优化、尺寸选择、画师组、固定角色、生成队列,需要配合 p-qiandao 使用",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js",