Browse Source

refactor(nextcloud): Rename WebDAV path variables

pull/520/head
jld3103 2 years ago
parent
commit
25f5ff78f5
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 52
      packages/nextcloud/lib/src/webdav/client.dart

52
packages/nextcloud/lib/src/webdav/client.dart

@ -91,9 +91,9 @@ class WebDavClient {
); );
} }
/// make a dir with [remotePath] under current dir /// make a dir with [path] under current dir
Future<HttpClientResponse> mkdir( Future<HttpClientResponse> mkdir(
final String remotePath, { final String path, {
final bool safe = true, final bool safe = true,
}) async { }) async {
final expectedCodes = [ final expectedCodes = [
@ -105,21 +105,21 @@ class WebDavClient {
]; ];
return _send( return _send(
'MKCOL', 'MKCOL',
_constructPath(remotePath), _constructPath(path),
expectedCodes, expectedCodes,
); );
} }
/// just like mkdir -p /// just like mkdir -p
Future<HttpClientResponse?> mkdirs( Future<HttpClientResponse?> mkdirs(
final String remotePath, { final String path, {
final bool safe = true, final bool safe = true,
}) async { }) async {
final dirs = remotePath.trim().split('/')..removeWhere((final value) => value == ''); final dirs = path.trim().split('/')..removeWhere((final value) => value == '');
if (dirs.isEmpty) { if (dirs.isEmpty) {
return null; return null;
} }
if (remotePath.trim().startsWith('/')) { if (path.trim().startsWith('/')) {
dirs[0] = '/${dirs[0]}'; // coverage:ignore-line dirs[0] = '/${dirs[0]}'; // coverage:ignore-line
} }
final prevPath = StringBuffer(); final prevPath = StringBuffer();
@ -161,32 +161,32 @@ class WebDavClient {
return headers.isNotEmpty ? headers : null; return headers.isNotEmpty ? headers : null;
} }
/// upload a new file with [localData] as content to [remotePath] /// upload a new file with [localData] as content to [path]
Future<HttpClientResponse> upload( Future<HttpClientResponse> upload(
final Uint8List localData, final Uint8List localData,
final String remotePath, { final String path, {
final DateTime? lastModified, final DateTime? lastModified,
final DateTime? created, final DateTime? created,
}) => }) =>
uploadStream( uploadStream(
Stream.value(localData), Stream.value(localData),
remotePath, path,
lastModified: lastModified, lastModified: lastModified,
created: created, created: created,
contentLength: localData.lengthInBytes, contentLength: localData.lengthInBytes,
); );
/// upload a new file with [localData] as content to [remotePath] /// upload a new file with [localData] as content to [path]
Future<HttpClientResponse> uploadStream( Future<HttpClientResponse> uploadStream(
final Stream<Uint8List> localData, final Stream<Uint8List> localData,
final String remotePath, { final String path, {
final DateTime? lastModified, final DateTime? lastModified,
final DateTime? created, final DateTime? created,
final int? contentLength, final int? contentLength,
}) async => }) async =>
_send( _send(
'PUT', 'PUT',
_constructPath(remotePath), _constructPath(path),
[200, 201, 204], [200, 201, 204],
data: localData, data: localData,
headers: _generateUploadHeaders( headers: _generateUploadHeaders(
@ -196,32 +196,32 @@ class WebDavClient {
), ),
); );
/// download [remotePath] and store the response file contents to String /// download [path] and store the response file contents to String
Future<Uint8List> download(final String remotePath) async => (await downloadStream(remotePath)).bodyBytes; Future<Uint8List> download(final String path) async => (await downloadStream(path)).bodyBytes;
/// download [remotePath] and store the response file contents to ByteStream /// download [path] and store the response file contents to ByteStream
Future<HttpClientResponse> downloadStream(final String remotePath) async => _send( Future<HttpClientResponse> downloadStream(final String path) async => _send(
'GET', 'GET',
_constructPath(remotePath), _constructPath(path),
[200], [200],
); );
Future<WebDavMultistatus> _parseResponse(final HttpClientResponse response) async => Future<WebDavMultistatus> _parseResponse(final HttpClientResponse response) async =>
WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.body).rootElement); WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.body).rootElement);
/// list the directories and files under given [remotePath]. /// list the directories and files under given [path].
/// ///
/// Optionally populates the given [prop]s on the returned files. /// Optionally populates the given [prop]s on the returned files.
/// [depth] can be '0', '1' or 'infinity'. /// [depth] can be '0', '1' or 'infinity'.
Future<WebDavMultistatus> ls( Future<WebDavMultistatus> ls(
final String remotePath, { final String path, {
final WebDavPropfindProp? prop, final WebDavPropfindProp? prop,
final String? depth, final String? depth,
}) async { }) async {
assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity'); assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity');
final response = await _send( final response = await _send(
'PROPFIND', 'PROPFIND',
_constructPath(remotePath), _constructPath(path),
[207, 301], [207, 301],
data: Stream.value( data: Stream.value(
Uint8List.fromList( Uint8List.fromList(
@ -249,17 +249,17 @@ class WebDavClient {
} }
/// Runs the filter-files report with the given [filterRules] on the /// Runs the filter-files report with the given [filterRules] on the
/// [remotePath]. /// [path].
/// ///
/// Optionally populates the given [prop]s on the returned files. /// Optionally populates the given [prop]s on the returned files.
Future<WebDavMultistatus> filter( Future<WebDavMultistatus> filter(
final String remotePath, final String path,
final WebDavOcFilterRules filterRules, { final WebDavOcFilterRules filterRules, {
final WebDavPropfindProp? prop, final WebDavPropfindProp? prop,
}) async { }) async {
final response = await _send( final response = await _send(
'REPORT', 'REPORT',
_constructPath(remotePath), _constructPath(path),
[200, 207], [200, 207],
data: Stream.value( data: Stream.value(
Uint8List.fromList( Uint8List.fromList(
@ -275,16 +275,16 @@ class WebDavClient {
return _parseResponse(response); return _parseResponse(response);
} }
/// Update (string) properties of the given [remotePath]. /// Update (string) properties of the given [path].
/// ///
/// Returns true if the update was successful. /// Returns true if the update was successful.
Future<bool> updateProps( Future<bool> updateProps(
final String remotePath, final String path,
final WebDavProp prop, final WebDavProp prop,
) async { ) async {
final response = await _send( final response = await _send(
'PROPPATCH', 'PROPPATCH',
_constructPath(remotePath), _constructPath(path),
[200, 207], [200, 207],
data: Stream.value( data: Stream.value(
Uint8List.fromList( Uint8List.fromList(

Loading…
Cancel
Save