Browse Source

neon_files: Cache WebDAV requests

pull/262/head
jld3103 2 years ago
parent
commit
ebf7928bcf
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 37
      packages/neon/neon_files/lib/blocs/browser.dart
  2. 8
      packages/neon/neon_files/lib/blocs/files.dart
  3. 1
      packages/neon/neon_files/lib/neon_files.dart
  4. 1
      packages/neon/neon_files/lib/utils/upload_task.dart

37
packages/neon/neon_files/lib/blocs/browser.dart

@ -14,12 +14,14 @@ abstract class FilesBrowserBlocStates {
class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents, FilesBrowserBlocStates {
FilesBrowserBloc(
this._requestManager,
this.options,
this.client,
) {
unawaited(refresh());
}
final RequestManager _requestManager;
final FilesAppSpecificOptions options;
final NextcloudClient client;
@ -38,26 +40,23 @@ class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents
@override
Future refresh() async {
// TODO: We have to do this manually, because we can't cache WebDAV stuff right now
try {
files.add(Result.loading());
final data = await client.webdav.ls(
await _requestManager.wrapWebDav<List<WebDavFile>>(
client.id,
'files-${path.value.join('/')}',
files,
() async => client.webdav.ls(
path.value.join('/'),
props: {
WebDavProps.davContentType.name,
WebDavProps.davETag.name,
WebDavProps.davLastModified.name,
WebDavProps.ncHasPreview.name,
WebDavProps.ocSize.name,
WebDavProps.ocFavorite.name,
},
);
files.add(Result.success(data));
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());
files.add(Result.error(e));
}
prop: WebDavPropfindProp(
davgetcontenttype: true,
davgetetag: true,
davgetlastmodified: true,
nchaspreview: true,
ocsize: true,
ocfavorite: true,
),
),
(final response) => response.toWebDavFiles(client.webdav),
);
}
@override

8
packages/neon/neon_files/lib/blocs/files.dart

@ -30,6 +30,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
FilesBloc(
this.options,
this.client,
this._requestManager,
this._platform,
) {
options.uploadQueueParallelism.stream.listen((final value) {
@ -42,6 +43,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
final FilesAppSpecificOptions options;
final NextcloudClient client;
final RequestManager _requestManager;
final NeonPlatform _platform;
late final browser = getNewFilesBrowserBloc();
@ -64,7 +66,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
@override
void addFavorite(final List<String> path) {
wrapAction(() async => client.webdav.updateProps(path.join('/'), {WebDavProps.ocFavorite.name: '1'}));
wrapAction(() async => client.webdav.updateProps(path.join('/'), WebDavProp(ocfavorite: 1)));
}
@override
@ -120,7 +122,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
wrapAction(
() async => client.webdav.updateProps(
path.join('/'),
{WebDavProps.ocFavorite.name: '0'},
WebDavProp(ocfavorite: 0),
),
);
}
@ -193,5 +195,5 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
}
}
FilesBrowserBloc getNewFilesBrowserBloc() => FilesBrowserBloc(options, client);
FilesBrowserBloc getNewFilesBrowserBloc() => FilesBrowserBloc(_requestManager, options, client);
}

1
packages/neon/neon_files/lib/neon_files.dart

@ -51,6 +51,7 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
FilesBloc buildBloc(final NextcloudClient client) => FilesBloc(
options,
client,
requestManager,
platform,
);

1
packages/neon/neon_files/lib/utils/upload_task.dart

@ -24,6 +24,7 @@ class UploadTask {
return Uint8List.fromList(chunk);
}),
path.join('/'),
lastModified: lastModified,
);
}
}

Loading…
Cancel
Save