fix: go back to otpauth instead of converting to json
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user