Feat : Handling idle state
All checks were successful
release / build (push) Successful in 25s
release / verify-windows (push) Successful in 1m14s

This commit is contained in:
jeanotx32
2026-08-11 23:31:26 +02:00
parent 2380196169
commit 242bbf1383
6 changed files with 108 additions and 11 deletions

View File

@@ -112,6 +112,45 @@ addColumnIfMissing('watch_targets', 'last_live_ended_at', 'INTEGER');
// longtemps. Desactivé par défaut : rien ne doit s'enclencher sans un geste.
addColumnIfMissing('watch_targets', 'auto_record', 'INTEGER NOT NULL DEFAULT 0');
/**
* `idle` — le « revient bientôt » de Stripchat — relevait de la clôture et non de
* la pause dans les versions antérieures. Les agents créés avant ce changement
* portent la liste figée dans leur JSON et n'hériteraient pas du nouveau défaut.
*
* La migration ne touche que les listes laissées telles quelles : dès qu'un
* opérateur a personnalisé la sienne, elle ne correspond plus et reste intacte.
* Elle est de ce fait idempotente — après un passage, plus aucune ligne ne
* satisfait la condition.
*/
const LEGACY_PRIVATE_STATUSES = ['private', 'p2p', 'groupShow', 'virtualPrivate', 'ticketShow'];
function migrateIdleStatus(): void {
const rows = db.prepare('SELECT id, watch_json FROM agents WHERE watch_json IS NOT NULL').all() as
unknown as Array<{ id: string; watch_json: string }>;
const update = db.prepare('UPDATE agents SET watch_json = ? WHERE id = ?');
let migrated = 0;
for (const row of rows) {
const watch = safeJsonParse<WatchSettings>(row.watch_json);
const statuses = watch?.privateStatuses;
if (!Array.isArray(statuses)) continue;
if (statuses.length !== LEGACY_PRIVATE_STATUSES.length) continue;
if (!LEGACY_PRIVATE_STATUSES.every((status) => statuses.includes(status))) continue;
update.run(
JSON.stringify({ ...watch, privateStatuses: [...statuses, 'idle'] }),
row.id,
);
migrated += 1;
}
if (migrated > 0) {
console.log(`Migration : « idle » ajouté aux statuts de pause de ${migrated} agent(s)`);
}
}
migrateIdleStatus();
export interface AgentRow {
id: string;
name: string;