koishi-plugin-p-draw 1.5.4 → 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 (2) hide show
  1. package/index.js +14 -4
  2. package/package.json +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
 
@@ -2152,6 +2161,7 @@ exports.apply = async function apply(ctx, cfg) {
2152
2161
  for (const file of files) {
2153
2162
  try { fs.unlinkSync(path.join(tempDir, file)) } catch (e) { /* ignore */ }
2154
2163
  }
2164
+ try { fs.rmdirSync(tempDir) } catch (e) { /* ignore */ }
2155
2165
  } catch (e) { /* ignore */ }
2156
2166
  })
2157
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.4",
4
+ "version": "1.5.5",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js",