From 098b4123e628f392471fb21a4feb0081988de937 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 1 Aug 2023 09:52:42 +0200 Subject: [PATCH] refactor(nextcloud): Reorder WebDAV methods --- packages/nextcloud/lib/src/webdav/client.dart | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 4c736d5a..0d9eea6c 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -76,6 +76,28 @@ class WebDavClient { .where((final part) => part.isNotEmpty) .join('/'); + Future _parseResponse(final HttpClientResponse response) async => + WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.body).rootElement); + + Map? _getUploadHeaders({ + required final DateTime? lastModified, + required final DateTime? created, + required final int? contentLength, + }) { + final headers = { + if (lastModified != null) ...{ + 'X-OC-Mtime': (lastModified.millisecondsSinceEpoch ~/ 1000).toString(), + }, + if (created != null) ...{ + 'X-OC-CTime': (created.millisecondsSinceEpoch ~/ 1000).toString(), + }, + if (contentLength != null) ...{ + 'Content-Length': contentLength.toString(), + }, + }; + return headers.isNotEmpty ? headers : null; + } + /// Gets the WebDAV capabilities of the server. Future options() async { final response = await _send( @@ -121,25 +143,6 @@ class WebDavClient { [204], ); - Map? _generateUploadHeaders({ - required final DateTime? lastModified, - required final DateTime? created, - required final int? contentLength, - }) { - final headers = { - if (lastModified != null) ...{ - 'X-OC-Mtime': (lastModified.millisecondsSinceEpoch ~/ 1000).toString(), - }, - if (created != null) ...{ - 'X-OC-CTime': (created.millisecondsSinceEpoch ~/ 1000).toString(), - }, - if (contentLength != null) ...{ - 'Content-Length': contentLength.toString(), - }, - }; - return headers.isNotEmpty ? headers : null; - } - /// Puts a new file at [path] with [localData] as content. /// /// [lastModified] sets the date when the file was last modified on the server. @@ -177,7 +180,7 @@ class WebDavClient { _constructPath(path), [200, 201, 204], data: localData, - headers: _generateUploadHeaders( + headers: _getUploadHeaders( lastModified: lastModified, created: created, contentLength: contentLength, @@ -194,9 +197,6 @@ class WebDavClient { [200], ); - Future _parseResponse(final HttpClientResponse response) async => - WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.body).rootElement); - /// Retrieves the props for the resource at [path]. /// /// Optionally populates the given [prop]s on the returned files.