fix: ensure unique IDs for bulk server import to prevent overwriting (#875)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-08-31 21:20:27 +08:00
committed by GitHub
parent 4c369546da
commit 5291d316a2

View File

@@ -618,8 +618,15 @@ extension on _BackupPageState {
if (sure == true) {
final (suc, err) = await context.showLoadingDialog(
fn: () async {
final usedIds = <String>{};
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;
},