Skip to content

Commit

Permalink
[auth] Add bitwarden folder as tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 committed Jun 3, 2024
1 parent ad00690 commit 7cd998b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions auth/lib/ui/settings/data/import/bitwarden_import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';

import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/models/code_display.dart';
import 'package:ente_auth/services/authenticator_service.dart';
import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
Expand Down Expand Up @@ -80,10 +81,19 @@ Future<int?> _processBitwardenExportFile(
final jsonString = await file.readAsString();
final data = jsonDecode(jsonString);
List<dynamic> jsonArray = data['items'];
final Map<String, String> folderIdToName = {};
try {
for (var item in data['folders']) {
folderIdToName[item['id']] = item['name'];
}
} catch (e) {
debugPrint("Failed to get folder details $e");
}
final parsedCodes = [];
for (var item in jsonArray) {
if (item['login'] != null && item['login']['totp'] != null) {
var totp = item['login']['totp'];
String? folderID = item['folderId'];

Code code;
if (totp.contains("otpauth://")) {
Expand All @@ -110,6 +120,11 @@ Future<int?> _processBitwardenExportFile(
Code.defaultDigits,
);
}
if (folderID != null && folderIdToName.containsKey(folderID)) {
code = code.copyWith(
display: CodeDisplay(tags: [folderIdToName[folderID]!]),
);
}

parsedCodes.add(code);
}
Expand Down

0 comments on commit 7cd998b

Please sign in to comment.