Files
FabledCurator/frontend/src/stores/downloads.js
T
bvandeusen 2358cedf3e feat(dashboards): scheduler health strip, failing-source rollup, 24h activity sparkline, credential staleness nudge
D1 scheduler visibility: AppSetting last-tick stamp on every Beat tick +
GET /api/sources/schedule-status (last_tick_at/next_due_at/due_now/auto_sources)
+ SchedulerStatusBar on the Subscriptions tab (re-polled every 30s).

D2 failing-source rollup: ?failing=true on the sources list + FailingSourcesCard
on Downloads with per-source and bulk "retry" (re-runs the feed via /check).

D3 activity sparkline: GET /api/downloads/activity hourly buckets + CSS bar
chart by the stat chips (failures stacked in error color); refreshes on live poll.

D4 credential staleness: surface last_verified age + "re-verify recommended"
warning past 30d; also fixes the dead last_verified_at field-name mismatch so
the verification row renders at all.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 08:30:14 -04:00

96 lines
2.7 KiB
JavaScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useApi } from '../composables/useApi.js'
export const useDownloadsStore = defineStore('downloads', () => {
const api = useApi()
const events = ref([])
const cursor = ref(null)
const hasMore = ref(true)
const filter = ref({
status: null, source_id: null, artist_id: null,
from_date: null, to_date: null,
})
const selected = ref(null)
const loading = ref(false)
const error = ref(null)
const stats = ref({ pending: 0, running: 0, ok: 0, error: 0, skipped: 0 })
const activity = ref({ hours: 24, buckets: [] })
const failing = ref([])
function _params(extra = {}) {
const out = { limit: 50, ...extra }
if (filter.value.status) out.status = filter.value.status
if (filter.value.source_id != null) out.source_id = filter.value.source_id
if (filter.value.artist_id != null) out.artist_id = filter.value.artist_id
return out
}
async function loadFirst() {
loading.value = true
error.value = null
try {
const body = await api.get('/api/downloads', { params: _params() })
events.value = body
cursor.value = body.length ? body[body.length - 1].id : null
hasMore.value = body.length === 50
} catch (e) {
error.value = e
} finally {
loading.value = false
}
}
async function loadMore() {
if (!hasMore.value || cursor.value == null) return
loading.value = true
try {
const body = await api.get('/api/downloads', { params: _params({ before: cursor.value }) })
events.value.push(...body)
cursor.value = body.length ? body[body.length - 1].id : cursor.value
hasMore.value = body.length === 50
} catch (e) {
error.value = e
} finally {
loading.value = false
}
}
async function loadOne(id) {
selected.value = await api.get(`/api/downloads/${id}`)
return selected.value
}
async function applyFilter(patch) {
filter.value = { ...filter.value, ...patch }
await loadFirst()
}
function closeDetail() {
selected.value = null
}
async function loadStats(windowHours = 24) {
stats.value = await api.get('/api/downloads/stats', { params: { window_hours: windowHours } })
return stats.value
}
async function loadActivity(hours = 24) {
activity.value = await api.get('/api/downloads/activity', { params: { hours } })
return activity.value
}
async function loadFailing() {
failing.value = await api.get('/api/sources', { params: { failing: true } })
return failing.value
}
return {
events, cursor, hasMore, filter, selected, loading, error, stats,
activity, failing,
loadFirst, loadMore, loadOne, applyFilter, closeDetail, loadStats,
loadActivity, loadFailing,
}
})