5a6a95682d
The transparency / single-color audit cards held the run + poll timer in local component state, so navigating away destroyed both and onMounted never reconnected — the Celery scan kept running and writing LibraryAuditRun, but the UI forgot it. Now each card, on mount, fetches its rule's latest run (GET /api/cleanup/audit?rule=<rule>&limit=1) and rehydrates: shows progress + resumes polling if still running, or shows the completed result (ready/applied/ error) so the operator can act on it after returning. Adds the ?rule= filter to the audit-history endpoint + cleanup store latestAuditForRule(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import { useApi } from '../composables/useApi.js'
|
|
|
|
export const useCleanupStore = defineStore('cleanup', () => {
|
|
const api = useApi()
|
|
|
|
// Defaults sourced from ImportSettings on mount. Cards pre-fill from
|
|
// these so the common case ("apply current import filters
|
|
// retroactively") is one click; operator can override per-audit.
|
|
const defaults = ref({
|
|
min_width: 0,
|
|
min_height: 0,
|
|
transparency_threshold: 0.9,
|
|
single_color_threshold: 0.95,
|
|
single_color_tolerance: 30,
|
|
})
|
|
|
|
const recentRuns = ref([])
|
|
|
|
async function loadDefaults() {
|
|
const s = await api.get('/api/settings/import')
|
|
defaults.value = {
|
|
min_width: s.min_width ?? 0,
|
|
min_height: s.min_height ?? 0,
|
|
transparency_threshold: s.transparency_threshold ?? 0.9,
|
|
single_color_threshold: s.single_color_threshold ?? 0.95,
|
|
single_color_tolerance: s.single_color_tolerance ?? 30,
|
|
}
|
|
}
|
|
|
|
async function previewMinDim(min_width, min_height) {
|
|
return await api.post('/api/cleanup/min-dimension/preview', {
|
|
body: { min_width, min_height },
|
|
})
|
|
}
|
|
|
|
async function deleteMinDim(min_width, min_height, confirm) {
|
|
return await api.post('/api/cleanup/min-dimension/delete', {
|
|
body: { min_width, min_height, confirm },
|
|
})
|
|
}
|
|
|
|
async function startAudit(rule, params) {
|
|
return await api.post('/api/cleanup/audit', { body: { rule, params } })
|
|
}
|
|
|
|
async function getAudit(id) {
|
|
return await api.get(`/api/cleanup/audit/${id}`)
|
|
}
|
|
|
|
async function loadHistory(limit = 20) {
|
|
const body = await api.get(`/api/cleanup/audit?limit=${limit}`)
|
|
recentRuns.value = body.runs
|
|
return body.runs
|
|
}
|
|
|
|
// The most recent audit run for a given rule, or null. Cards call this on
|
|
// mount to reconnect to a scan that's still running (or to show the last
|
|
// completed result) after the user navigates away and back.
|
|
async function latestAuditForRule(rule) {
|
|
const body = await api.get('/api/cleanup/audit', { params: { rule, limit: 1 } })
|
|
return (body.runs && body.runs[0]) || null
|
|
}
|
|
|
|
async function applyAudit(id, confirm) {
|
|
return await api.post(`/api/cleanup/audit/${id}/apply`, { body: { confirm } })
|
|
}
|
|
|
|
async function cancelAudit(id) {
|
|
return await api.post(`/api/cleanup/audit/${id}/cancel`)
|
|
}
|
|
|
|
return {
|
|
defaults, recentRuns,
|
|
loadDefaults,
|
|
previewMinDim, deleteMinDim,
|
|
startAudit, getAudit, loadHistory, latestAuditForRule, applyAudit, cancelAudit,
|
|
}
|
|
})
|