Remove redundant code to sync diff
This commit is contained in:
parent
2f89dcde2a
commit
13715c924c
2 changed files with 3 additions and 42 deletions
|
@ -158,32 +158,13 @@ class SyncService {
|
|||
if (!Configuration.instance.hasConfiguredAccount()) {
|
||||
return Future.error("Account not configured yet");
|
||||
}
|
||||
// TODO: Verify flow starting here
|
||||
await CollectionsService.instance.sync();
|
||||
await _persistFilesDiff();
|
||||
await _persistEncryptedFilesDiff();
|
||||
await _uploadDiff();
|
||||
await _deletePhotosOnServer();
|
||||
}
|
||||
|
||||
Future<void> _persistFilesDiff() async {
|
||||
final diff = await _downloader.getFilesDiff(_getSyncTime(), _diffLimit);
|
||||
if (diff != null && diff.isNotEmpty) {
|
||||
await _storeDiff(diff, _syncTimeKey);
|
||||
FileRepository.instance.reloadFiles();
|
||||
if (diff.length == _diffLimit) {
|
||||
return await _persistFilesDiff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int _getSyncTime() {
|
||||
var syncTime = _prefs.getInt(_syncTimeKey);
|
||||
if (syncTime == null) {
|
||||
syncTime = 0;
|
||||
}
|
||||
return syncTime;
|
||||
}
|
||||
|
||||
Future<void> _persistEncryptedFilesDiff() async {
|
||||
final diff = await _downloader.getEncryptedFilesDiff(
|
||||
_getEncryptedFilesSyncTime(), _diffLimit);
|
||||
|
|
|
@ -18,8 +18,9 @@ class DiffFetcher {
|
|||
return _dio
|
||||
.get(
|
||||
Configuration.instance.getHttpEndpoint() + "/files/diff",
|
||||
options: Options(
|
||||
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
queryParameters: {
|
||||
"token": Configuration.instance.getToken(),
|
||||
"sinceTime": lastSyncTime,
|
||||
"limit": limit,
|
||||
},
|
||||
|
@ -60,25 +61,4 @@ class DiffFetcher {
|
|||
return files;
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<File>> getFilesDiff(int lastSyncTime, int limit) async {
|
||||
Response response = await _dio.get(
|
||||
Configuration.instance.getHttpEndpoint() + "/files/diff",
|
||||
options:
|
||||
Options(headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
queryParameters: {
|
||||
"sinceTime": lastSyncTime,
|
||||
"limit": limit,
|
||||
},
|
||||
).catchError((e) => _logger.severe(e));
|
||||
if (response != null) {
|
||||
Bus.instance.fire(RemoteSyncEvent(true));
|
||||
return (response.data["diff"] as List)
|
||||
.map((file) => new File.fromJson(file))
|
||||
.toList();
|
||||
} else {
|
||||
Bus.instance.fire(RemoteSyncEvent(false));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue