Let finished caption jobs be dismissed from the Queue panel.
This commit is contained in:
@@ -107,6 +107,8 @@ export interface StudioJob {
|
||||
lastError?: string
|
||||
waitReason?: string
|
||||
resultText?: string
|
||||
/** Hidden from Queue UI; keeps resultText on the stored row. */
|
||||
dismissed?: boolean
|
||||
}
|
||||
|
||||
type StudioQueueStore = {
|
||||
@@ -535,6 +537,40 @@ function canCancelStudioStatus(status: StudioJobStatus) {
|
||||
return status === 'waiting' || status === 'held' || status === 'running' || status === 'error'
|
||||
}
|
||||
|
||||
function isFinishedStudioStatus(status: StudioJobStatus) {
|
||||
return status === 'complete' || status === 'error' || status === 'cancelled'
|
||||
}
|
||||
|
||||
/** Hide a finished studio-queue row from the Queue panel (keeps resultText). */
|
||||
export async function dismissStudioJob(owner: string, id: string) {
|
||||
return mutate(owner, (jobs) => {
|
||||
const job = jobs.find(item => item.id === id)
|
||||
if (!job) throw createError({ statusCode: 404, statusMessage: 'Queued job not found' })
|
||||
if (!isFinishedStudioStatus(job.status)) {
|
||||
throw createError({ statusCode: 409, statusMessage: 'Only finished jobs can be dismissed' })
|
||||
}
|
||||
job.dismissed = true
|
||||
job.updatedAt = Date.now()
|
||||
return structuredClone(job)
|
||||
})
|
||||
}
|
||||
|
||||
/** Dismiss finished studio-queue rows (caption complete cards, errors, etc.). */
|
||||
export async function dismissFinishedStudioJobs(owner: string, ids?: string[]) {
|
||||
return mutate(owner, (jobs) => {
|
||||
let cleared = 0
|
||||
for (const job of jobs) {
|
||||
if (ids?.length && !ids.includes(job.id)) continue
|
||||
if (job.dismissed) continue
|
||||
if (!isFinishedStudioStatus(job.status)) continue
|
||||
job.dismissed = true
|
||||
job.updatedAt = Date.now()
|
||||
cleared += 1
|
||||
}
|
||||
return cleared
|
||||
})
|
||||
}
|
||||
|
||||
export async function cancelStudioJob(owner: string, id: string) {
|
||||
const before = readJobs(owner).find(item => item.id === id)
|
||||
if (!before) throw createError({ statusCode: 404, statusMessage: 'Queued job not found' })
|
||||
|
||||
Reference in New Issue
Block a user