Fix: Use new db to get fileKey

This commit is contained in:
Neeraj Gupta
2025-07-31 15:02:25 +05:30
parent bd49b8464b
commit f7a0a414db
4 changed files with 31 additions and 8 deletions

View File

@@ -75,6 +75,20 @@ extension CollectionFiles on RemoteDB {
.toList(growable: false);
}
Future<Map<int, CollectionFile>> getFileIdToCollectionFile(
List<int> fileIDs,
) async {
final rows = await sqliteDB.getAll(
"SELECT * FROM collection_files JOIN files on collection_files.file_id=files.id WHERE file_id IN (${fileIDs.join(",")})",
);
final Map<int, CollectionFile> result = {};
for (var row in rows) {
final entry = CollectionFile.fromMap(row);
result[entry.fileID] = entry;
}
return result;
}
Future<List<CollectionFile>> getAllFiles(int userID) {
return sqliteDB.getAll(
"SELECT * FROM collection_files JOIN files ON collection_files.file_id = files.id WHERE files.owner_id = ? ORDER BY files.creation_time DESC",

View File

@@ -4,10 +4,11 @@ import "package:computer/computer.dart";
import "package:dio/dio.dart";
import "package:flutter/foundation.dart" show Uint8List;
import "package:logging/logging.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/db/remote/table/collection_files.dart";
import "package:photos/models/file/file.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/filedata/model/enc_file_data.dart";
import "package:photos/services/filedata/model/file_data.dart";
import "package:photos/services/filedata/model/response.dart";
@@ -102,14 +103,18 @@ class FileDataService {
return result;
}
final inputs = <_DecoderInput>[];
final fileMap = await FilesDB.instance
.getFileIDToFileFromIDs(remoteData.map((e) => e.fileID).toList());
final fileToCFMap = await remoteDB
.getFileIdToCollectionFile(remoteData.map((e) => e.fileID).toList());
for (final data in remoteData) {
final file = fileMap[data.fileID];
if (file == null) {
final cf = fileToCFMap[data.fileID];
if (cf == null) {
assert(
false,
"Assert: CF for for fileID ${data.fileID} not found in DB",
);
continue;
}
final fileKey = getFileKey(file);
final fileKey = getKeyFromCF(cf);
final input = _DecoderInput(data, fileKey);
inputs.add(input);
}

View File

@@ -122,7 +122,7 @@ class RemoteFaceEmbedding {
factory RemoteFaceEmbedding.fromJson(Map<String, dynamic> json) {
return RemoteFaceEmbedding(
List<Face>.from(
json['faces'].map((x) => Face.fromJson(x as Map<String, dynamic>)),
json['faces'].map((x) => Face.fromJson<int>(x as Map<String, dynamic>)),
),
json['version'] as int,
client: json['client'] as String,

View File

@@ -2,10 +2,14 @@ import "dart:typed_data";
import "package:ente_crypto/ente_crypto.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/remote/collection_file.dart";
import "package:photos/services/collections_service.dart";
Uint8List getFileKey(EnteFile file) {
final cf = file.cf!;
return getKeyFromCF(file.cf!);
}
Uint8List getKeyFromCF(CollectionFile cf) {
final collectionKey =
CollectionsService.instance.getCollectionKey(cf.collectionID);
return CryptoUtil.decryptSync(