mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-27 16:49:51 -07:00
feat(sync): add sync-hosts store, NDJSON --json mode, and --check to subminer sync
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import { resolveConfigDir } from '../../src/config/path-resolution.js';
|
||||
import {
|
||||
getSyncHostsPath,
|
||||
readSyncHostsState,
|
||||
recordSyncResult,
|
||||
writeSyncHostsState,
|
||||
type SyncResultStatus,
|
||||
} from '../../src/shared/sync/sync-hosts-store.js';
|
||||
|
||||
export function resolveSyncHostsFilePath(): string {
|
||||
const configDir = resolveConfigDir({
|
||||
platform: process.platform,
|
||||
appDataDir: process.env.APPDATA,
|
||||
xdgConfigHome: process.env.XDG_CONFIG_HOME,
|
||||
homeDir: os.homedir(),
|
||||
existsSync: fs.existsSync,
|
||||
});
|
||||
return getSyncHostsPath(configDir);
|
||||
}
|
||||
|
||||
// Best-effort bookkeeping so hosts synced from the CLI show up in the sync UI;
|
||||
// a failure to persist must never fail the sync itself.
|
||||
export function recordHostSyncResultToDisk(
|
||||
host: string,
|
||||
status: SyncResultStatus,
|
||||
detail: string | null,
|
||||
): void {
|
||||
try {
|
||||
const filePath = resolveSyncHostsFilePath();
|
||||
const state = recordSyncResult(readSyncHostsState(filePath), host, {
|
||||
atMs: Date.now(),
|
||||
status,
|
||||
detail,
|
||||
});
|
||||
writeSyncHostsState(filePath, state);
|
||||
} catch {
|
||||
// best effort
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,8 @@ import { resolveConfigDir } from '../../src/config/path-resolution.js';
|
||||
|
||||
export { SCHEMA_VERSION };
|
||||
|
||||
export interface SyncMergeSummary {
|
||||
sessionsMerged: number;
|
||||
sessionsAlreadyPresent: number;
|
||||
activeSessionsSkipped: number;
|
||||
animeAdded: number;
|
||||
videosAdded: number;
|
||||
wordsAdded: number;
|
||||
kanjiAdded: number;
|
||||
subtitleLinesAdded: number;
|
||||
telemetryRowsAdded: number;
|
||||
eventsAdded: number;
|
||||
excludedWordsAdded: number;
|
||||
dailyRollupsCopied: number;
|
||||
monthlyRollupsCopied: number;
|
||||
rollupGroupsRecomputed: number;
|
||||
}
|
||||
export type { SyncMergeSummary } from '../../src/shared/sync/sync-events.js';
|
||||
import type { SyncMergeSummary } from '../../src/shared/sync/sync-events.js';
|
||||
|
||||
export function createEmptyMergeSummary(): SyncMergeSummary {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user