koishi-plugin-p-draw 1.5.3 → 1.5.5

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 +19 -7
  2. package/package.json +1 -1
  3. package/readme.md +1 -1
package/index.js CHANGED
@@ -2,6 +2,7 @@ const { Schema, h } = require('koishi')
2
2
  const fs = require('fs')
3
3
  const fsp = require('fs/promises')
4
4
  const path = require('path')
5
+ const os = require('os')
5
6
  const crypto = require('crypto')
6
7
  const { pathToFileURL } = require('url')
7
8
 
@@ -173,10 +174,18 @@ exports.apply = async function apply(ctx, cfg) {
173
174
  // 用户自选模型偏好(userid -> unet 文件名),持久化在 p_draw_config.user_models
174
175
  if (!cfg.userModels || typeof cfg.userModels !== 'object') cfg.userModels = {}
175
176
 
176
- const tempDir = path.join(__dirname, 'temp')
177
- if (!fs.existsSync(tempDir)) {
178
- try { fs.mkdirSync(tempDir, { recursive: true }) } catch (e) { logger.warn('无法创建临时目录:' + e.message) }
179
- }
177
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pdraw-'))
178
+ // 启动时清理上次运行遗留的临时文件
179
+ try {
180
+ const leftovers = fs.readdirSync(os.tmpdir()).filter((n) => n.startsWith('pdraw-'))
181
+ for (const name of leftovers) {
182
+ const dir = path.join(os.tmpdir(), name)
183
+ try {
184
+ for (const file of fs.readdirSync(dir)) fs.unlinkSync(path.join(dir, file))
185
+ fs.rmdirSync(dir)
186
+ } catch (e) { /* ignore */ }
187
+ }
188
+ } catch (e) { /* ignore */ }
180
189
 
181
190
  const baseUrl = () => normalizeBaseUrl(cfg.comfyuiBaseUrl)
182
191
 
@@ -462,9 +471,11 @@ exports.apply = async function apply(ctx, cfg) {
462
471
  return { notices }
463
472
  }
464
473
 
465
- function buildChargeNotice({ isAdmin, totalPrice, unetName, seeds }) {
466
- if (isAdmin || !seeds.length) return ''
467
- return `已扣除 ${totalPrice} P 点,当前模型:${unetName},--seed=${seeds.join(',')}`
474
+ function buildChargeNotice({ isAdmin, totalPrice, unetName, seeds }) {
475
+ if (!seeds.length) return ''
476
+ const modelSeed = `当前模型:${unetName},--seed=${seeds.join(',')}`
477
+ if (isAdmin) return modelSeed
478
+ return `已扣除 ${totalPrice} P 点,${modelSeed}`
468
479
  }
469
480
 
470
481
  function buildGenerationReply(session, { successCount, count, failures, notes = [], chargeNotice = '' }) {
@@ -2150,6 +2161,7 @@ exports.apply = async function apply(ctx, cfg) {
2150
2161
  for (const file of files) {
2151
2162
  try { fs.unlinkSync(path.join(tempDir, file)) } catch (e) { /* ignore */ }
2152
2163
  }
2164
+ try { fs.rmdirSync(tempDir) } catch (e) { /* ignore */ }
2153
2165
  } catch (e) { /* ignore */ }
2154
2166
  })
2155
2167
 
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.5.3",
4
+ "version": "1.5.5",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js",
package/readme.md CHANGED
@@ -20,7 +20,7 @@ p点-绘图插件,连接本地 ComfyUI 生图,参考 AstrBot 的 [anima 绘
20
20
  - 生成队列(逐张顺序执行,防止争抢 GPU)。
21
21
  - `p-draw 状态` 查看 ComfyUI 连接状态与模型可用性。
22
22
  - `p-draw help`(或 `帮助`)查看全部指令帮助,包含生成 / 多人 / 批量张数 / 尺寸 / 画师组 / 状态等。
23
- - 发图时会以合并转发发送,每张图片后附对应的 Positive / Negative 提示词;生成完成消息会显示实际模型和 seed(如 `已扣除 750 P 点,当前模型:animagine-xl-3.1.safetensors,--seed=123456`)。
23
+ - 发图时会以合并转发发送,每张图片后附对应的 Positive / Negative 提示词;生成完成消息会显示实际模型和 seed(如 `已扣除 750 P 点,当前模型:animagine-xl-3.1.safetensors,--seed=123456`)。管理员/免扣费用户不显示扣费金额,但仍显示模型和 seed。
24
24
 
25
25
  ## 安装
26
26