added hash check back
This commit is contained in:
parent
82a18101fe
commit
a90696ddad
8 changed files with 46 additions and 19 deletions
|
|
@ -74,7 +74,7 @@ class _MyAppState extends ConsumerState<MyApp> {
|
|||
Widget build(BuildContext context) {
|
||||
final syncOnAppLaunch = ref.watch(syncOnAppLaunchStateProvider);
|
||||
if (syncOnAppLaunch) {
|
||||
ref.read(syncServerProvider(syncId: 1).notifier).syncToServer(ref, true);
|
||||
ref.read(syncServerProvider(syncId: 1).notifier).checkForSync(ref, true);
|
||||
}
|
||||
final isDarkTheme = ref.watch(themeModeStateProvider);
|
||||
final blendLevel = ref.watch(blendLevelStateProvider);
|
||||
|
|
|
|||
|
|
@ -646,7 +646,6 @@ class MangasSetIsReadState extends _$MangasSetIsReadState {
|
|||
final chapters = manga.chapters;
|
||||
if (chapters.isNotEmpty) {
|
||||
chapters.last.updateTrackChapterRead(ref);
|
||||
chapters.last.syncProgressAfterChapterRead(ref);
|
||||
isar.writeTxnSync(() {
|
||||
for (var chapter in chapters) {
|
||||
chapter.isRead = true;
|
||||
|
|
@ -655,6 +654,7 @@ class MangasSetIsReadState extends _$MangasSetIsReadState {
|
|||
chapter.manga.saveSync();
|
||||
}
|
||||
});
|
||||
chapters.last.syncProgressAfterChapterRead(ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2520,7 +2520,7 @@ final isLongPressedMangaStateProvider =
|
|||
|
||||
typedef _$IsLongPressedMangaState = AutoDisposeNotifier<bool>;
|
||||
String _$mangasSetIsReadStateHash() =>
|
||||
r'dce8293fa6b8338791c76ddad07efa4339ca8628';
|
||||
r'6553a77aa5672636739207be5d2e5374a0dc8208';
|
||||
|
||||
abstract class _$MangasSetIsReadState
|
||||
extends BuildlessAutoDisposeNotifier<void> {
|
||||
|
|
|
|||
|
|
@ -787,7 +787,6 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
|
|||
onPressed: () {
|
||||
int index = chapters.indexOf(chap.first);
|
||||
chapters[index + 1].updateTrackChapterRead(ref);
|
||||
chapters[index + 1].syncProgressAfterChapterRead(ref);
|
||||
isar.writeTxnSync(() {
|
||||
for (var i = index + 1;
|
||||
i < chapters.length;
|
||||
|
|
@ -807,6 +806,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
|
|||
.read(chaptersListStateProvider.notifier)
|
||||
.clear();
|
||||
});
|
||||
chapters[index + 1].syncProgressAfterChapterRead(ref);
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ extension ChapterExtensions on Chapter {
|
|||
if (!(ref is WidgetRef || ref is AutoDisposeNotifierProviderRef)) return;
|
||||
final syncAfterReading = ref.watch(syncAfterReadingStateProvider);
|
||||
if (!syncAfterReading) return;
|
||||
ref.read(syncServerProvider(syncId: 1).notifier).syncToServer(ref, true);
|
||||
ref.read(syncServerProvider(syncId: 1).notifier).checkForSync(ref, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class SyncScreen extends ConsumerWidget {
|
|||
ref
|
||||
.read(syncServerProvider(syncId: 1)
|
||||
.notifier)
|
||||
.syncToServer(ref, false);
|
||||
.checkForSync(ref, false);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.sync,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ part 'sync_server.g.dart';
|
|||
class SyncServer extends _$SyncServer {
|
||||
final http = MClient.init(reqcopyWith: {'useDartHttpClient': true});
|
||||
final String _loginUrl = '/login';
|
||||
final String _checkUrl = '/check';
|
||||
final String _syncUrl = '/sync';
|
||||
final String _uploadUrl = '/upload/full';
|
||||
final String _downloadUrl = '/download';
|
||||
|
|
@ -64,6 +65,38 @@ class SyncServer extends _$SyncServer {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> checkForSync(WidgetRef ref, bool silent) async {
|
||||
if (!silent) {
|
||||
botToast("Checking for sync...", second: 2);
|
||||
}
|
||||
try {
|
||||
final datas = _getData();
|
||||
final accessToken = _getAccessToken();
|
||||
final localHash = _getDataHash(datas);
|
||||
|
||||
var response = await http.get(
|
||||
Uri.parse('${_getServer()}$_checkUrl'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $accessToken'
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
botToast("Check failed", second: 5);
|
||||
return;
|
||||
}
|
||||
var jsonData = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final remoteHash = jsonData["hash"];
|
||||
if (localHash != remoteHash) {
|
||||
syncToServer(ref, silent);
|
||||
} else if (!silent) {
|
||||
botToast("Sync up to date", second: 2);
|
||||
}
|
||||
} catch (error) {
|
||||
botToast(error.toString(), second: 5);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> syncToServer(WidgetRef ref, bool silent) async {
|
||||
if (!silent) {
|
||||
botToast("Sync started...", second: 2);
|
||||
|
|
@ -71,7 +104,6 @@ class SyncServer extends _$SyncServer {
|
|||
try {
|
||||
final datas = _getData();
|
||||
final accessToken = _getAccessToken();
|
||||
final localHash = _getDataHash(datas);
|
||||
|
||||
var response = await http.post(
|
||||
Uri.parse('${_getServer()}$_syncUrl'),
|
||||
|
|
@ -89,17 +121,12 @@ class SyncServer extends _$SyncServer {
|
|||
final decodedBackupData = jsonData["backupData"] is String
|
||||
? jsonDecode(jsonData["backupData"])
|
||||
: jsonData["backupData"];
|
||||
final remoteHash = _getDataHash(decodedBackupData);
|
||||
if (localHash != remoteHash) {
|
||||
_restoreMerge(decodedBackupData, ref);
|
||||
ref
|
||||
.read(synchingProvider(syncId: syncId).notifier)
|
||||
.setLastSync(DateTime.now().millisecondsSinceEpoch);
|
||||
if (!silent) {
|
||||
botToast("Sync finished", second: 2);
|
||||
}
|
||||
} else if (!silent) {
|
||||
botToast("Sync up to date", second: 2);
|
||||
_restoreMerge(decodedBackupData, ref);
|
||||
ref
|
||||
.read(synchingProvider(syncId: syncId).notifier)
|
||||
.setLastSync(DateTime.now().millisecondsSinceEpoch);
|
||||
if (!silent) {
|
||||
botToast("Sync finished", second: 2);
|
||||
}
|
||||
} catch (error) {
|
||||
botToast(error.toString(), second: 5);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ part of 'sync_server.dart';
|
|||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$syncServerHash() => r'79a57c46772a4ca28681162896742c1fd24955da';
|
||||
String _$syncServerHash() => r'b1e0d222b36758fd106ebdbcbe943bd7df19bdd0';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
|
|
|
|||
Loading…
Reference in a new issue