sync method

Future<void> sync()

Implementation

Future<void> sync() async {
  // Step 1: Fetch total pages and last sync time from cache
  final syncHistory = await fetchSyncHistory();
  // final cachedTotalPages ??= 0; // If no cached value, default to 0
  // final lastSyncTime ??= DateTime.fromMillisecondsSinceEpoch(0);

  // Step 2: Fetch metadata from the API (total pages, latest sync time)
  final latestTotalPages = await fetchLatestTotalPages();

  if (syncHistory == null || latestTotalPages > syncHistory.totalPages) {
    await scrapeAllPages(
      cachedTotalPages: syncHistory == null ? 0 : syncHistory.totalPages,
      latestTotalPages: latestTotalPages,
    );

    return;
  }

  print('Cache is up-to-date.');

  // Phase 3: Update with detailed information
  // await scraper.updateAudiobookDetails();
}