Skip to content

Commit

Permalink
refactor(nextcloud)!: Remove WebDavFile in favor of low-level WebDavR…
Browse files Browse the repository at this point in the history
…esponse

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 9, 2024
1 parent 548176b commit efc8823
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sealed class FilesBrowserBloc implements InteractiveBloc {
webdav.PathUri? hideUri,
}) = _FilesBrowserBloc;

BehaviorSubject<Result<BuiltList<webdav.WebDavFile>>> get files;
BehaviorSubject<Result<BuiltList<webdav.WebDavResponse>>> get files;

/// Mode to operate the `FilesBrowserView` in.
FilesBrowserMode get mode;
Expand Down Expand Up @@ -95,8 +95,12 @@ class _FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBloc {
depth: webdav.WebDavDepth.one,
),
converter: const webdav.WebDavResponseConverter(),
unwrap: (response) => BuiltList<webdav.WebDavFile>.build((b) {
for (final file in response.toWebDavFiles()) {
unwrap: (response) => BuiltList<webdav.WebDavResponse>.build((b) {
for (final file in response.responses) {
if (file.href == null) {
continue;
}

// Do not show itself
if (uri == file.path) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class FileDetails {
}) : task = null;

FileDetails.fromWebDav({
required webdav.WebDavFile file,
required webdav.WebDavResponse file,
}) : uri = file.path,
size = file.size,
etag = file.etag,
mimeType = file.mimeType,
lastModified = file.lastModified,
isFavorite = file.favorite,
blurHash = file.blurHash,
size = file.props.ocSize,
etag = file.props.davGetetag,
mimeType = file.props.davGetcontenttype,
lastModified = file.props.davGetlastmodified,
isFavorite = file.props.ocFavorite,
blurHash = file.props.ncMetadataBlurhash,
task = null;

FileDetails.fromUploadTask({
Expand All @@ -38,18 +38,18 @@ class FileDetails {

FileDetails.fromDownloadTask({
required FilesDownloadTask this.task,
required webdav.WebDavFile file,
required webdav.WebDavResponse file,
}) : uri = task.uri,
size = file.size,
etag = file.etag,
mimeType = file.mimeType,
lastModified = file.lastModified,
isFavorite = file.favorite,
blurHash = file.blurHash;
size = file.props.ocSize,
etag = file.props.davGetetag,
mimeType = file.props.davGetcontenttype,
lastModified = file.props.davGetlastmodified,
isFavorite = file.props.ocFavorite,
blurHash = file.props.ncMetadataBlurhash;

factory FileDetails.fromTask({
required FilesTask task,
required webdav.WebDavFile file,
required webdav.WebDavResponse file,
}) {
switch (task) {
case FilesUploadTask():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'package:neon_framework/sort_box.dart';
import 'package:nextcloud/utils.dart';
import 'package:nextcloud/webdav.dart' as webdav;

final filesSortBox = SortBox<FilesSortProperty, webdav.WebDavFile>(
final filesSortBox = SortBox<FilesSortProperty, webdav.WebDavResponse>(
properties: {
FilesSortProperty.name: (file) => file.name.toLowerCase(),
FilesSortProperty.modifiedDate: (file) => file.lastModified?.secondsSinceEpoch ?? 0,
FilesSortProperty.size: (file) => file.size ?? 0,
FilesSortProperty.modifiedDate: (file) => file.props.davGetlastmodified?.secondsSinceEpoch ?? 0,
FilesSortProperty.size: (file) => file.props.ocSize ?? 0,
FilesSortProperty.isFolder: (file) => file.isDirectory ? 0 : 1,
},
boxes: const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
);
}

Iterable<Widget> buildUploadTasks(BuiltList<FilesTask> tasks, List<webdav.WebDavFile> files) sync* {
Iterable<Widget> buildUploadTasks(BuiltList<FilesTask> tasks, List<webdav.WebDavResponse> files) sync* {
for (final task in tasks) {
if (task is! FilesUploadTask) {
continue;
Expand Down
1 change: 0 additions & 1 deletion packages/nextcloud/lib/src/api/webdav/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export 'path_uri.dart';
export 'props.dart';
export 'webdav.dart';
export 'webdav_depth.dart';
export 'webdav_file.dart';
export 'webdav_options.dart';
88 changes: 0 additions & 88 deletions packages/nextcloud/lib/src/api/webdav/models/webdav_file.dart

This file was deleted.

1 change: 1 addition & 0 deletions packages/nextcloud/lib/src/api/webdav/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export 'options_parser.dart';
export 'webdav_response_converter.dart';
export 'webdav_response_helpers.dart';
export 'webdav_uri.dart';
export 'xml_date_time_converter.dart';
export 'xml_duration_converter.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:nextcloud/src/api/webdav/models/models.dart';

/// Helpers
extension WebDavResponseHelpers on WebDavResponse {
/// All available props.
WebDavProp get props => propstats.singleWhere((propstat) => propstat.status.contains('200 OK')).prop;

/// The path of the resource.
PathUri get path {
final href = PathUri.parse(Uri.decodeFull(this.href!));
return PathUri(
isAbsolute: false,
isDirectory: href.isDirectory,
pathSegments: href.pathSegments.sublist(2),
);
}

/// The name of the resource.
String get name => path.name;

/// Whether the file is hidden.
bool get isHidden => props.ncHidden ?? name.startsWith('.');

/// Whether the file is a directory
bool get isDirectory => props.davResourcetype?.collection != null || path.isDirectory;
}

0 comments on commit efc8823

Please sign in to comment.