From 5291d316a2bd273775218048e498732fafebb93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Sun, 31 Aug 2025 21:20:27 +0800 Subject: [PATCH] fix: ensure unique IDs for bulk server import to prevent overwriting (#875) --- lib/view/page/backup.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/view/page/backup.dart b/lib/view/page/backup.dart index cec6a5d9..1b8896ea 100644 --- a/lib/view/page/backup.dart +++ b/lib/view/page/backup.dart @@ -618,8 +618,15 @@ extension on _BackupPageState { if (sure == true) { final (suc, err) = await context.showLoadingDialog( fn: () async { + final usedIds = {}; for (var spi in spis) { - Stores.server.put(spi); + // Ensure each server has a unique ID + + // Only generate a new ID if the imported one is empty or already used in importing stage + final isIdUsed = spi.id.isNotEmpty || usedIds.contains(spi.id); + final spiWithId = isIdUsed ? spi.copyWith(id: ShortId.generate()) : spi; + Stores.server.put(spiWithId); + usedIds.add(spiWithId.id); } return true; },