mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
@@ -46,19 +46,24 @@ class Backup implements Mergeable {
|
||||
|
||||
Map<String, dynamic> toJson() => _$BackupToJson(this);
|
||||
|
||||
Backup.loadFromStore()
|
||||
: version = backupFormatVersion,
|
||||
date = DateTime.now().toString().split('.').firstOrNull ?? '',
|
||||
spis = Stores.server.fetch(),
|
||||
snippets = Stores.snippet.fetch(),
|
||||
keys = Stores.key.fetch(),
|
||||
container = Stores.container.box.toJson(),
|
||||
lastModTime = Stores.lastModTime,
|
||||
history = Stores.history.box.toJson(),
|
||||
settings = Stores.setting.box.toJson();
|
||||
static Future<Backup> loadFromStore() async {
|
||||
final lastModTime = Stores.lastModTime?.millisecondsSinceEpoch;
|
||||
return Backup(
|
||||
version: backupFormatVersion,
|
||||
date: DateTime.now().toString().split('.').firstOrNull ?? '',
|
||||
spis: Stores.server.fetch(),
|
||||
snippets: Stores.snippet.fetch(),
|
||||
keys: Stores.key.fetch(),
|
||||
container: await Stores.container.getAllMap(),
|
||||
lastModTime: lastModTime,
|
||||
history: await Stores.history.getAllMap(),
|
||||
settings: await Stores.setting.getAllMap(),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<String> backup([String? name]) async {
|
||||
final result = _diyEncrypt(json.encode(Backup.loadFromStore().toJson()));
|
||||
final bak = await Backup.loadFromStore();
|
||||
final result = _diyEncrypt(json.encode(bak.toJson()));
|
||||
final path = Paths.doc.joinPath(name ?? Miscs.bakFileName);
|
||||
await File(path).writeAsString(result);
|
||||
return path;
|
||||
@@ -66,7 +71,7 @@ class Backup implements Mergeable {
|
||||
|
||||
@override
|
||||
Future<void> merge({bool force = false}) async {
|
||||
final curTime = Stores.lastModTime ?? 0;
|
||||
final curTime = Stores.lastModTime?.millisecondsSinceEpoch ?? 0;
|
||||
final bakTime = lastModTime ?? 0;
|
||||
final shouldRestore = force || curTime < bakTime;
|
||||
if (!shouldRestore) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class _AbsolutePath {
|
||||
_path = newPath;
|
||||
return;
|
||||
}
|
||||
_path = _path.joinPath(newPath, seperator: _sep);
|
||||
_path = _path.joinPath(newPath, separator: _sep);
|
||||
}
|
||||
|
||||
bool undo() {
|
||||
|
||||
@@ -21,7 +21,7 @@ class SftpReq {
|
||||
}
|
||||
if (spi.jumpId != null) {
|
||||
jumpSpi = Stores.server.box.get(spi.jumpId);
|
||||
jumpPrivateKey = Stores.key.get(jumpSpi?.keyId)?.key;
|
||||
jumpPrivateKey = Stores.key.fetchOne(jumpSpi?.keyId)?.key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user