feat: GitHub Gist sync (#854)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-08-14 23:21:33 +08:00
committed by GitHub
parent 1d553eccd5
commit bc1b6e5a4a
21 changed files with 538 additions and 197 deletions

View File

@@ -12,12 +12,28 @@ final class BakSyncer extends SyncIface {
const BakSyncer._() : super();
@override
Future<void> saveToFile() => BackupV2.backup();
Future<void> saveToFile() async {
final pwd = await SecureStoreProps.bakPwd.read();
if (pwd == null || pwd.isEmpty) {
// Enforce password for non-clipboard backups
throw Exception('Backup password not set');
}
await BackupV2.backup(null, pwd);
}
@override
Future<Mergeable> fromFile(String path) async {
final content = await File(path).readAsString();
return MergeableUtils.fromJsonString(content).$1;
final pwd = await SecureStoreProps.bakPwd.read();
try {
if (Cryptor.isEncrypted(content)) {
return MergeableUtils.fromJsonString(content, pwd).$1;
}
return MergeableUtils.fromJsonString(content).$1;
} catch (_) {
// Fallback: try without password if detection failed
return MergeableUtils.fromJsonString(content).$1;
}
}
@override
@@ -28,6 +44,9 @@ final class BakSyncer extends SyncIface {
final webdavEnabled = PrefProps.webdavSync.get();
if (webdavEnabled) return Webdav.shared;
final gistEnabled = PrefProps.gistSync.get();
if (gistEnabled) return GistRs.shared;
return null;
}
}