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.
- package/index.js +14 -4
- 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(
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|