feat(ui): refonte de l'interface

This commit is contained in:
ElPouki committed 2026-09-15 15:30:20 +02:00
1 parent 3ede3e808c
commit 09eb1fa3aa
79 files changed
+5323 -3514

No files matched your search

+46 -4
View File
@@ -1,12 +1,54 @@
import fs from 'fs'
import path from 'path'
import { DATA_DIR } from '../config.js'
export interface OrganizeNotif {
hash: string; name: string; done: number; skipped: number; errors: number
hash: string; name: string; serieId?: number | null; done: number; skipped: number; errors: number
errorFiles: { file: string; error: string }[]; at: string
}
export const recentOrganized: OrganizeNotif[] = []
const MAX_NOTIFS = 20
export interface RecentSerieImport { serieId: number; episodes: number; at: string }
const HISTORY_PATH = path.join(DATA_DIR, 'import-history.json')
const MAX_HISTORY = 200
const RECENT_WINDOW_MS = 7 * 24 * 60 * 60_000
function loadHistory(): OrganizeNotif[] {
try {
if (!fs.existsSync(HISTORY_PATH)) return []
const data = JSON.parse(fs.readFileSync(HISTORY_PATH, 'utf-8'))
return Array.isArray(data) ? data.slice(0, MAX_HISTORY) : []
} catch { return [] }
}
function saveHistory(): void {
try {
fs.mkdirSync(path.dirname(HISTORY_PATH), { recursive: true })
fs.writeFileSync(HISTORY_PATH, JSON.stringify(recentOrganized, null, 2))
} catch {}
}
// Du plus récent au plus ancien
export const recentOrganized: OrganizeNotif[] = loadHistory()
export function pushNotif(n: OrganizeNotif) {
recentOrganized.unshift(n)
if (recentOrganized.length > MAX_NOTIFS) recentOrganized.pop()
if (recentOrganized.length > MAX_HISTORY) recentOrganized.length = MAX_HISTORY
saveHistory()
}
export function clearNotifs() {
recentOrganized.length = 0
saveHistory()
}
export function recentImportsBySerie(): RecentSerieImport[] {
const bySerie = new Map<number, RecentSerieImport>()
for (const n of recentOrganized) {
if (n.serieId == null || n.done <= 0) continue
const current = bySerie.get(n.serieId)
if (!current) { bySerie.set(n.serieId, { serieId: n.serieId, episodes: n.done, at: n.at }); continue }
if (Date.parse(current.at) - Date.parse(n.at) <= RECENT_WINDOW_MS) current.episodes += n.done
}
return [...bySerie.values()]
}