Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix: go back to otpauth instead of converting to json

Prateek Sunal5f921e701a99
diff --git a/auth/lib/models/code.dart b/auth/lib/models/code.dart
index 6abbb61ea2..9ba33f3c18 100644
--- a/auth/lib/models/code.dart
+++ b/auth/lib/models/code.dart
@@ -1,3 +1,5 @@
+import 'dart:convert';
+
import 'package:ente_auth/models/code_display.dart';
import 'package:ente_auth/utils/totp_util.dart';
import 'package:flutter/foundation.dart';
@@ -105,7 +107,7 @@ class Code {
_getType(uri),
_getCounter(uri),
rawData,
- display: display,
+ display: CodeDisplay.fromUri(uri),
);
} catch (e) {
// if account name contains # without encoding,
@@ -148,11 +150,10 @@ class Code {
}
}
- Map<String, dynamic> toExportJson() {
- return {
- 'rawData': rawData,
- if (display != null) 'display': display?.toJson(),
- };
+ String toExportFormat() {
+ return Uri.parse(
+ rawData + "&codeDisplay=" + jsonEncode(display ?? CodeDisplay()),
+ ).toString();
}
static String _getIssuer(Uri uri) {
diff --git a/auth/lib/models/code_display.dart b/auth/lib/models/code_display.dart
index 11f69492a5..604ae9cea5 100644
--- a/auth/lib/models/code_display.dart
+++ b/auth/lib/models/code_display.dart
@@ -1,15 +1,19 @@
+import 'dart:convert';
+
/// Used to store the display settings of a code.
class CodeDisplay {
final bool pinned;
final bool trashed;
final int lastUsedAt;
final int tapCount;
+ final List<String> tags;
CodeDisplay({
this.pinned = false,
this.trashed = false,
this.lastUsedAt = 0,
this.tapCount = 0,
+ this.tags = const [],
});
// copyWith
@@ -18,16 +22,20 @@ class CodeDisplay {
bool? trashed,
int? lastUsedAt,
int? tapCount,
+ List<String>? tags,
}) {
final bool updatedPinned = pinned ?? this.pinned;
final bool updatedTrashed = trashed ?? this.trashed;
final int updatedLastUsedAt = lastUsedAt ?? this.lastUsedAt;
final int updatedTapCount = tapCount ?? this.tapCount;
+ final List<String> updatedTags = tags ?? this.tags;
+
return CodeDisplay(
pinned: updatedPinned,
trashed: updatedTrashed,
lastUsedAt: updatedLastUsedAt,
tapCount: updatedTapCount,
+ tags: updatedTags,
);
}
@@ -43,6 +51,14 @@ class CodeDisplay {
);
}
+ static CodeDisplay? fromUri(Uri uri) {
+ if (!uri.queryParameters.containsKey("codeDisplay")) return null;
+ final String codeDisplay = uri.queryParameters['codeDisplay']!;
+ final decodedDisplay = jsonDecode(codeDisplay);
+
+ return CodeDisplay.fromJson(decodedDisplay);
+ }
+
Map<String, dynamic> toJson() {
return {
'pinned': pinned,
diff --git a/auth/lib/store/code_store.dart b/auth/lib/store/code_store.dart
index 70c1219cc4..817a578765 100644
--- a/auth/lib/store/code_store.dart
+++ b/auth/lib/store/code_store.dart
@@ -80,14 +80,14 @@ class CodeStore {
result = AddResult.updateCode;
await _authenticatorService.updateEntry(
code.generatedID!,
- jsonEncode(code.toExportJson()),
+ code.toExportFormat(),
shouldSync,
mode,
);
} else {
result = AddResult.newCode;
code.generatedID = await _authenticatorService.addEntry(
- jsonEncode(code.toExportJson()),
+ code.toExportFormat(),
shouldSync,
mode,
);
diff --git a/auth/lib/ui/settings/data/export_widget.dart b/auth/lib/ui/settings/data/export_widget.dart
index ccf3b7df55..1110329852 100644
--- a/auth/lib/ui/settings/data/export_widget.dart
+++ b/auth/lib/ui/settings/data/export_widget.dart
@@ -172,13 +172,10 @@ Future<void> _exportCodes(BuildContext context, String fileContent) async {
Future<String> _getAuthDataForExport() async {
final codes = await CodeStore.instance.getAllCodes();
- List<Map<String, dynamic>> items = [];
+ String data = "";
for (final code in codes) {
- items.add(code.toExportJson());
+ data += "${code.rawData}\n";
}
- final data = {
- "items": items,
- };
- return jsonEncode(data);
+ return data;
}