mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-02 00:58:19 +08:00
opt: webdav
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -122,7 +122,11 @@ class _WebDavSettingPageState extends State<WebDavSettingPage> {
|
|||||||
.put(SettingBoxKey.webdavDirectory, _directoryCtr.text);
|
.put(SettingBoxKey.webdavDirectory, _directoryCtr.text);
|
||||||
try {
|
try {
|
||||||
final res = await WebDav().init();
|
final res = await WebDav().init();
|
||||||
SmartDialog.showToast('配置${res ? '成功' : '失败'}');
|
if (res.first) {
|
||||||
|
SmartDialog.showToast('配置成功');
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast('配置失败: ${res.second}');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
SmartDialog.showToast('配置失败: ${e.toString()}');
|
SmartDialog.showToast('配置失败: ${e.toString()}');
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
@@ -17,7 +18,7 @@ class WebDav {
|
|||||||
static final WebDav _instance = WebDav._internal();
|
static final WebDav _instance = WebDav._internal();
|
||||||
factory WebDav() => _instance;
|
factory WebDav() => _instance;
|
||||||
|
|
||||||
Future<bool> init() async {
|
Future<Pair<bool, String?>> init() async {
|
||||||
_webDavUri = GStorage.webdavUri;
|
_webDavUri = GStorage.webdavUri;
|
||||||
_webDavUsername = GStorage.webdavUsername;
|
_webDavUsername = GStorage.webdavUsername;
|
||||||
_webDavPassword = GStorage.webdavPassword;
|
_webDavPassword = GStorage.webdavPassword;
|
||||||
@@ -42,26 +43,27 @@ class WebDav {
|
|||||||
await client.mkdirAll(_webdavDirectory);
|
await client.mkdirAll(_webdavDirectory);
|
||||||
|
|
||||||
_client = client;
|
_client = client;
|
||||||
return true;
|
return Pair(first: true, second: null);
|
||||||
} catch (_) {
|
} catch (e) {
|
||||||
return false;
|
return Pair(first: false, second: e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future backup() async {
|
Future backup() async {
|
||||||
if (_client == null) {
|
if (_client == null) {
|
||||||
if (await init() == false) {
|
final res = await init();
|
||||||
SmartDialog.showToast('备份失败,请检查配置');
|
if (res.first == false) {
|
||||||
|
SmartDialog.showToast('备份失败,请检查配置: ${res.second}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
String data = await GStorage.exportAllSettings();
|
||||||
final path = '$_webdavDirectory/piliplus_settings.json';
|
final path = '$_webdavDirectory/piliplus_settings.json';
|
||||||
final file = File(path);
|
final file = File(path);
|
||||||
if (await file.exists()) {
|
if (await file.exists()) {
|
||||||
await file.delete();
|
await file.delete();
|
||||||
}
|
}
|
||||||
String data = await GStorage.exportAllSettings();
|
|
||||||
await _client!.write(path, utf8.encode(data));
|
await _client!.write(path, utf8.encode(data));
|
||||||
SmartDialog.showToast('备份成功');
|
SmartDialog.showToast('备份成功');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -71,8 +73,9 @@ class WebDav {
|
|||||||
|
|
||||||
Future restore() async {
|
Future restore() async {
|
||||||
if (_client == null) {
|
if (_client == null) {
|
||||||
if (await init() == false) {
|
final res = await init();
|
||||||
SmartDialog.showToast('恢复失败,请检查配置');
|
if (res.first == false) {
|
||||||
|
SmartDialog.showToast('恢复失败,请检查配置: ${res.second}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user