mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-01-12 03:55:00 +01:00
* fix: Added logging to exception handling Added detailed error logging to exception handling across multiple files, including exception information and stack traces, to facilitate troubleshooting. * refactor(logging): Standardize logging output methods Replace existing debugPrint and lprint with Loggers.app.warning to enhance logging consistency and maintainability. * refactor: Remove redundant debug log prints Clean up unnecessary log print statements in debug code * feat(i18n): Added internationalization support for the logging feature
50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:fl_lib/fl_lib.dart';
|
|
import 'package:server_box/data/model/app/bak/backup2.dart';
|
|
import 'package:server_box/data/model/app/bak/utils.dart';
|
|
|
|
const bakSync = BakSyncer._();
|
|
|
|
final icloud = ICloud(containerId: 'iCloud.tech.lolli.serverbox');
|
|
|
|
final class BakSyncer extends SyncIface {
|
|
const BakSyncer._() : super();
|
|
|
|
@override
|
|
Future<void> saveToFile() async {
|
|
final pwd = await SecureStoreProps.bakPwd.read();
|
|
await BackupV2.backup(null, pwd?.isEmpty == true ? null : pwd);
|
|
}
|
|
|
|
@override
|
|
Future<Mergeable> fromFile(String path) async {
|
|
final content = await File(path).readAsString();
|
|
final pwd = await SecureStoreProps.bakPwd.read();
|
|
try {
|
|
if (Cryptor.isEncrypted(content)) {
|
|
return MergeableUtils.fromJsonString(content, pwd).$1;
|
|
}
|
|
return MergeableUtils.fromJsonString(content).$1;
|
|
} catch (e, s) {
|
|
Loggers.app.warning('Failed to parse backup file with password, trying without password', e, s);
|
|
// Fallback: try without password if detection failed
|
|
return MergeableUtils.fromJsonString(content).$1;
|
|
}
|
|
}
|
|
|
|
@override
|
|
RemoteStorage? get remoteStorage {
|
|
final icloudEnabled = PrefProps.icloudSync.get();
|
|
if (icloudEnabled) return icloud;
|
|
|
|
final webdavEnabled = PrefProps.webdavSync.get();
|
|
if (webdavEnabled) return Webdav.shared;
|
|
|
|
final gistEnabled = PrefProps.gistSync.get();
|
|
if (gistEnabled) return GistRs.shared;
|
|
|
|
return null;
|
|
}
|
|
}
|