• Exports sync error logs to a JSON file.

    Parameters

    • report: SyncReport

      The sync report containing errors to export.

    Returns void

    If there are no errors, a warning is logged and no file is exported.

    exportSyncErrorLog(report);
    
    export function exportSyncErrorLog(report: SyncReport): void {
    if (!report || !report.errors.length) {
    console.warn("No errors to export");
    return;
    }

    try {
    // Create a formatted error log with timestamp
    const errorLog = {
    timestamp: report.timestamp,
    totalEntries: report.totalEntries,
    successfulUpdates: report.successfulUpdates,
    failedUpdates: report.failedUpdates,
    errors: report.errors,
    };

    // Convert to JSON string with pretty formatting
    const jsonContent = JSON.stringify(errorLog, null, 2);

    // Create blob and URL
    const blob = new Blob([jsonContent], { type: "application/json" });
    const url = URL.createObjectURL(blob);

    // Create element to trigger download
    const link = document.createElement("a");
    link.href = url;

    // Generate filename with date
    const date = new Date(report.timestamp);
    const dateStr = date.toISOString().split("T")[0]; // YYYY-MM-DD format
    link.download = `anilist-sync-errors-${dateStr}.json`;

    // Trigger download
    document.body.appendChild(link);
    link.click();

    // Clean up
    document.body.removeChild(link);
    URL.revokeObjectURL(url);

    console.log("Error log exported successfully");
    } catch (error) {
    console.error("Failed to export error log:", error);
    }
    }