fix: warn when 0 keys imported (#38)

This commit is contained in:
鲁树人 2023-07-02 15:39:14 +01:00
parent 48b8932a1d
commit 455a05c360
2 changed files with 16 additions and 4 deletions

View File

@ -49,8 +49,14 @@ export function PanelKWMv2Key() {
const fileBuffer = await file.arrayBuffer(); const fileBuffer = await file.arrayBuffer();
keys = MMKVParser.parseKuwoEKey(new DataView(fileBuffer)); keys = MMKVParser.parseKuwoEKey(new DataView(fileBuffer));
} }
if (keys?.length === 0) {
if (keys) { toast({
title: '未导入密钥',
description: '选择的密钥数据库文件未发现任何可用的密钥。',
isClosable: true,
status: 'warning',
});
} else if (keys) {
dispatch(kwm2ImportKeys(keys)); dispatch(kwm2ImportKeys(keys));
setShowImportModal(false); setShowImportModal(false);
toast({ toast({

View File

@ -71,14 +71,20 @@ export function PanelQMCv2Key() {
qmc2Keys = Array.from(map.entries(), ([name, ekey]) => ({ name: getFileName(name), ekey })); qmc2Keys = Array.from(map.entries(), ([name, ekey]) => ({ name: getFileName(name), ekey }));
} }
if (qmc2Keys) { if (qmc2Keys?.length === 0) {
toast({
title: '未导入密钥',
description: '选择的密钥数据库文件未发现任何可用的密钥。',
isClosable: true,
status: 'warning',
});
} else if (qmc2Keys) {
dispatch(qmc2ImportKeys(qmc2Keys)); dispatch(qmc2ImportKeys(qmc2Keys));
setShowImportModal(false); setShowImportModal(false);
toast({ toast({
title: `导入成功 (${qmc2Keys.length})`, title: `导入成功 (${qmc2Keys.length})`,
description: '记得保存更改来应用。', description: '记得保存更改来应用。',
isClosable: true, isClosable: true,
duration: 5000,
status: 'success', status: 'success',
}); });
} else { } else {