Browse Source

nextcloud, harbour: Fix WebDAV client nullable

pull/23/head
jld3103 2 years ago
parent
commit
b8636b1e95
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/harbour/lib/src/apps/files/blocs/browser.dart
  2. 12
      packages/harbour/lib/src/apps/files/blocs/files.dart
  3. 2
      packages/harbour/lib/src/apps/files/utils/download_task.dart
  4. 2
      packages/harbour/lib/src/apps/files/utils/upload_task.dart
  5. 4
      packages/nextcloud/lib/src/client.dart
  6. 72
      packages/nextcloud/test/webdav_test.dart

4
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,

12
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'},
),

2
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 {

2
packages/harbour/lib/src/apps/files/utils/upload_task.dart

@ -16,7 +16,7 @@ class UploadTask {
Future execute(final NextcloudClient client, final Stream<List<int>> 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());

4
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<T>(final T? t) {
T _getUsernameRequiredClient<T>(final T? t) {
if (t != null) {
return t;
}

72
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',

Loading…
Cancel
Save