Add API to fetch backed up files

This commit is contained in:
Vishnu 2021-06-28 11:00:58 +05:30
parent 043b9e8f2f
commit 3a369eb76d
3 changed files with 32 additions and 0 deletions

View file

@ -213,6 +213,21 @@ class FilesDB {
return ids;
}
Future<Set<String>> getUploadedLocalIDs() async {
final db = await instance.database;
final results = await db.query(
table,
columns: [columnLocalID],
where:
'$columnLocalID IS NOT NULL AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)',
);
final ids = Set<String>();
for (final result in results) {
ids.add(result[columnLocalID]);
}
return ids;
}
Future<List<File>> getAllFiles(int startTime, int endTime,
{int limit, bool asc}) async {
final db = await instance.database;

View file

@ -0,0 +1,6 @@
class BackedUpFiles {
final Set<String> localIDs;
final int space;
BackedUpFiles(this.localIDs, this.space);
}

View file

@ -7,6 +7,7 @@ import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/events/local_photos_updated_event.dart';
import 'package:photos/events/sync_status_update_event.dart';
import 'package:photos/models/backed_up_files.dart';
import 'package:photos/models/file.dart';
import 'package:photos/utils/file_sync_util.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -173,6 +174,16 @@ class LocalSyncService {
return _prefs.getBool(kHasCompletedFirstImportKey) ?? false;
}
Future<BackedUpFiles> getBackupStatus() async {
final localIDs = await FilesDB.instance.getUploadedLocalIDs();
int space = 0;
for (final id in localIDs) {
final asset = await AssetEntity.fromId(id);
space += (await asset.originFile).lengthSync();
}
return BackedUpFiles(localIDs, space);
}
Future<void> _loadAndStorePhotos(
int fromTime,
int toTime,