Delete imported Comfy stills from disk instead of looking for them in the video folder.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -530,34 +530,73 @@ function sharedRoots() {
|
||||
const local = process.env.LOCALAPPDATA || ''
|
||||
return {
|
||||
input: process.env.COMFY_INPUT_DIR || join(local, 'Comfy-Desktop', 'ComfyUI-Shared', 'input'),
|
||||
output: process.env.COMFY_OUTPUT_DIR || join(local, 'Comfy-Desktop', 'ComfyUI-Shared', 'output')
|
||||
output: process.env.COMFY_OUTPUT_DIR || join(local, 'Comfy-Desktop', 'ComfyUI-Shared', 'output'),
|
||||
temp: process.env.COMFY_TEMP_DIR || join(local, 'Comfy-Desktop', 'ComfyUI-Shared', 'temp')
|
||||
}
|
||||
}
|
||||
|
||||
function inputRoots() {
|
||||
function installLeafRoots(leaf) {
|
||||
const local = process.env.LOCALAPPDATA || ''
|
||||
const roots = [
|
||||
process.env.COMFY_INPUT_DIR || join(local, 'Comfy-Desktop', 'ComfyUI-Shared', 'input')
|
||||
]
|
||||
const cwd = process.env.COMFY_LAUNCH_CWD
|
||||
if (cwd) roots.push(join(cwd, 'input'))
|
||||
const roots = []
|
||||
const installs = join(local, 'Comfy-Desktop', 'ComfyUI-Installs')
|
||||
try {
|
||||
for (const dir of readdirSync(installs, { withFileTypes: true })) {
|
||||
if (!dir.isDirectory()) continue
|
||||
roots.push(join(installs, dir.name, 'ComfyUI', 'input'))
|
||||
roots.push(join(installs, dir.name, 'ComfyUI', leaf))
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
return roots
|
||||
}
|
||||
|
||||
function inputRoots() {
|
||||
const roots = [sharedRoots().input]
|
||||
const cwd = process.env.COMFY_LAUNCH_CWD
|
||||
if (cwd) roots.push(join(cwd, 'input'))
|
||||
roots.push(...installLeafRoots('input'))
|
||||
return [...new Set(roots)]
|
||||
}
|
||||
|
||||
function outputRoots() {
|
||||
const roots = [sharedRoots().output]
|
||||
const cwd = process.env.COMFY_LAUNCH_CWD
|
||||
if (cwd) roots.push(join(cwd, 'output'))
|
||||
if (cwd) {
|
||||
roots.push(join(cwd, 'output'))
|
||||
roots.push(join(cwd, 'ComfyUI', 'output'))
|
||||
}
|
||||
roots.push(...installLeafRoots('output'))
|
||||
return [...new Set(roots)]
|
||||
}
|
||||
|
||||
function tempRoots() {
|
||||
const roots = [sharedRoots().temp]
|
||||
const cwd = process.env.COMFY_LAUNCH_CWD
|
||||
if (cwd) {
|
||||
roots.push(join(cwd, 'temp'))
|
||||
roots.push(join(cwd, 'ComfyUI', 'temp'))
|
||||
}
|
||||
roots.push(...installLeafRoots('temp'))
|
||||
return [...new Set(roots)]
|
||||
}
|
||||
|
||||
function rootsForType(type) {
|
||||
if (type === 'input') return inputRoots()
|
||||
if (type === 'temp') return [...tempRoots(), ...outputRoots()]
|
||||
return [...outputRoots(), ...tempRoots()]
|
||||
}
|
||||
|
||||
function removeNamedFile(roots, filename, subfolders) {
|
||||
const deleted = []
|
||||
const subs = [...new Set((subfolders || []).map(item => String(item || '')))]
|
||||
for (const root of roots) {
|
||||
if (!existsSync(root)) continue
|
||||
for (const sub of subs) {
|
||||
const path = safeFile(root, sub, filename)
|
||||
if (removeFile(path)) deleted.push(path)
|
||||
}
|
||||
}
|
||||
return deleted
|
||||
}
|
||||
|
||||
function safeFile(root, subfolder, filename) {
|
||||
const name = basename(String(filename || ''))
|
||||
if (!name || name === '.' || name === '..') return null
|
||||
@@ -597,43 +636,37 @@ function purgeDesktopFiles(body) {
|
||||
].map(name => String(name || '').trim()).filter(Boolean)
|
||||
const imageSub = String(body?.imageSubfolder || '')
|
||||
for (const imageName of names) {
|
||||
for (const root of inputRoots()) {
|
||||
if (!existsSync(root)) continue
|
||||
const nested = safeFile(root, imageSub, imageName)
|
||||
if (removeFile(nested)) deleted.push(nested)
|
||||
if (imageSub) {
|
||||
const flat = safeFile(root, '', imageName)
|
||||
if (removeFile(flat)) deleted.push(flat)
|
||||
}
|
||||
}
|
||||
deleted.push(...removeNamedFile(inputRoots(), imageName, [imageSub, '']))
|
||||
}
|
||||
const video = body?.video || null
|
||||
const videoName = String(video?.filename || '')
|
||||
if (videoName) {
|
||||
for (const root of outputRoots()) {
|
||||
const nested = safeFile(root, video.subfolder || 'video', videoName)
|
||||
if (removeFile(nested)) deleted.push(nested)
|
||||
const flat = safeFile(root, '', videoName)
|
||||
if (removeFile(flat)) deleted.push(flat)
|
||||
}
|
||||
const type = String(video?.type || 'output')
|
||||
const imageOut = /\.(png|jpe?g|webp|gif)$/i.test(videoName)
|
||||
deleted.push(...removeNamedFile(
|
||||
rootsForType(type),
|
||||
videoName,
|
||||
[video.subfolder, imageOut ? '' : 'video', '']
|
||||
))
|
||||
}
|
||||
const output = body?.output || null
|
||||
const outputName = String(output?.filename || '')
|
||||
if (outputName) {
|
||||
const type = String(output?.type || 'output')
|
||||
const sub = String(output?.subfolder || '')
|
||||
const rootsForType = type === 'input' ? inputRoots() : outputRoots()
|
||||
for (const root of rootsForType) {
|
||||
if (!existsSync(root)) continue
|
||||
const nested = safeFile(root, sub, outputName)
|
||||
if (removeFile(nested)) deleted.push(nested)
|
||||
if (sub) {
|
||||
const flat = safeFile(root, '', outputName)
|
||||
if (removeFile(flat)) deleted.push(flat)
|
||||
}
|
||||
}
|
||||
deleted.push(...removeNamedFile(
|
||||
rootsForType(String(output?.type || 'output')),
|
||||
outputName,
|
||||
[output.subfolder, '']
|
||||
))
|
||||
}
|
||||
console.log(JSON.stringify({ src: 'comfy-host-agent', event: 'purge', deleted: deleted.length, files: deleted.map((path) => basename(path)), imageNames: names }))
|
||||
console.log(JSON.stringify({
|
||||
src: 'comfy-host-agent',
|
||||
event: 'purge',
|
||||
deleted: deleted.length,
|
||||
files: deleted.map((path) => basename(path)),
|
||||
imageNames: names,
|
||||
video: videoName || null,
|
||||
output: outputName || null
|
||||
}))
|
||||
return { ok: true, deleted }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user