π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Add support for storing fileDataInfo
Neeraj Guptab886a9e31c3e
diff --git a/mobile/lib/db/ml/db_fields.dart b/mobile/lib/db/ml/db_fields.dartindex 4910a35a66..a9438dc2ac 100644--- a/mobile/lib/db/ml/db_fields.dart+++ b/mobile/lib/db/ml/db_fields.dart@@ -111,6 +111,7 @@ const fileDataTable = 'filedata';const createFileDataTable = '''CREATE TABLE IF NOT EXISTS $fileDataTable ($fileIDColumn INTEGER NOT NULL,+ user_id INTEGER NOT NULL,type TEXT NOT NULL,size INTEGER NOT NULL,updated_at INTEGER NOT NULL,diff --git a/mobile/lib/db/ml/filedata.dart b/mobile/lib/db/ml/filedata.dartnew file mode 100644index 0000000000..e2c6ee5f58--- /dev/null+++ b/mobile/lib/db/ml/filedata.dart@@ -0,0 +1,26 @@+import "package:photos/db/ml/db.dart";+import "package:photos/db/ml/db_fields.dart";+import "package:photos/services/filedata/model/file_data.dart";++extension FileDataTable on MLDataDB {+ Future<void> putIndexStatus(List<IndexInfo> embeddings) async {+ if (embeddings.isEmpty) return;+ final db = await MLDataDB.instance.asyncDB;+ final inputs = <List<Object?>>[];+ for (var embedding in embeddings) {+ inputs.add(+ [+ embedding.fileID,+ embedding.userID,+ embedding.type,+ embedding.size,+ embedding.updatedAt,+ ],+ );+ }+ await db.executeBatch(+ 'INSERT OR REPLACE INTO $fileDataTable ($fileIDColumn, user_id, type, size, updated_at) values(?, ?, ?, ?, ?)',+ inputs,+ );+ }+}diff --git a/mobile/lib/services/filedata/filedata_service.dart b/mobile/lib/services/filedata/filedata_service.dartindex 51048905a1..48f4f851ae 100644--- a/mobile/lib/services/filedata/filedata_service.dart+++ b/mobile/lib/services/filedata/filedata_service.dart@@ -5,6 +5,8 @@ import "package:flutter/foundation.dart" show Uint8List;import "package:logging/logging.dart";import "package:photos/core/network/network.dart";import "package:photos/db/files_db.dart";+import "package:photos/db/ml/db.dart";+import "package:photos/db/ml/filedata.dart";import "package:photos/models/file/file.dart";import "package:photos/services/filedata/model/enc_file_data.dart";import "package:photos/services/filedata/model/file_data.dart";@@ -20,8 +22,11 @@ class FileDataService {static final FileDataService instance = FileDataService._privateConstructor();final _logger = Logger("FileDataService");final _dio = NetworkClient.instance.enteDio;+ late final SharedPreferences _prefs;- void init(SharedPreferences prefs) {}+ void init(SharedPreferences prefs) {+ _prefs = prefs;+ }Future<void> putFileData(EnteFile file, FileDataEntity data) async {data.validate();@@ -105,6 +110,34 @@ class FileDataService {},);}++ Future<void> syncDiff() async {+ try {+ _logger.info("syncDiff");+ final lastTime = _prefs.getInt("fd.lastSyncTime") ?? 1;+ final res = await _dio.post(+ "/files/data/status-diff",+ data: {+ "lastUpdated": lastTime,+ },+ );+ final data = res.data as List;+ final List<IndexInfo> info = [];+ int maxUpdatedAt = lastTime;+ for (var entry in data) {+ info.add(IndexInfo.fromJson(entry));+ if (entry["updatedAt"] > maxUpdatedAt) {+ maxUpdatedAt = entry["updatedAt"];+ }+ }+ await MLDataDB.instance.putIndexStatus(info);+ await _prefs.setInt("fd.lastSyncTime", maxUpdatedAt);+ _logger.info('found ${info.length} entries');+ } catch (e) {+ _logger.severe("Failed to syncDiff", e);+ rethrow;+ }+ }}Future<Map<int, FileDataEntity>> _decryptFileDataComputer(diff --git a/mobile/lib/services/filedata/model/file_data.dart b/mobile/lib/services/filedata/model/file_data.dartindex e9dd6fc14b..2db7a105c7 100644--- a/mobile/lib/services/filedata/model/file_data.dart+++ b/mobile/lib/services/filedata/model/file_data.dart@@ -154,3 +154,31 @@ class RemoteClipEmbedding {);}}++class IndexInfo {+ final int fileID;+ final int userID;+ final String type;+ final bool isDeleted;+ final int size;+ final int updatedAt;+ IndexInfo({+ required this.fileID,+ required this.userID,+ required this.type,+ required this.size,+ required this.updatedAt,+ this.isDeleted = false,+ });++ factory IndexInfo.fromJson(Map<String, dynamic> json) {+ return IndexInfo(+ fileID: json['fileID'] as int,+ userID: json['userID'] as int,+ type: json['type'] as String,+ isDeleted: json['isDeleted'] as bool? ?? false,+ size: json['size'] as int,+ updatedAt: json['updatedAt'] as int,+ );+ }+}diff --git a/mobile/lib/services/machine_learning/ml_service.dart b/mobile/lib/services/machine_learning/ml_service.dartindex e8563a7ac9..f942d5fd83 100644--- a/mobile/lib/services/machine_learning/ml_service.dart+++ b/mobile/lib/services/machine_learning/ml_service.dart@@ -125,6 +125,7 @@ class MLService {}if (_cannotRunMLFunction() && !force) return;_isRunningML = true;+ FileDataService.instance.syncDiff().ignore();await sync();