fixed review changes

This commit is contained in:
a5xwin
2025-09-11 11:12:19 +05:30
parent 8e9a43564a
commit 0a1bcc863b
2 changed files with 29 additions and 16 deletions

View File

@@ -7,6 +7,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:intl/intl.dart'; //for time based file naming
import 'package:logging/logging.dart';
import 'package:shared_preferences/shared_preferences.dart';
//we gonn change
class LocalBackupService {
final _logger = Logger('LocalBackupService');
@@ -40,7 +41,28 @@ class LocalBackupService {
_logger.info("Change detected, triggering automatic encrypted backup...");
final plainTextContent = await CodeStore.instance.getCodesForExport();
String rawContent = await CodeStore.instance.getCodesForExport();
List<String> lines = rawContent.split('\n');
List<String> cleanedLines = [];
for (String line in lines) {
if (line.trim().isEmpty) continue;
String cleanUrl;
if (line.startsWith('"') && line.endsWith('"')) {
cleanUrl = jsonDecode(line);
}
else {
cleanUrl = line;
}
cleanedLines.add(cleanUrl);
}
final plainTextContent = cleanedLines.join('\n');
if (plainTextContent.trim().isEmpty) {
return;

View File

@@ -46,7 +46,7 @@ Future<void> showEncryptedImportInstruction(BuildContext context) async {
if (result?.action != null && result!.action != ButtonAction.cancel) {
if (result.action == ButtonAction.first) {
await _pickEnteJsonFile(context);
}
} else {}
}
}
@@ -85,6 +85,7 @@ Future<void> _decryptExportData(
enteAuthExport.kdfParams.opsLimit,
);
Uint8List? decryptedContent;
// Encrypt the key with this derived key
try {
decryptedContent = await CryptoUtil.decryptData(
CryptoUtil.base642bin(enteAuthExport.encryptedData),
@@ -98,6 +99,7 @@ Future<void> _decryptExportData(
}
if (isPasswordIncorrect) {
await progressDialog.hide();
Future.delayed(const Duration(seconds: 0), () {
_decryptExportData(context, enteAuthExport, password: password);
});
@@ -107,28 +109,17 @@ Future<void> _decryptExportData(
List<String> splitCodes = content.split("\n");
final parsedCodes = [];
for (final code in splitCodes) {
if (code.trim().isEmpty) continue;
try {
String otpUrl;
if (code.startsWith('"') && code.endsWith('"')) {
otpUrl = jsonDecode(code); // decode json wrapped URL
}
else {
otpUrl = code; // use raw URL directly
}
parsedCodes.add(Code.fromOTPAuthUrl(otpUrl));
}
catch (e) {
parsedCodes.add(Code.fromOTPAuthUrl(code));
} catch (e) {
Logger('EncryptedText').severe("Could not parse code", e);
}
}
}
for (final code in parsedCodes) {
await CodeStore.instance.addCode(code, shouldSync: false);
}
unawaited(AuthenticatorService.instance.onlineSync());
importedCodeCount = parsedCodes.length;
await progressDialog.hide();
} catch (e, s) {
await progressDialog.hide();