query('SELECT COUNT(*) FROM sites')->fetchColumn(); $rows = $pdo->query('SELECT id, url, icon_custom FROM sites ORDER BY id LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll(); $updated = 0; $skipped = 0; $failed = 0; $now = date('Y-m-d H:i:s'); foreach ($rows as $row) { $url = norm_url((string)$row['url']); $custom = (int)$row['icon_custom'] === 1; $meta = fetch_site_meta($url); $domain = domain_of($meta['final_url'] ?: $url); $name = $meta['name'] !== '' ? $meta['name'] : $meta['title']; $sets = ['updated_at=?']; $args = [$now]; if ($name !== '') { $sets[] = 'name=?'; $args[] = $name; } if ($custom) { // 用户自定义图标:绝不覆盖 $skipped++; } else { $iconFile = download_best_icon($meta['icons'], $domain); if ($iconFile !== '') { $sets[] = 'icon=?'; $args[] = $iconFile; } if ($iconFile !== '' || $name !== '') { $updated++; } else { $failed++; } } // 注意:这里绝不修改 short_name(用户自定义简称) $args[] = (int)$row['id']; try { $pdo->prepare('UPDATE sites SET ' . implode(',', $sets) . ' WHERE id=?')->execute($args); } catch (Throwable $e) { $failed++; } } $next = $offset + count($rows); echo json_encode([ 'done' => $next >= $total || count($rows) === 0, 'total' => $total, 'offset' => $next, 'updated' => $updated, 'skipped' => $skipped, 'failed' => $failed, ], JSON_UNESCAPED_UNICODE);