claude refactor
This commit is contained in:
@@ -65,6 +65,28 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showUploadError(String message) {
|
||||
setState(() {
|
||||
_isUploading = false;
|
||||
_overallProgressValue = 0.0;
|
||||
_infoText = '';
|
||||
});
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Upload fehlgeschlagen'),
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Schließen', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> uploadFiles({bool override = false}) async {
|
||||
setState(() {
|
||||
_isUploading = true;
|
||||
@@ -74,16 +96,24 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
}
|
||||
});
|
||||
|
||||
var webdavClient = await WebdavApi.webdav;
|
||||
final webdavClient = await WebdavApi.webdav;
|
||||
|
||||
if (!override) {
|
||||
var result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
|
||||
List<dynamic> result;
|
||||
try {
|
||||
result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_showUploadError('Verbindung fehlgeschlagen: $e');
|
||||
return;
|
||||
}
|
||||
var conflictingFiles = _uploadableFiles.where((file) {
|
||||
var fileName = file.fileName;
|
||||
return result.any((element) => Uri.decodeComponent(element.href!).endsWith('/$fileName'));
|
||||
}).toList();
|
||||
|
||||
if(conflictingFiles.isNotEmpty) {
|
||||
if (!mounted) return;
|
||||
bool replaceFiles = await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -157,17 +187,24 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
_infoText = '${_uploadableFiles.indexOf(file) + 1}/${_uploadableFiles.length}';
|
||||
});
|
||||
|
||||
var uploadTask = await webdavClient.putFile(
|
||||
File(filePath),
|
||||
FileStat.statSync(filePath),
|
||||
PathUri.parse(fullRemotePath),
|
||||
onProgress: (progress) {
|
||||
setState(() {
|
||||
file._uploadProgress = progress;
|
||||
_overallProgressValue = ((progress + _uploadableFiles.indexOf(file)) / _uploadableFiles.length).toDouble();
|
||||
});
|
||||
},
|
||||
);
|
||||
final dynamic uploadTask;
|
||||
try {
|
||||
uploadTask = await webdavClient.putFile(
|
||||
File(filePath),
|
||||
FileStat.statSync(filePath),
|
||||
PathUri.parse(fullRemotePath),
|
||||
onProgress: (progress) {
|
||||
setState(() {
|
||||
file._uploadProgress = progress;
|
||||
_overallProgressValue = ((progress + _uploadableFiles.indexOf(file)) / _uploadableFiles.length).toDouble();
|
||||
});
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_showUploadError('Upload fehlgeschlagen für "$fileName": $e');
|
||||
return;
|
||||
}
|
||||
|
||||
if(uploadTask.statusCode < 200 || uploadTask.statusCode > 299) {
|
||||
setState(() {
|
||||
@@ -175,6 +212,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
_overallProgressValue = 0.0;
|
||||
_infoText = '';
|
||||
});
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
showHttpErrorCode(uploadTask.statusCode);
|
||||
} else {
|
||||
@@ -187,6 +225,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
_overallProgressValue = 0.0;
|
||||
_infoText = '';
|
||||
});
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
widget.onUploadFinished(uploadetFilePaths);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user