|
@@ -1,4 +1,4 @@
|
|
-import 'dart:io' as io;
|
|
|
|
|
|
+import "dart:io";
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:logging/logging.dart';
|
|
@@ -107,7 +107,7 @@ class FilesDB {
|
|
|
|
|
|
// this opens the database (and creates it if it doesn't exist)
|
|
// this opens the database (and creates it if it doesn't exist)
|
|
Future<Database> _initDatabase() async {
|
|
Future<Database> _initDatabase() async {
|
|
- final io.Directory documentsDirectory =
|
|
|
|
|
|
+ final Directory documentsDirectory =
|
|
await getApplicationDocumentsDirectory();
|
|
await getApplicationDocumentsDirectory();
|
|
final String path = join(documentsDirectory.path, _databaseName);
|
|
final String path = join(documentsDirectory.path, _databaseName);
|
|
_logger.info("DB path " + path);
|
|
_logger.info("DB path " + path);
|
|
@@ -391,23 +391,23 @@ class FilesDB {
|
|
Future<void> deleteDB() async {
|
|
Future<void> deleteDB() async {
|
|
if (kDebugMode) {
|
|
if (kDebugMode) {
|
|
debugPrint("Deleting files db");
|
|
debugPrint("Deleting files db");
|
|
- final io.Directory documentsDirectory =
|
|
|
|
|
|
+ final Directory documentsDirectory =
|
|
await getApplicationDocumentsDirectory();
|
|
await getApplicationDocumentsDirectory();
|
|
final String path = join(documentsDirectory.path, _databaseName);
|
|
final String path = join(documentsDirectory.path, _databaseName);
|
|
- io.File(path).deleteSync(recursive: true);
|
|
|
|
|
|
+ File(path).deleteSync(recursive: true);
|
|
_dbFuture = null;
|
|
_dbFuture = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Future<void> insertMultiple(
|
|
Future<void> insertMultiple(
|
|
- List<File> files, {
|
|
|
|
|
|
+ List<EnteFile> files, {
|
|
ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.replace,
|
|
ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.replace,
|
|
}) async {
|
|
}) async {
|
|
final startTime = DateTime.now();
|
|
final startTime = DateTime.now();
|
|
final db = await database;
|
|
final db = await database;
|
|
var batch = db.batch();
|
|
var batch = db.batch();
|
|
int batchCounter = 0;
|
|
int batchCounter = 0;
|
|
- for (File file in files) {
|
|
|
|
|
|
+ for (EnteFile file in files) {
|
|
if (batchCounter == 400) {
|
|
if (batchCounter == 400) {
|
|
await batch.commit(noResult: true);
|
|
await batch.commit(noResult: true);
|
|
batch = db.batch();
|
|
batch = db.batch();
|
|
@@ -435,7 +435,7 @@ class FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<int> insert(File file) async {
|
|
|
|
|
|
+ Future<int> insert(EnteFile file) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
return db.insert(
|
|
return db.insert(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -444,7 +444,7 @@ class FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<File?> getFile(int generatedID) async {
|
|
|
|
|
|
+ Future<EnteFile?> getFile(int generatedID) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
final results = await db.query(
|
|
final results = await db.query(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -457,7 +457,7 @@ class FilesDB {
|
|
return convertToFiles(results)[0];
|
|
return convertToFiles(results)[0];
|
|
}
|
|
}
|
|
|
|
|
|
- Future<File?> getUploadedFile(int uploadedID, int collectionID) async {
|
|
|
|
|
|
+ Future<EnteFile?> getUploadedFile(int uploadedID, int collectionID) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
final results = await db.query(
|
|
final results = await db.query(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -580,13 +580,13 @@ class FilesDB {
|
|
limit: limit,
|
|
limit: limit,
|
|
);
|
|
);
|
|
final files = convertToFiles(results);
|
|
final files = convertToFiles(results);
|
|
- final List<File> filteredFiles = await applyDBFilters(files, filterOptions);
|
|
|
|
|
|
+ final List<EnteFile> filteredFiles = await applyDBFilters(files, filterOptions);
|
|
return FileLoadResult(filteredFiles, files.length == limit);
|
|
return FileLoadResult(filteredFiles, files.length == limit);
|
|
}
|
|
}
|
|
|
|
|
|
- List<File> deduplicateByLocalID(List<File> files) {
|
|
|
|
|
|
+ List<EnteFile> deduplicateByLocalID(List<EnteFile> files) {
|
|
final localIDs = <String>{};
|
|
final localIDs = <String>{};
|
|
- final List<File> deduplicatedFiles = [];
|
|
|
|
|
|
+ final List<EnteFile> deduplicatedFiles = [];
|
|
for (final file in files) {
|
|
for (final file in files) {
|
|
final id = file.localID;
|
|
final id = file.localID;
|
|
if (id == null) {
|
|
if (id == null) {
|
|
@@ -627,7 +627,7 @@ class FilesDB {
|
|
return FileLoadResult(files, files.length == limit);
|
|
return FileLoadResult(files, files.length == limit);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getAllFilesCollection(int collectionID) async {
|
|
|
|
|
|
+ Future<List<EnteFile>> getAllFilesCollection(int collectionID) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
const String whereClause = '$columnCollectionID = ?';
|
|
const String whereClause = '$columnCollectionID = ?';
|
|
final List<Object> whereArgs = [collectionID];
|
|
final List<Object> whereArgs = [collectionID];
|
|
@@ -640,7 +640,7 @@ class FilesDB {
|
|
return files;
|
|
return files;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getNewFilesInCollection(
|
|
|
|
|
|
+ Future<List<EnteFile>> getNewFilesInCollection(
|
|
int collectionID,
|
|
int collectionID,
|
|
int addedTime,
|
|
int addedTime,
|
|
) async {
|
|
) async {
|
|
@@ -666,7 +666,7 @@ class FilesDB {
|
|
bool? asc,
|
|
bool? asc,
|
|
}) async {
|
|
}) async {
|
|
if (collectionIDs.isEmpty) {
|
|
if (collectionIDs.isEmpty) {
|
|
- return FileLoadResult(<File>[], false);
|
|
|
|
|
|
+ return FileLoadResult(<EnteFile>[], false);
|
|
}
|
|
}
|
|
String inParam = "";
|
|
String inParam = "";
|
|
for (final id in collectionIDs) {
|
|
for (final id in collectionIDs) {
|
|
@@ -695,13 +695,13 @@ class FilesDB {
|
|
return FileLoadResult(files, files.length == limit);
|
|
return FileLoadResult(files, files.length == limit);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getFilesCreatedWithinDurations(
|
|
|
|
|
|
+ Future<List<EnteFile>> getFilesCreatedWithinDurations(
|
|
List<List<int>> durations,
|
|
List<List<int>> durations,
|
|
Set<int> ignoredCollectionIDs, {
|
|
Set<int> ignoredCollectionIDs, {
|
|
String order = 'ASC',
|
|
String order = 'ASC',
|
|
}) async {
|
|
}) async {
|
|
if (durations.isEmpty) {
|
|
if (durations.isEmpty) {
|
|
- return <File>[];
|
|
|
|
|
|
+ return <EnteFile>[];
|
|
}
|
|
}
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
String whereClause = "( ";
|
|
String whereClause = "( ";
|
|
@@ -730,7 +730,7 @@ class FilesDB {
|
|
|
|
|
|
// Files which user added to a collection manually but they are not
|
|
// Files which user added to a collection manually but they are not
|
|
// uploaded yet or files belonging to a collection which is marked for backup
|
|
// uploaded yet or files belonging to a collection which is marked for backup
|
|
- Future<List<File>> getFilesPendingForUpload() async {
|
|
|
|
|
|
+ Future<List<EnteFile>> getFilesPendingForUpload() async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
final results = await db.query(
|
|
final results = await db.query(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -753,7 +753,7 @@ class FilesDB {
|
|
return files;
|
|
return files;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getUnUploadedLocalFiles() async {
|
|
|
|
|
|
+ Future<List<EnteFile>> getUnUploadedLocalFiles() async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
final results = await db.query(
|
|
final results = await db.query(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -785,7 +785,7 @@ class FilesDB {
|
|
return uploadedFileIDs;
|
|
return uploadedFileIDs;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<File?> getUploadedLocalFileInAnyCollection(
|
|
|
|
|
|
+ Future<EnteFile?> getUploadedLocalFileInAnyCollection(
|
|
int uploadedFileID,
|
|
int uploadedFileID,
|
|
int userID,
|
|
int userID,
|
|
) async {
|
|
) async {
|
|
@@ -911,7 +911,7 @@ class FilesDB {
|
|
This method should only return localIDs which are not uploaded yet
|
|
This method should only return localIDs which are not uploaded yet
|
|
and can be mapped to incoming remote entry
|
|
and can be mapped to incoming remote entry
|
|
*/
|
|
*/
|
|
- Future<List<File>> getUnlinkedLocalMatchesForRemoteFile(
|
|
|
|
|
|
+ Future<List<EnteFile>> getUnlinkedLocalMatchesForRemoteFile(
|
|
int ownerID,
|
|
int ownerID,
|
|
String localID,
|
|
String localID,
|
|
FileType fileType, {
|
|
FileType fileType, {
|
|
@@ -930,7 +930,7 @@ class FilesDB {
|
|
getInt(fileType),
|
|
getInt(fileType),
|
|
title,
|
|
title,
|
|
];
|
|
];
|
|
- if (io.Platform.isAndroid) {
|
|
|
|
|
|
+ if (Platform.isAndroid) {
|
|
whereClause = ''' ($columnOwnerID = ? OR $columnOwnerID IS NULL) AND
|
|
whereClause = ''' ($columnOwnerID = ? OR $columnOwnerID IS NULL) AND
|
|
$columnLocalID = ? AND $columnFileType = ? AND $columnTitle=? AND $columnDeviceFolder= ?
|
|
$columnLocalID = ? AND $columnFileType = ? AND $columnTitle=? AND $columnDeviceFolder= ?
|
|
''';
|
|
''';
|
|
@@ -952,7 +952,7 @@ class FilesDB {
|
|
return convertToFiles(rows);
|
|
return convertToFiles(rows);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getUploadedFilesWithHashes(
|
|
|
|
|
|
+ Future<List<EnteFile>> getUploadedFilesWithHashes(
|
|
FileHashData hashData,
|
|
FileHashData hashData,
|
|
FileType fileType,
|
|
FileType fileType,
|
|
int ownerID,
|
|
int ownerID,
|
|
@@ -976,7 +976,7 @@ class FilesDB {
|
|
return convertToFiles(rows);
|
|
return convertToFiles(rows);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<int> update(File file) async {
|
|
|
|
|
|
+ Future<int> update(EnteFile file) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
return await db.update(
|
|
return await db.update(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -986,7 +986,7 @@ class FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<int> updateUploadedFileAcrossCollections(File file) async {
|
|
|
|
|
|
+ Future<int> updateUploadedFileAcrossCollections(EnteFile file) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
return await db.update(
|
|
return await db.update(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -1043,7 +1043,7 @@ class FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<int> deleteLocalFile(File file) async {
|
|
|
|
|
|
+ Future<int> deleteLocalFile(EnteFile file) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
if (file.localID != null) {
|
|
if (file.localID != null) {
|
|
// delete all files with same local ID
|
|
// delete all files with same local ID
|
|
@@ -1077,7 +1077,7 @@ class FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getLocalFiles(List<String> localIDs) async {
|
|
|
|
|
|
+ Future<List<EnteFile>> getLocalFiles(List<String> localIDs) async {
|
|
String inParam = "";
|
|
String inParam = "";
|
|
for (final localID in localIDs) {
|
|
for (final localID in localIDs) {
|
|
inParam += "'" + localID + "',";
|
|
inParam += "'" + localID + "',";
|
|
@@ -1173,7 +1173,7 @@ class FilesDB {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getPendingUploadForCollection(int collectionID) async {
|
|
|
|
|
|
+ Future<List<EnteFile>> getPendingUploadForCollection(int collectionID) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
final results = await db.query(
|
|
final results = await db.query(
|
|
filesTable,
|
|
filesTable,
|
|
@@ -1185,7 +1185,7 @@ class FilesDB {
|
|
}
|
|
}
|
|
|
|
|
|
Future<Set<String>> getLocalIDsPresentInEntries(
|
|
Future<Set<String>> getLocalIDsPresentInEntries(
|
|
- List<File> existingFiles,
|
|
|
|
|
|
+ List<EnteFile> existingFiles,
|
|
int collectionID,
|
|
int collectionID,
|
|
) async {
|
|
) async {
|
|
String inParam = "";
|
|
String inParam = "";
|
|
@@ -1237,7 +1237,7 @@ class FilesDB {
|
|
|
|
|
|
// getCollectionFileFirstOrLast returns the first or last uploaded file in
|
|
// getCollectionFileFirstOrLast returns the first or last uploaded file in
|
|
// the collection based on the given collectionID and the order.
|
|
// the collection based on the given collectionID and the order.
|
|
- Future<File?> getCollectionFileFirstOrLast(
|
|
|
|
|
|
+ Future<EnteFile?> getCollectionFileFirstOrLast(
|
|
int collectionID,
|
|
int collectionID,
|
|
bool sortAsc,
|
|
bool sortAsc,
|
|
) async {
|
|
) async {
|
|
@@ -1292,8 +1292,8 @@ class FilesDB {
|
|
return rows.isNotEmpty;
|
|
return rows.isNotEmpty;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<Map<int, File>> getFilesFromIDs(List<int> ids) async {
|
|
|
|
- final result = <int, File>{};
|
|
|
|
|
|
+ Future<Map<int, EnteFile>> getFilesFromIDs(List<int> ids) async {
|
|
|
|
+ final result = <int, EnteFile>{};
|
|
if (ids.isEmpty) {
|
|
if (ids.isEmpty) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -1314,8 +1314,8 @@ class FilesDB {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<Map<int, File>> getFilesFromGeneratedIDs(List<int> ids) async {
|
|
|
|
- final result = <int, File>{};
|
|
|
|
|
|
+ Future<Map<int, EnteFile>> getFilesFromGeneratedIDs(List<int> ids) async {
|
|
|
|
+ final result = <int, EnteFile>{};
|
|
if (ids.isEmpty) {
|
|
if (ids.isEmpty) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -1336,10 +1336,10 @@ class FilesDB {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<Map<int, List<File>>> getAllFilesGroupByCollectionID(
|
|
|
|
|
|
+ Future<Map<int, List<EnteFile>>> getAllFilesGroupByCollectionID(
|
|
List<int> ids,
|
|
List<int> ids,
|
|
) async {
|
|
) async {
|
|
- final result = <int, List<File>>{};
|
|
|
|
|
|
+ final result = <int, List<EnteFile>>{};
|
|
if (ids.isEmpty) {
|
|
if (ids.isEmpty) {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -1354,9 +1354,9 @@ class FilesDB {
|
|
where: '$columnUploadedFileID IN ($inParam)',
|
|
where: '$columnUploadedFileID IN ($inParam)',
|
|
);
|
|
);
|
|
final files = convertToFiles(results);
|
|
final files = convertToFiles(results);
|
|
- for (File eachFile in files) {
|
|
|
|
|
|
+ for (EnteFile eachFile in files) {
|
|
if (!result.containsKey(eachFile.collectionID)) {
|
|
if (!result.containsKey(eachFile.collectionID)) {
|
|
- result[eachFile.collectionID as int] = <File>[];
|
|
|
|
|
|
+ result[eachFile.collectionID as int] = <EnteFile>[];
|
|
}
|
|
}
|
|
result[eachFile.collectionID]!.add(eachFile);
|
|
result[eachFile.collectionID]!.add(eachFile);
|
|
}
|
|
}
|
|
@@ -1381,8 +1381,8 @@ class FilesDB {
|
|
return collectionIDsOfFile;
|
|
return collectionIDsOfFile;
|
|
}
|
|
}
|
|
|
|
|
|
- List<File> convertToFiles(List<Map<String, dynamic>> results) {
|
|
|
|
- final List<File> files = [];
|
|
|
|
|
|
+ List<EnteFile> convertToFiles(List<Map<String, dynamic>> results) {
|
|
|
|
+ final List<EnteFile> files = [];
|
|
for (final result in results) {
|
|
for (final result in results) {
|
|
files.add(_getFileFromRow(result));
|
|
files.add(_getFileFromRow(result));
|
|
}
|
|
}
|
|
@@ -1467,12 +1467,12 @@ class FilesDB {
|
|
await batch.commit(noResult: true);
|
|
await batch.commit(noResult: true);
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getAllFilesFromDB(Set<int> collectionsToIgnore) async {
|
|
|
|
|
|
+ Future<List<EnteFile>> getAllFilesFromDB(Set<int> collectionsToIgnore) async {
|
|
final db = await instance.database;
|
|
final db = await instance.database;
|
|
final List<Map<String, dynamic>> result =
|
|
final List<Map<String, dynamic>> result =
|
|
await db.query(filesTable, orderBy: '$columnCreationTime DESC');
|
|
await db.query(filesTable, orderBy: '$columnCreationTime DESC');
|
|
- final List<File> files = convertToFiles(result);
|
|
|
|
- final List<File> deduplicatedFiles = await applyDBFilters(
|
|
|
|
|
|
+ final List<EnteFile> files = convertToFiles(result);
|
|
|
|
+ final List<EnteFile> deduplicatedFiles = await applyDBFilters(
|
|
files,
|
|
files,
|
|
DBFilterOptions(ignoredCollectionIDs: collectionsToIgnore),
|
|
DBFilterOptions(ignoredCollectionIDs: collectionsToIgnore),
|
|
);
|
|
);
|
|
@@ -1515,11 +1515,11 @@ class FilesDB {
|
|
limit: limit,
|
|
limit: limit,
|
|
);
|
|
);
|
|
final files = convertToFiles(results);
|
|
final files = convertToFiles(results);
|
|
- final List<File> filteredFiles = await applyDBFilters(files, filterOptions);
|
|
|
|
|
|
+ final List<EnteFile> filteredFiles = await applyDBFilters(files, filterOptions);
|
|
return FileLoadResult(filteredFiles, files.length == limit);
|
|
return FileLoadResult(filteredFiles, files.length == limit);
|
|
}
|
|
}
|
|
|
|
|
|
- Map<String, dynamic> _getRowForFile(File file) {
|
|
|
|
|
|
+ Map<String, dynamic> _getRowForFile(EnteFile file) {
|
|
final row = <String, dynamic>{};
|
|
final row = <String, dynamic>{};
|
|
if (file.generatedID != null) {
|
|
if (file.generatedID != null) {
|
|
row[columnGeneratedID] = file.generatedID;
|
|
row[columnGeneratedID] = file.generatedID;
|
|
@@ -1574,7 +1574,7 @@ class FilesDB {
|
|
return row;
|
|
return row;
|
|
}
|
|
}
|
|
|
|
|
|
- Map<String, dynamic> _getRowForFileWithoutCollection(File file) {
|
|
|
|
|
|
+ Map<String, dynamic> _getRowForFileWithoutCollection(EnteFile file) {
|
|
final row = <String, dynamic>{};
|
|
final row = <String, dynamic>{};
|
|
row[columnLocalID] = file.localID;
|
|
row[columnLocalID] = file.localID;
|
|
row[columnUploadedFileID] = file.uploadedFileID ?? -1;
|
|
row[columnUploadedFileID] = file.uploadedFileID ?? -1;
|
|
@@ -1615,8 +1615,8 @@ class FilesDB {
|
|
return row;
|
|
return row;
|
|
}
|
|
}
|
|
|
|
|
|
- File _getFileFromRow(Map<String, dynamic> row) {
|
|
|
|
- final file = File();
|
|
|
|
|
|
+ EnteFile _getFileFromRow(Map<String, dynamic> row) {
|
|
|
|
+ final file = EnteFile();
|
|
file.generatedID = row[columnGeneratedID];
|
|
file.generatedID = row[columnGeneratedID];
|
|
file.localID = row[columnLocalID];
|
|
file.localID = row[columnLocalID];
|
|
file.uploadedFileID =
|
|
file.uploadedFileID =
|