Delete Comfy input stills after library save, not only outputs.
Purge was skipping Beast input copies and never sending image names to the host agent, so studio temps piled up on the desktop. Also sweep stale hex-/aigen-prefixed inputs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -683,7 +683,10 @@ function defaultSweepPrefixes() {
|
||||
}
|
||||
|
||||
function looksLikeStudioStill(name) {
|
||||
return /^[0-9a-f]{12}(_p\d+)?(_\d{5})?_?\.(png|jpe?g|webp)$/i.test(String(name || ''))
|
||||
// Studio uploads: 12-hex job prefix, or legacy aigen_<hex>_…
|
||||
const n = String(name || '')
|
||||
return /^[0-9a-f]{12}_.+\.(png|jpe?g|webp|gif)$/i.test(n)
|
||||
|| /^aigen_[0-9a-f]+_.+\.(png|jpe?g|webp|gif)$/i.test(n)
|
||||
}
|
||||
|
||||
function isStudioOutputName(file, sub, prefixes) {
|
||||
@@ -697,6 +700,28 @@ function isStudioOutputName(file, sub, prefixes) {
|
||||
return prefixes.some(prefix => file.startsWith(prefix))
|
||||
}
|
||||
|
||||
function sweepStaleStudioInputs(maxAgeMs = 15 * 60 * 1000) {
|
||||
const deleted = []
|
||||
const cutoff = Date.now() - Math.max(60_000, Number(maxAgeMs) || 900_000)
|
||||
for (const root of inputRoots()) {
|
||||
if (!existsSync(root)) continue
|
||||
let files = []
|
||||
try { files = readdirSync(root) } catch { continue }
|
||||
for (const file of files) {
|
||||
if (!looksLikeStudioStill(file)) continue
|
||||
const path = join(root, file)
|
||||
try {
|
||||
const st = statSync(path)
|
||||
if (st.isDirectory() || st.mtimeMs > cutoff) continue
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
if (removeFile(path)) deleted.push(path)
|
||||
}
|
||||
}
|
||||
return deleted
|
||||
}
|
||||
|
||||
function sweepStaleStudioOutputs(prefixes, subfolders, maxAgeMs = 15 * 60 * 1000) {
|
||||
const deleted = []
|
||||
const names = [...new Set([...defaultSweepPrefixes(), ...(prefixes || [])])].map(item => String(item || '').trim()).filter(Boolean)
|
||||
@@ -784,6 +809,7 @@ function purgeDesktopFiles(body) {
|
||||
))
|
||||
}
|
||||
if (allowSweep) {
|
||||
deleted.push(...sweepStaleStudioInputs(body?.sweepMaxAgeMs))
|
||||
deleted.push(...sweepStaleStudioOutputs(body?.sweepPrefixes, body?.sweepSubfolders, body?.sweepMaxAgeMs))
|
||||
}
|
||||
const unique = [...new Set(deleted)]
|
||||
@@ -911,7 +937,10 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
if (req.method === 'POST' && url.pathname === '/sweep') {
|
||||
const body = await readJson(req)
|
||||
const deleted = sweepStaleStudioOutputs(body?.sweepPrefixes, body?.sweepSubfolders, body?.sweepMaxAgeMs)
|
||||
const deleted = [
|
||||
...sweepStaleStudioInputs(body?.sweepMaxAgeMs),
|
||||
...sweepStaleStudioOutputs(body?.sweepPrefixes, body?.sweepSubfolders, body?.sweepMaxAgeMs)
|
||||
]
|
||||
console.log(JSON.stringify({
|
||||
src: 'comfy-host-agent',
|
||||
event: 'sweep',
|
||||
|
||||
Reference in New Issue
Block a user