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. 35
      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

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

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

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

@ -30,6 +30,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
FilesBloc( FilesBloc(
this.options, this.options,
this.client, this.client,
this._requestManager,
this._platform, this._platform,
) { ) {
options.uploadQueueParallelism.stream.listen((final value) { options.uploadQueueParallelism.stream.listen((final value) {
@ -42,6 +43,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
final FilesAppSpecificOptions options; final FilesAppSpecificOptions options;
final NextcloudClient client; final NextcloudClient client;
final RequestManager _requestManager;
final NeonPlatform _platform; final NeonPlatform _platform;
late final browser = getNewFilesBrowserBloc(); late final browser = getNewFilesBrowserBloc();
@ -64,7 +66,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
@override @override
void addFavorite(final List<String> path) { 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 @override
@ -120,7 +122,7 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
wrapAction( wrapAction(
() async => client.webdav.updateProps( () async => client.webdav.updateProps(
path.join('/'), 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( FilesBloc buildBloc(final NextcloudClient client) => FilesBloc(
options, options,
client, client,
requestManager,
platform, platform,
); );

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

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

Loading…
Cancel
Save