Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use generated Legacy types in Flutter

Manav Rathi75d44d4b109b
diff --git a/mobile/apps/locker/flutter_rust_bridge.yaml b/mobile/apps/locker/flutter_rust_bridge.yaml
index a2589f39ba..61ae1d0e29 100644
--- a/mobile/apps/locker/flutter_rust_bridge.yaml
+++ b/mobile/apps/locker/flutter_rust_bridge.yaml
@@ -1,5 +1,5 @@
rust_input: crate::api, ente-frb-lib
-rust_features: [ente-frb-lib/contacts]
+rust_features: ["ente-frb-lib/contacts,ente-frb-lib/legacy"]
rust_root: ../../../rust/bindings/frb/locker/
dart_output: lib/src/rust
dart_entrypoint_class_name: EnteLockerRust
diff --git a/mobile/apps/locker/lib/services/legacy_kit.dart b/mobile/apps/locker/lib/services/legacy_kit.dart
index 8b77655d62..b51cab6944 100644
--- a/mobile/apps/locker/lib/services/legacy_kit.dart
+++ b/mobile/apps/locker/lib/services/legacy_kit.dart
@@ -1,63 +1,27 @@
import 'package:ente_base/models/key_attributes.dart';
-import 'package:ente_legacy/errors.dart';
-import 'package:ente_legacy/models/legacy_kit_models.dart';
+import 'package:ente_frb/legacy.dart';
import 'package:locker/src/rust/api/legacy.dart' as rust;
import 'package:locker/src/rust/third_party/ente_frb_lib/session.dart';
-Future<List<LegacyKit>> getLegacyKits(Session session) async {
- final kits = await rust.kits(session: session);
- return kits.map(_fromRustKit).toList(growable: false);
-}
-
-Future<LegacyKitCreateResult> createLegacyKit(
- Session session,
- KeyAttributes currentUserKeyAttrs,
- List<String> partNames,
- int noticePeriodInHours,
-) async {
- final result = await rust.createKit(
- session: session,
- currentUserKeyAttrs: _toRustKeyAttributes(currentUserKeyAttrs),
- partNames: partNames,
- noticePeriodInHours: noticePeriodInHours,
- );
- return LegacyKitCreateResult(
- kit: _fromRustKit(result.kit),
- shares: result.shares.map(_fromRustShare).toList(growable: false),
- );
-}
-
-Future<List<LegacyKitShare>> downloadLegacyKitShares(
- Session session,
- String kitId,
-) async {
- final shares = await rust.downloadKitShares(session: session, kitId: kitId);
- return shares.map(_fromRustShare).toList(growable: false);
-}
-
-Future<void> updateLegacyKitRecoveryNotice(
- Session session,
- String kitId,
- int noticePeriodInHours,
-) async {
- try {
- await rust.updateKitRecoveryNotice(
- session: session,
- kitId: kitId,
- noticePeriodInHours: noticePeriodInHours,
- );
- } on rust.LegacyError_ActiveRecoverySession {
- throw LegacyKitActiveRecoverySessionException();
- }
-}
-
-Future<void> blockLegacyKitRecovery(Session session, String kitId) async {
- await rust.blockKitRecovery(session: session, kitId: kitId);
-}
-
-Future<void> deleteLegacyKit(Session session, String kitId) async {
- await rust.deleteKit(session: session, kitId: kitId);
-}
+export 'package:locker/src/rust/api/legacy.dart'
+ show
+ blockKitRecovery,
+ deleteKit,
+ downloadKitShares,
+ kits,
+ updateKitRecoveryNotice;
+
+Future<LegacyKitCreateResult> createKit({
+ required Session session,
+ required KeyAttributes currentUserKeyAttrs,
+ required List<String> partNames,
+ required int noticePeriodInHours,
+}) => rust.createKit(
+ session: session,
+ currentUserKeyAttrs: _toRustKeyAttributes(currentUserKeyAttrs),
+ partNames: partNames,
+ noticePeriodInHours: noticePeriodInHours,
+);
rust.AccountKeyAttributes _toRustKeyAttributes(KeyAttributes attributes) {
return rust.AccountKeyAttributes(
@@ -77,53 +41,3 @@ rust.AccountKeyAttributes _toRustKeyAttributes(KeyAttributes attributes) {
recoveryKeyDecryptionNonce: attributes.recoveryKeyDecryptionNonce,
);
}
-
-LegacyKit _fromRustKit(rust.LegacyKit kit) {
- return LegacyKit(
- id: kit.id,
- noticePeriodInHours: kit.noticePeriodInHours,
- legacyUrl: kit.legacyUrl,
- parts: kit.metadata.parts
- .map((part) => LegacyKitPart(index: part.index, name: part.name))
- .toList(growable: false),
- createdAt: kit.createdAt,
- updatedAt: kit.updatedAt,
- activeRecoverySession: kit.activeRecoverySession == null
- ? null
- : _fromRustRecoverySession(kit.activeRecoverySession!),
- );
-}
-
-LegacyKitRecoverySession _fromRustRecoverySession(
- rust.LegacyKitRecoverySession session,
-) {
- return LegacyKitRecoverySession(
- id: session.id,
- kitId: session.kitId,
- status: switch (session.status) {
- rust.LegacyKitRecoveryStatus.waiting => LegacyKitRecoveryStatus.waiting,
- rust.LegacyKitRecoveryStatus.ready => LegacyKitRecoveryStatus.ready,
- rust.LegacyKitRecoveryStatus.blocked => LegacyKitRecoveryStatus.blocked,
- rust.LegacyKitRecoveryStatus.cancelled =>
- LegacyKitRecoveryStatus.cancelled,
- rust.LegacyKitRecoveryStatus.recovered =>
- LegacyKitRecoveryStatus.recovered,
- },
- waitTill: session.waitTill,
- createdAt: session.createdAt,
- );
-}
-
-LegacyKitShare _fromRustShare(rust.LegacyKitShare share) {
- return LegacyKitShare(
- payloadVersion: share.payloadVersion,
- variant: switch (share.variant) {
- rust.LegacyKitVariant.twoOfThree => 1,
- },
- kitId: share.kitId,
- shareIndex: share.shareIndex,
- share: share.share,
- checksum: share.checksum,
- partName: share.partName,
- );
-}
diff --git a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
index 7818ef634a..78d709be26 100644
--- a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
+++ b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
@@ -103,7 +103,7 @@ Future<bool?> hasLegacyKit() async {
}
Future<List<LegacyKit>> _getLegacyKits() =>
- legacy.getLegacyKits(authenticatedSession());
+ legacy.kits(session: authenticatedSession());
Future<LegacyKitCreateResult> _createLegacyKit(
List<String> partNames,
@@ -113,33 +113,33 @@ Future<LegacyKitCreateResult> _createLegacyKit(
if (keyAttributes == null) {
throw StateError("Missing account key attributes");
}
- final result = await legacy.createLegacyKit(
- authenticatedSession(),
- keyAttributes,
- partNames,
- noticePeriodInHours,
+ final result = await legacy.createKit(
+ session: authenticatedSession(),
+ currentUserKeyAttrs: keyAttributes,
+ partNames: partNames,
+ noticePeriodInHours: noticePeriodInHours,
);
Bus.instance.fire(LegacyKitCreatedEvent());
return result;
}
Future<List<LegacyKitShare>> _downloadLegacyKitShares(String kitId) =>
- legacy.downloadLegacyKitShares(authenticatedSession(), kitId);
+ legacy.downloadKitShares(session: authenticatedSession(), kitId: kitId);
Future<void> _updateLegacyKitRecoveryNotice(
String kitId,
int noticePeriodInHours,
-) => legacy.updateLegacyKitRecoveryNotice(
- authenticatedSession(),
- kitId,
- noticePeriodInHours,
+) => legacy.updateKitRecoveryNotice(
+ session: authenticatedSession(),
+ kitId: kitId,
+ noticePeriodInHours: noticePeriodInHours,
);
Future<void> _blockLegacyKitRecovery(String kitId) =>
- legacy.blockLegacyKitRecovery(authenticatedSession(), kitId);
+ legacy.blockKitRecovery(session: authenticatedSession(), kitId: kitId);
Future<void> _deleteLegacyKit(String kitId) =>
- legacy.deleteLegacyKit(authenticatedSession(), kitId);
+ legacy.deleteKit(session: authenticatedSession(), kitId: kitId);
Future<bool> _authenticateForLegacyFlow(BuildContext context, String reason) {
return LocalAuthenticationService.instance.requestLocalAuthentication(
diff --git a/mobile/packages/frb/pubspec.yaml b/mobile/packages/frb/pubspec.yaml
index b1b0feccb1..89c9a8196a 100644
--- a/mobile/packages/frb/pubspec.yaml
+++ b/mobile/packages/frb/pubspec.yaml
@@ -8,3 +8,4 @@ environment:
dependencies:
flutter_rust_bridge: 2.12.0
+ freezed_annotation: 3.1.0
diff --git a/mobile/packages/legacy/lib/ente_legacy.dart b/mobile/packages/legacy/lib/ente_legacy.dart
index 6ee8a2b93f..f8361b7ddf 100644
--- a/mobile/packages/legacy/lib/ente_legacy.dart
+++ b/mobile/packages/legacy/lib/ente_legacy.dart
@@ -1,5 +1,4 @@
export 'components/legacy_kit_recovery_wait_time_sheet.dart';
-export 'errors.dart';
export 'models/emergency_models.dart';
export 'models/legacy_kit_models.dart';
export 'pages/create_legacy_kit_sheet.dart';
diff --git a/mobile/packages/legacy/lib/errors.dart b/mobile/packages/legacy/lib/errors.dart
deleted file mode 100644
index c6b7a11309..0000000000
--- a/mobile/packages/legacy/lib/errors.dart
+++ /dev/null
@@ -1 +0,0 @@
-class LegacyKitActiveRecoverySessionException implements Exception {}
diff --git a/mobile/packages/legacy/lib/models/legacy_kit_models.dart b/mobile/packages/legacy/lib/models/legacy_kit_models.dart
index 09c041eb84..7a1076c5de 100644
--- a/mobile/packages/legacy/lib/models/legacy_kit_models.dart
+++ b/mobile/packages/legacy/lib/models/legacy_kit_models.dart
@@ -1,75 +1,16 @@
import "dart:convert";
-enum LegacyKitRecoveryStatus { waiting, ready, blocked, cancelled, recovered }
+import "package:ente_frb/legacy.dart";
-class LegacyKitRecoverySession {
- final String id;
- final String kitId;
- final LegacyKitRecoveryStatus status;
- // Remaining microseconds until recovery becomes ready, matching the existing
- // legacy contact recovery API contract.
- final int waitTill;
- final int createdAt;
-
- const LegacyKitRecoverySession({
- required this.id,
- required this.kitId,
- required this.status,
- required this.waitTill,
- required this.createdAt,
- });
-}
-
-class LegacyKitPart {
- final int index;
- final String name;
-
- const LegacyKitPart({required this.index, required this.name});
-}
-
-class LegacyKit {
- final String id;
- final int noticePeriodInHours;
- final String legacyUrl;
- final List<LegacyKitPart> parts;
- final int createdAt;
- final int updatedAt;
- final LegacyKitRecoverySession? activeRecoverySession;
-
- const LegacyKit({
- required this.id,
- required this.noticePeriodInHours,
- required this.legacyUrl,
- required this.parts,
- required this.createdAt,
- required this.updatedAt,
- required this.activeRecoverySession,
- });
+export "package:ente_frb/legacy.dart";
+extension LegacyKitDisplay on LegacyKit {
String get displayName => parts.map((part) => part.name).join(" Β· ");
bool get hasActiveRecoverySession => activeRecoverySession != null;
}
-class LegacyKitShare {
- final int payloadVersion;
- final int variant;
- final String kitId;
- final int shareIndex;
- final String share;
- final String checksum;
- final String partName;
-
- const LegacyKitShare({
- required this.payloadVersion,
- required this.variant,
- required this.kitId,
- required this.shareIndex,
- required this.share,
- required this.checksum,
- required this.partName,
- });
-
+extension LegacyKitShareEncoding on LegacyKitShare {
String toQrPayload() {
return jsonEncode({
"pv": payloadVersion,
@@ -90,10 +31,3 @@ class LegacyKitShare {
return value.replaceAll(RegExp(r"\s+"), "");
}
}
-
-class LegacyKitCreateResult {
- final LegacyKit kit;
- final List<LegacyKitShare> shares;
-
- const LegacyKitCreateResult({required this.kit, required this.shares});
-}
diff --git a/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart b/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart
index e5a856b0df..a0eb765ff5 100644
--- a/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart
+++ b/mobile/packages/legacy/lib/pages/share_legacy_kit_page.dart
@@ -6,7 +6,6 @@ import "package:collection/collection.dart";
import "package:ente_components/ente_components.dart";
import "package:ente_legacy/components/legacy_kit_card_preview.dart";
import "package:ente_legacy/components/legacy_kit_recovery_wait_time_sheet.dart";
-import "package:ente_legacy/errors.dart";
import "package:ente_legacy/models/legacy_kit_models.dart";
import "package:ente_legacy/pages/legacy_congratulations_page.dart";
import "package:ente_legacy/services/legacy_kit_local_settings.dart";
@@ -501,7 +500,7 @@ class _ShareLegacyKitPageState extends State<ShareLegacyKitPage> {
}
if (updateError == null) {
showShortToast(context, context.strings.recoveryTimeUpdated);
- } else if (updateError is LegacyKitActiveRecoverySessionException) {
+ } else if (updateError is LegacyError_ActiveRecoverySession) {
try {
await _refreshKit();
} catch (_) {
diff --git a/mobile/packages/legacy/pubspec.yaml b/mobile/packages/legacy/pubspec.yaml
index b837197f76..87b1d00639 100644
--- a/mobile/packages/legacy/pubspec.yaml
+++ b/mobile/packages/legacy/pubspec.yaml
@@ -24,6 +24,8 @@ dependencies:
path: ../ente_crypto_api
ente_events:
path: ../events
+ ente_frb:
+ path: ../frb
ente_network:
path: ../network
ente_pure_utils:
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 3c185853d9..31ca474c14 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2590,6 +2590,7 @@ version = "0.0.0"
dependencies = [
"ente-contacts",
"ente-core",
+ "ente-legacy",
"flutter_rust_bridge",
]
diff --git a/rust/apps/codegen/src/main.rs b/rust/apps/codegen/src/main.rs
index 8302c9adbc..2cbf5c97ce 100644
--- a/rust/apps/codegen/src/main.rs
+++ b/rust/apps/codegen/src/main.rs
@@ -1,3 +1,4 @@
+use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::ffi::OsStr;
@@ -171,27 +172,47 @@ fn generate_frb(target: FrbTarget) -> Result<(), DynError> {
};
let shared_dir = repo_root.join("mobile/packages/frb/lib");
write_generated_gitignore(&shared_dir)?;
- let mut shared_types = None;
+ let mut shared_types = HashMap::new();
for app in apps {
let package_dir = repo_root.join("mobile/apps").join(app);
generate_frb_package(&package_dir)?;
- let types_path =
- package_dir.join("lib/src/rust/third_party/ente_frb_lib/contacts/types.dart");
- let types =
- fs::read_to_string(&types_path)?.replace("import '../../../frb_generated.dart';\n", "");
- if shared_types
- .as_ref()
- .is_some_and(|previous| previous != &types)
- {
- return Err("Photos and Locker generated different shared Contacts types".into());
+ let mut modules = vec![("contacts", "contacts/types")];
+ if *app == "locker" {
+ modules.push(("legacy", "legacy"));
+ }
+ for (name, module) in modules {
+ let types_path = package_dir
+ .join("lib/src/rust/third_party/ente_frb_lib")
+ .join(format!("{module}.dart"));
+ let types = fs::read_to_string(&types_path)?
+ .lines()
+ .filter(|line| !line.ends_with("/frb_generated.dart';"))
+ .collect::<Vec<_>>()
+ .join("\n")
+ + "\n";
+ if shared_types
+ .get(name)
+ .is_some_and(|previous| previous != &types)
+ {
+ return Err(format!("Apps generated different shared {name} types").into());
+ }
+ let freezed_file = format!("{name}.freezed.dart");
+ if types.contains(&format!("part '{freezed_file}';")) {
+ fs::rename(
+ types_path.with_extension("freezed.dart"),
+ shared_dir.join(freezed_file),
+ )?;
+ }
+ fs::write(shared_dir.join(format!("{name}.dart")), &types)?;
+ fs::write(
+ types_path,
+ format!(
+ "// This file is automatically generated, so please do not edit it.\n\n\
+ export 'package:ente_frb/{name}.dart';\n"
+ ),
+ )?;
+ shared_types.insert(name, types);
}
- fs::write(shared_dir.join("contacts.dart"), &types)?;
- fs::write(
- types_path,
- "// This file is automatically generated, so please do not edit it.\n\n\
- export 'package:ente_frb/contacts.dart';\n",
- )?;
- shared_types = Some(types);
}
format_frb_bindings(target)
}
diff --git a/rust/bindings/frb/lib/Cargo.toml b/rust/bindings/frb/lib/Cargo.toml
index e6ae0a6482..3ba8deffa3 100644
--- a/rust/bindings/frb/lib/Cargo.toml
+++ b/rust/bindings/frb/lib/Cargo.toml
@@ -4,10 +4,12 @@ edition = "2024"
[features]
contacts = ["dep:ente-contacts"]
+legacy = ["dep:ente-legacy"]
[dependencies]
ente-contacts = { workspace = true, optional = true }
ente-core.workspace = true
+ente-legacy = { workspace = true, optional = true }
flutter_rust_bridge.workspace = true
[lints.rust]
diff --git a/rust/bindings/frb/lib/src/legacy.rs b/rust/bindings/frb/lib/src/legacy.rs
new file mode 100644
index 0000000000..7e748abff1
--- /dev/null
+++ b/rust/bindings/frb/lib/src/legacy.rs
@@ -0,0 +1,145 @@
+use flutter_rust_bridge::frb;
+
+#[frb(non_opaque)]
+pub enum LegacyError {
+ ActiveRecoverySession { message: String },
+ Other { message: String },
+}
+
+impl From<ente_legacy::Error> for LegacyError {
+ fn from(error: ente_legacy::Error) -> Self {
+ let message = ente_core::error::chain(&error);
+ match error {
+ ente_legacy::Error::ActiveRecoverySession => Self::ActiveRecoverySession { message },
+ _ => Self::Other { message },
+ }
+ }
+}
+
+#[frb(unignore)]
+#[derive(Clone)]
+pub struct LegacyKit {
+ pub id: String,
+ pub notice_period_in_hours: i32,
+ pub legacy_url: String,
+ pub parts: Vec<LegacyKitPart>,
+ pub created_at: i64,
+ pub updated_at: i64,
+ pub active_recovery_session: Option<LegacyKitRecoverySession>,
+}
+
+impl From<ente_legacy::LegacyKit> for LegacyKit {
+ fn from(value: ente_legacy::LegacyKit) -> Self {
+ Self {
+ id: value.id,
+ notice_period_in_hours: value.notice_period_in_hours,
+ legacy_url: value.legacy_url,
+ parts: value.metadata.parts.into_iter().map(Into::into).collect(),
+ created_at: value.created_at,
+ updated_at: value.updated_at,
+ active_recovery_session: value.active_recovery_session.map(Into::into),
+ }
+ }
+}
+
+#[frb(unignore)]
+#[derive(Clone)]
+pub struct LegacyKitCreateResult {
+ pub kit: LegacyKit,
+ pub shares: Vec<LegacyKitShare>,
+}
+
+impl From<ente_legacy::LegacyKitCreateResult> for LegacyKitCreateResult {
+ fn from(value: ente_legacy::LegacyKitCreateResult) -> Self {
+ Self {
+ kit: value.kit.into(),
+ shares: value.shares.into_iter().map(Into::into).collect(),
+ }
+ }
+}
+
+#[frb(unignore)]
+#[derive(Clone)]
+pub struct LegacyKitShare {
+ pub payload_version: u8,
+ pub variant: u8,
+ pub kit_id: String,
+ pub share_index: u8,
+ pub share: String,
+ pub checksum: String,
+ pub part_name: String,
+}
+
+impl From<ente_legacy::LegacyKitShare> for LegacyKitShare {
+ fn from(value: ente_legacy::LegacyKitShare) -> Self {
+ Self {
+ payload_version: value.payload_version,
+ variant: value.variant.code(),
+ kit_id: value.kit_id,
+ share_index: value.share_index,
+ share: value.share,
+ checksum: value.checksum,
+ part_name: value.part_name,
+ }
+ }
+}
+
+#[frb(unignore)]
+#[derive(Clone)]
+pub struct LegacyKitPart {
+ pub index: u8,
+ pub name: String,
+}
+
+impl From<ente_legacy::LegacyKitPart> for LegacyKitPart {
+ fn from(value: ente_legacy::LegacyKitPart) -> Self {
+ Self {
+ index: value.index,
+ name: value.name,
+ }
+ }
+}
+
+#[frb(unignore)]
+#[derive(Clone)]
+pub struct LegacyKitRecoverySession {
+ pub id: String,
+ pub kit_id: String,
+ pub status: LegacyKitRecoveryStatus,
+ pub wait_till: i64,
+ pub created_at: i64,
+}
+
+impl From<ente_legacy::LegacyKitRecoverySession> for LegacyKitRecoverySession {
+ fn from(value: ente_legacy::LegacyKitRecoverySession) -> Self {
+ Self {
+ id: value.id,
+ kit_id: value.kit_id,
+ status: value.status.into(),
+ wait_till: value.wait_till,
+ created_at: value.created_at,
+ }
+ }
+}
+
+#[frb(unignore)]
+#[derive(Clone, Copy)]
+pub enum LegacyKitRecoveryStatus {
+ Waiting,
+ Ready,
+ Blocked,
+ Cancelled,
+ Recovered,
+}
+
+impl From<ente_legacy::LegacyKitRecoveryStatus> for LegacyKitRecoveryStatus {
+ fn from(value: ente_legacy::LegacyKitRecoveryStatus) -> Self {
+ match value {
+ ente_legacy::LegacyKitRecoveryStatus::Waiting => Self::Waiting,
+ ente_legacy::LegacyKitRecoveryStatus::Ready => Self::Ready,
+ ente_legacy::LegacyKitRecoveryStatus::Blocked => Self::Blocked,
+ ente_legacy::LegacyKitRecoveryStatus::Cancelled => Self::Cancelled,
+ ente_legacy::LegacyKitRecoveryStatus::Recovered => Self::Recovered,
+ }
+ }
+}
diff --git a/rust/bindings/frb/lib/src/lib.rs b/rust/bindings/frb/lib/src/lib.rs
index 377f032eb4..f5b6507ae1 100644
--- a/rust/bindings/frb/lib/src/lib.rs
+++ b/rust/bindings/frb/lib/src/lib.rs
@@ -1,3 +1,5 @@
#[cfg(feature = "contacts")]
pub mod contacts;
+#[cfg(feature = "legacy")]
+pub mod legacy;
pub mod session;
diff --git a/rust/bindings/frb/locker/Cargo.toml b/rust/bindings/frb/locker/Cargo.toml
index 8599c5f563..883346d825 100644
--- a/rust/bindings/frb/locker/Cargo.toml
+++ b/rust/bindings/frb/locker/Cargo.toml
@@ -9,7 +9,7 @@ crate-type = ["cdylib", "staticlib"]
ente-accounts.workspace = true
ente-assets.workspace = true
ente-core.workspace = true
-ente-frb-lib = { workspace = true, features = ["contacts"] }
+ente-frb-lib = { workspace = true, features = ["contacts", "legacy"] }
ente-frb-log.workspace = true
ente-legacy.workspace = true
ente-ml.workspace = true
diff --git a/rust/bindings/frb/locker/src/api/legacy.rs b/rust/bindings/frb/locker/src/api/legacy.rs
index 0df39639ee..503a75f2f0 100644
--- a/rust/bindings/frb/locker/src/api/legacy.rs
+++ b/rust/bindings/frb/locker/src/api/legacy.rs
@@ -1,23 +1,8 @@
use flutter_rust_bridge::frb;
+use ente_frb_lib::legacy::{LegacyError, LegacyKit, LegacyKitCreateResult, LegacyKitShare};
use ente_frb_lib::session::Session;
-#[frb]
-pub enum LegacyError {
- ActiveRecoverySession { message: String },
- Other { message: String },
-}
-
-impl From<ente_legacy::Error> for LegacyError {
- fn from(error: ente_legacy::Error) -> Self {
- let message = ente_core::error::chain(&error);
- match error {
- ente_legacy::Error::ActiveRecoverySession => Self::ActiveRecoverySession { message },
- _ => Self::Other { message },
- }
- }
-}
-
#[frb]
#[derive(Clone)]
pub struct AccountKeyAttributes {
@@ -55,164 +40,6 @@ impl From<AccountKeyAttributes> for ente_accounts::auth::KeyAttributes {
}
}
-#[frb]
-#[derive(Clone, Copy)]
-pub enum LegacyKitVariant {
- TwoOfThree,
-}
-
-impl From<ente_legacy::LegacyKitVariant> for LegacyKitVariant {
- fn from(value: ente_legacy::LegacyKitVariant) -> Self {
- match value {
- ente_legacy::LegacyKitVariant::TwoOfThree => Self::TwoOfThree,
- }
- }
-}
-
-#[frb]
-#[derive(Clone, Copy)]
-pub enum LegacyKitRecoveryStatus {
- Waiting,
- Ready,
- Blocked,
- Cancelled,
- Recovered,
-}
-
-impl From<ente_legacy::LegacyKitRecoveryStatus> for LegacyKitRecoveryStatus {
- fn from(value: ente_legacy::LegacyKitRecoveryStatus) -> Self {
- match value {
- ente_legacy::LegacyKitRecoveryStatus::Waiting => Self::Waiting,
- ente_legacy::LegacyKitRecoveryStatus::Ready => Self::Ready,
- ente_legacy::LegacyKitRecoveryStatus::Blocked => Self::Blocked,
- ente_legacy::LegacyKitRecoveryStatus::Cancelled => Self::Cancelled,
- ente_legacy::LegacyKitRecoveryStatus::Recovered => Self::Recovered,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitRecoverySession {
- pub id: String,
- pub kit_id: String,
- pub status: LegacyKitRecoveryStatus,
- pub wait_till: i64,
- pub created_at: i64,
-}
-
-impl From<ente_legacy::LegacyKitRecoverySession> for LegacyKitRecoverySession {
- fn from(value: ente_legacy::LegacyKitRecoverySession) -> Self {
- Self {
- id: value.id,
- kit_id: value.kit_id,
- status: value.status.into(),
- wait_till: value.wait_till,
- created_at: value.created_at,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitPart {
- pub index: u8,
- pub name: String,
-}
-
-impl From<ente_legacy::LegacyKitPart> for LegacyKitPart {
- fn from(value: ente_legacy::LegacyKitPart) -> Self {
- Self {
- index: value.index,
- name: value.name,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitMetadata {
- pub parts: Vec<LegacyKitPart>,
-}
-
-impl From<ente_legacy::LegacyKitMetadata> for LegacyKitMetadata {
- fn from(value: ente_legacy::LegacyKitMetadata) -> Self {
- Self {
- parts: value.parts.into_iter().map(Into::into).collect(),
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKit {
- pub id: String,
- pub variant: LegacyKitVariant,
- pub notice_period_in_hours: i32,
- pub legacy_url: String,
- pub metadata: LegacyKitMetadata,
- pub created_at: i64,
- pub updated_at: i64,
- pub active_recovery_session: Option<LegacyKitRecoverySession>,
-}
-
-impl From<ente_legacy::LegacyKit> for LegacyKit {
- fn from(value: ente_legacy::LegacyKit) -> Self {
- Self {
- id: value.id,
- variant: value.variant.into(),
- notice_period_in_hours: value.notice_period_in_hours,
- legacy_url: value.legacy_url,
- metadata: value.metadata.into(),
- created_at: value.created_at,
- updated_at: value.updated_at,
- active_recovery_session: value.active_recovery_session.map(Into::into),
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitShare {
- pub payload_version: u8,
- pub variant: LegacyKitVariant,
- pub kit_id: String,
- pub share_index: u8,
- pub share: String,
- pub checksum: String,
- pub part_name: String,
-}
-
-impl From<ente_legacy::LegacyKitShare> for LegacyKitShare {
- fn from(value: ente_legacy::LegacyKitShare) -> Self {
- Self {
- payload_version: value.payload_version,
- variant: value.variant.into(),
- kit_id: value.kit_id,
- share_index: value.share_index,
- share: value.share,
- checksum: value.checksum,
- part_name: value.part_name,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitCreateResult {
- pub kit: LegacyKit,
- pub shares: Vec<LegacyKitShare>,
-}
-
-impl From<ente_legacy::LegacyKitCreateResult> for LegacyKitCreateResult {
- fn from(value: ente_legacy::LegacyKitCreateResult) -> Self {
- Self {
- kit: value.kit.into(),
- shares: value.shares.into_iter().map(Into::into).collect(),
- }
- }
-}
-
pub async fn kits(session: &Session) -> Result<Vec<LegacyKit>, LegacyError> {
ente_legacy::kits(session.as_ref())
.await