From b8636b1e9553be054215132b9fe14976552acdec Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 15 Jul 2022 11:34:05 +0200 Subject: [PATCH] nextcloud, harbour: Fix WebDAV client nullable --- .../lib/src/apps/files/blocs/browser.dart | 4 +- .../lib/src/apps/files/blocs/files.dart | 12 ++-- .../src/apps/files/utils/download_task.dart | 2 +- .../lib/src/apps/files/utils/upload_task.dart | 2 +- packages/nextcloud/lib/src/client.dart | 4 +- packages/nextcloud/test/webdav_test.dart | 72 +++++++++---------- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/packages/harbour/lib/src/apps/files/blocs/browser.dart b/packages/harbour/lib/src/apps/files/blocs/browser.dart index 55a1cd03..85c377df 100644 --- a/packages/harbour/lib/src/apps/files/blocs/browser.dart +++ b/packages/harbour/lib/src/apps/files/blocs/browser.dart @@ -39,7 +39,7 @@ class FilesBrowserBloc extends $FilesBrowserBloc { _$createFolderEvent.listen((final path) { _wrapAction( - () async => client.webdav!.mkdir( + () async => client.webdav.mkdir( path.join('/'), safe: false, ), @@ -60,7 +60,7 @@ class FilesBrowserBloc extends $FilesBrowserBloc { void _loadFiles() { _requestManager .wrapWithoutCache( - () async => client.webdav!.ls( + () async => client.webdav.ls( _pathSubject.value.join('/'), props: { WebDavProps.davContentType.name, diff --git a/packages/harbour/lib/src/apps/files/blocs/files.dart b/packages/harbour/lib/src/apps/files/blocs/files.dart index c1fb7e7a..c42a79af 100644 --- a/packages/harbour/lib/src/apps/files/blocs/files.dart +++ b/packages/harbour/lib/src/apps/files/blocs/files.dart @@ -119,13 +119,13 @@ class FilesBloc extends $FilesBloc { }); _$deleteEvent.listen((final path) { - _wrapAction(false, () async => client.webdav!.delete(path.join('/'))); + _wrapAction(false, () async => client.webdav.delete(path.join('/'))); }); _$renameEvent.listen((final event) { _wrapAction( false, - () async => client.webdav!.move( + () async => client.webdav.move( event.path.join('/'), (event.path.sublist(0, event.path.length - 1)..add(event.name)).join('/'), ), @@ -135,7 +135,7 @@ class FilesBloc extends $FilesBloc { _$moveEvent.listen((final event) { _wrapAction( false, - () async => client.webdav!.move( + () async => client.webdav.move( event.path.join('/'), event.destination.join('/'), ), @@ -145,7 +145,7 @@ class FilesBloc extends $FilesBloc { _$copyEvent.listen((final event) { _wrapAction( false, - () async => client.webdav!.copy( + () async => client.webdav.copy( event.path.join('/'), event.destination.join('/'), ), @@ -155,7 +155,7 @@ class FilesBloc extends $FilesBloc { _$addFavoriteEvent.listen((final path) { _wrapAction( false, - () async => client.webdav!.updateProps( + () async => client.webdav.updateProps( path.join('/'), {WebDavProps.ocFavorite.name: '1'}, ), @@ -165,7 +165,7 @@ class FilesBloc extends $FilesBloc { _$removeFavoriteEvent.listen((final path) { _wrapAction( false, - () async => client.webdav!.updateProps( + () async => client.webdav.updateProps( path.join('/'), {WebDavProps.ocFavorite.name: '0'}, ), diff --git a/packages/harbour/lib/src/apps/files/utils/download_task.dart b/packages/harbour/lib/src/apps/files/utils/download_task.dart index e0921af3..f4af3532 100644 --- a/packages/harbour/lib/src/apps/files/utils/download_task.dart +++ b/packages/harbour/lib/src/apps/files/utils/download_task.dart @@ -13,7 +13,7 @@ class DownloadTask { Future execute(final NextcloudClient client, final IOSink sink) async { final completer = Completer(); - final response = await client.webdav!.downloadStream(path.join('/')); + final response = await client.webdav.downloadStream(path.join('/')); var downloaded = 0; response.listen((final chunk) async { diff --git a/packages/harbour/lib/src/apps/files/utils/upload_task.dart b/packages/harbour/lib/src/apps/files/utils/upload_task.dart index 9040381b..6a52f431 100644 --- a/packages/harbour/lib/src/apps/files/utils/upload_task.dart +++ b/packages/harbour/lib/src/apps/files/utils/upload_task.dart @@ -16,7 +16,7 @@ class UploadTask { Future execute(final NextcloudClient client, final Stream> stream) async { var uploaded = 0; - await client.webdav!.uploadStream( + await client.webdav.uploadStream( stream.map((final chunk) { uploaded += chunk.length; _streamController.add((uploaded / size * 100).toInt()); diff --git a/packages/nextcloud/lib/src/client.dart b/packages/nextcloud/lib/src/client.dart index 97656ec4..b535a846 100644 --- a/packages/nextcloud/lib/src/client.dart +++ b/packages/nextcloud/lib/src/client.dart @@ -113,7 +113,7 @@ class NextcloudClient { late NextcloudUserStatusClient _userStatus; /// Client for WebDAV. Might be null if no username is set for the client - NextcloudWebDAVClient? get webdav => _getUsernameRequiredClient(_webdav); + NextcloudWebDAVClient get webdav => _getUsernameRequiredClient(_webdav); /// Client for Core APIs NextcloudCoreClient get core => _core; @@ -133,7 +133,7 @@ class NextcloudClient { /// Client for User Status NextcloudUserStatusClient get userStatus => _userStatus; - T? _getUsernameRequiredClient(final T? t) { + T _getUsernameRequiredClient(final T? t) { if (t != null) { return t; } diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index d014f154..f6592a29 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -24,13 +24,13 @@ Future main() async { }); test('Get status', () async { - final status = await client.webdav!.status(); + final status = await client.webdav.status(); expect(status.capabilities, containsAll(['1', '3', 'access-control'])); expect(status.searchCapabilities, hasLength(0)); }); test('List directory', () async { - final files = await client.webdav!.ls( + final files = await client.webdav.ls( '/', props: { WebDavProps.ncHasPreview.name, @@ -48,7 +48,7 @@ Future main() async { }); test('Create directory', () async { - final response = await client.webdav!.mkdir('test'); + final response = await client.webdav.mkdir('test'); expect(response.statusCode, equals(201)); }); @@ -56,13 +56,13 @@ Future main() async { final pngBytes = File('test/files/test.png').readAsBytesSync(); final txtBytes = File('test/files/test.txt').readAsBytesSync(); - var response = await client.webdav!.upload(pngBytes, 'test.png'); + var response = await client.webdav.upload(pngBytes, 'test.png'); expect(response.statusCode, equals(201)); - response = await client.webdav!.upload(txtBytes, 'test.txt'); + response = await client.webdav.upload(txtBytes, 'test.txt'); expect(response.statusCode, equals(201)); - final files = await client.webdav!.ls( + final files = await client.webdav.ls( '/', props: { WebDavProps.ocSize.name, @@ -76,31 +76,31 @@ Future main() async { }); test('Copy file', () async { - final response = await client.webdav!.copy( + final response = await client.webdav.copy( 'Nextcloud.png', 'test.png', ); expect(response.statusCode, 201); - final files = await client.webdav!.ls('/'); + final files = await client.webdav.ls('/'); expect(files.where((final f) => f.name == 'Nextcloud.png'), hasLength(1)); expect(files.where((final f) => f.name == 'test.png'), hasLength(1)); }); test('Copy file (overwrite fail)', () async { - await client.webdav!.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); - await client.webdav!.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); expect( - () => client.webdav!.copy('1.txt', '2.txt'), + () => client.webdav.copy('1.txt', '2.txt'), throwsA(predicate((final e) => (e! as ApiException).code == 412)), ); }); test('Copy file (overwrite success)', () async { - await client.webdav!.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); - await client.webdav!.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); - final response = await client.webdav!.copy( + final response = await client.webdav.copy( '1.txt', '2.txt', overwrite: true, @@ -109,31 +109,31 @@ Future main() async { }); test('Move file', () async { - final response = await client.webdav!.move( + final response = await client.webdav.move( 'Nextcloud.png', 'test.png', ); expect(response.statusCode, 201); - final files = await client.webdav!.ls('/'); + final files = await client.webdav.ls('/'); expect(files.where((final f) => f.name == 'Nextcloud.png'), hasLength(0)); expect(files.where((final f) => f.name == 'test.png'), hasLength(1)); }); test('Move file (overwrite fail)', () async { - await client.webdav!.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); - await client.webdav!.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); expect( - () => client.webdav!.move('1.txt', '2.txt'), + () => client.webdav.move('1.txt', '2.txt'), throwsA(predicate((final e) => (e! as ApiException).code == 412)), ); }); test('Move file (overwrite success)', () async { - await client.webdav!.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); - await client.webdav!.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('1')), '1.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('2')), '2.txt'); - final response = await client.webdav!.move( + final response = await client.webdav.move( '1.txt', '2.txt', overwrite: true, @@ -142,7 +142,7 @@ Future main() async { }); test('Get file props', () async { - final file = await client.webdav!.getProps( + final file = await client.webdav.getProps( 'Nextcloud.png', props: { WebDavProps.ncHasPreview.name, @@ -159,10 +159,10 @@ Future main() async { test('Get directory props', () async { final data = Uint8List.fromList(utf8.encode('test')); - await client.webdav!.mkdir('test'); - await client.webdav!.upload(data, 'test/test.txt'); + await client.webdav.mkdir('test'); + await client.webdav.upload(data, 'test/test.txt'); - final file = await client.webdav!.getProps( + final file = await client.webdav.getProps( 'test', props: { WebDavProps.davResourceType.name, @@ -179,11 +179,11 @@ Future main() async { }); test('Filter files', () async { - final response = await client.webdav!.upload(Uint8List.fromList(utf8.encode('test')), 'test.txt'); + final response = await client.webdav.upload(Uint8List.fromList(utf8.encode('test')), 'test.txt'); final id = response.headers['oc-fileid']!.first; - await client.webdav!.updateProps('test.txt', {WebDavProps.ocFavorite.name: '1'}); + await client.webdav.updateProps('test.txt', {WebDavProps.ocFavorite.name: '1'}); - final files = await client.webdav!.filter( + final files = await client.webdav.filter( '/', { WebDavProps.ocFavorite.name: '1', @@ -204,15 +204,15 @@ Future main() async { final createdEpoch = createdDate.millisecondsSinceEpoch / 1000; final uploadTime = DateTime.now(); - await client.webdav!.upload(Uint8List.fromList(utf8.encode('test')), 'test.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('test')), 'test.txt'); - final updated = await client.webdav!.updateProps('test.txt', { + final updated = await client.webdav.updateProps('test.txt', { WebDavProps.ocFavorite.name: '1', WebDavProps.ncCreationTime.name: '$createdEpoch', }); expect(updated, isTrue); - final file = await client.webdav!.getProps( + final file = await client.webdav.getProps( 'test.txt', props: { WebDavProps.ocFavorite.name, @@ -226,16 +226,16 @@ Future main() async { }); test('Set custom properties', () async { - client.webdav!.registerNamespace('http://example.com/ns', 'test'); + client.webdav.registerNamespace('http://example.com/ns', 'test'); - await client.webdav!.upload(Uint8List.fromList(utf8.encode('test')), 'test.txt'); + await client.webdav.upload(Uint8List.fromList(utf8.encode('test')), 'test.txt'); - final updated = await client.webdav!.updateProps('test.txt', { + final updated = await client.webdav.updateProps('test.txt', { 'test:custom': 'test-custom-prop-value', }); expect(updated, isTrue); - final file = await client.webdav!.getProps( + final file = await client.webdav.getProps( 'test.txt', props: { 'test:custom',