π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: methods and fetching of EntityType
Prateek Sunal4f8b2e9fa0c3
diff --git a/mobile/apps/photos/lib/gateways/entity_gw.dart b/mobile/apps/photos/lib/gateways/entity_gw.dartindex 7cbf4331f7..f26428c906 100644--- a/mobile/apps/photos/lib/gateways/entity_gw.dart+++ b/mobile/apps/photos/lib/gateways/entity_gw.dart@@ -16,7 +16,7 @@ class EntityGateway {await _enteDio.post("/user-entity/key",data: {- "type": entityType.typeToString(),+ "type": entityType.name,"encryptedKey": encKey,"header": header,},@@ -28,7 +28,7 @@ class EntityGateway {final response = await _enteDio.get("/user-entity/key",queryParameters: {- "type": type.typeToString(),+ "type": type.name,},);return EntityKey.fromMap(response.data);@@ -55,7 +55,7 @@ class EntityGateway {"encryptedData": encryptedData,if (id != null) "id": id,"header": header,- "type": type.typeToString(),+ "type": type.name,},);return EntityData.fromMap(response.data);@@ -73,7 +73,7 @@ class EntityGateway {"id": id,"encryptedData": encryptedData,"header": header,- "type": type.typeToString(),+ "type": type.name,},);return EntityData.fromMap(response.data);@@ -100,7 +100,7 @@ class EntityGateway {queryParameters: {"sinceTime": sinceTime,"limit": limit,- "type": type.typeToString(),+ "type": type.name,},);final List<EntityData> authEntities = <EntityData>[];diff --git a/mobile/apps/photos/lib/models/api/entity/key.dart b/mobile/apps/photos/lib/models/api/entity/key.dartindex 58e53e042a..a4285979eb 100644--- a/mobile/apps/photos/lib/models/api/entity/key.dart+++ b/mobile/apps/photos/lib/models/api/entity/key.dart@@ -22,7 +22,7 @@ class EntityKey {Map<String, dynamic> toMap() {return {'userID': userID,- 'type': type.typeToString(),+ 'type': type.name,'encryptedKey': encryptedKey,'header': header,'createdAt': createdAt,@@ -35,7 +35,7 @@ class EntityKey {map['encryptedKey']!,map['header']!,map['createdAt']?.toInt() ?? 0,- typeFromString(map['type']!),+ entityTypeFromString(map['type']!),);}diff --git a/mobile/apps/photos/lib/models/api/entity/type.dart b/mobile/apps/photos/lib/models/api/entity/type.dartindex 6cf1cbc736..71714d9f0c 100644--- a/mobile/apps/photos/lib/models/api/entity/type.dart+++ b/mobile/apps/photos/lib/models/api/entity/type.dart@@ -1,30 +1,11 @@-import "package:flutter/foundation.dart";-enum EntityType {location,person,cgroup,unknown,- smartAlbum,-}+ smartAlbum;-EntityType typeFromString(String type) {- switch (type) {- case "location":- return EntityType.location;- case "person":- return EntityType.location;- case "cgroup":- return EntityType.cgroup;- case "smart_album":- return EntityType.smartAlbum;- }- debugPrint("unexpected entity type $type");- return EntityType.unknown;-}--extension EntityTypeExtn on EntityType {- bool isZipped() {+ bool get isZipped {switch (this) {case EntityType.location:case EntityType.person:@@ -34,7 +15,7 @@ extension EntityTypeExtn on EntityType {}}- String typeToString() {+ String get name {switch (this) {case EntityType.location:return "location";@@ -49,3 +30,10 @@ extension EntityTypeExtn on EntityType {}}}++EntityType entityTypeFromString(String type) {+ return EntityType.values.firstWhere(+ (e) => e.name == type,+ orElse: () => EntityType.unknown,+ );+}diff --git a/mobile/apps/photos/lib/models/local_entity_data.dart b/mobile/apps/photos/lib/models/local_entity_data.dartindex 910167b13e..17d6d9c031 100644--- a/mobile/apps/photos/lib/models/local_entity_data.dart+++ b/mobile/apps/photos/lib/models/local_entity_data.dart@@ -20,7 +20,7 @@ class LocalEntityData {Map<String, dynamic> toJson() {return {"id": id,- "type": type.typeToString(),+ "type": type.name,"data": data,"ownerID": ownerID,"updatedAt": updatedAt,@@ -30,7 +30,7 @@ class LocalEntityData {factory LocalEntityData.fromJson(Map<String, dynamic> json) {return LocalEntityData(id: json["id"],- type: typeFromString(json["type"]),+ type: entityTypeFromString(json["type"]),data: json["data"],ownerID: json["ownerID"] as int,updatedAt: json["updatedAt"] as int,diff --git a/mobile/apps/photos/lib/services/entity_service.dart b/mobile/apps/photos/lib/services/entity_service.dartindex 2fe2169cf8..bb8d159736 100644--- a/mobile/apps/photos/lib/services/entity_service.dart+++ b/mobile/apps/photos/lib/services/entity_service.dart@@ -30,15 +30,15 @@ class EntityService {}String _getEntityKeyPrefix(EntityType type) {- return "entity_key_" + type.typeToString();+ return "entity_key_" + type.name;}String _getEntityHeaderPrefix(EntityType type) {- return "entity_key_header_" + type.typeToString();+ return "entity_key_header_" + type.name;}String _getEntityLastSyncTimePrefix(EntityType type) {- return "entity_last_sync_time_" + type.typeToString();+ return "entity_last_sync_time_" + type.name;}Future<List<LocalEntityData>> getCertainEntities(@@ -65,7 +65,7 @@ class EntityService {final String plainText = jsonEncode(jsonMap);final key = await getOrCreateEntityKey(type);late String encryptedData, header;- if (type.isZipped()) {+ if (type.isZipped) {final ChaChaEncryptionResult result =await gzipAndEncryptJson(jsonMap, key);encryptedData = result.encData;@@ -77,8 +77,7 @@ class EntityService {header = CryptoUtil.bin2base64(encryptedKeyData.header!);}debugPrint(- " ${id == null ? 'Adding' : 'Updating'} entity of type: " +- type.typeToString(),+ " ${id == null ? 'Adding' : 'Updating'} entity of type: " + type.name,);final EntityData data = id == null || addWithCustomID@@ -155,7 +154,7 @@ class EntityService {for (EntityData e in result) {try {late String plainText;- if (type.isZipped()) {+ if (type.isZipped) {final jsonMap = await decryptAndUnzipJson(entityKey,encryptedData: e.encryptedData!,