part of '../../nextcloud.dart'; // ignore: public_member_api_docs extension WebDavMultistatusFile on WebDavMultistatus { /// Convert the [WebDavMultistatus] into a [WebDavFile] for easier handling List toWebDavFiles(final WebDavClient client) => responses .where((final response) => response.href != null) .map( (final response) => WebDavFile( basePath: client.basePath, response: response, ), ) .toList(); } /// WebDavFile class class WebDavFile { /// Creates a new WebDavFile object with the given path WebDavFile({ required final String basePath, required final WebDavResponse response, }) : _basePath = basePath, _response = response; final String _basePath; final WebDavResponse _response; /// Get the props of the file late final WebDavProp props = _response.propstats.singleWhere((final propstat) => propstat.status.contains('200')).prop; /// The path of file late final String path = Uri.decodeFull(_response.href!.substring(Uri.encodeFull(_basePath).length, _response.href!.length)); /// The fileid namespaced by the instance id, globally unique late final String? id = props.ocid; /// The unique id for the file within the instance late final String? fileId = props.ocfileid; /// Whether this is a collection resource type late final bool? isCollection = props.davresourcetype != null ? props.davresourcetype!.collection != null : null; /// Mime-type of the file late final String? mimeType = props.davgetcontenttype; /// ETag of the file late final String? etag = props.davgetetag; /// File content length or folder size late final int? size = props.ocsize ?? props.davgetcontentlength; /// The user id of the owner of a shared file late final String? ownerId = props.ocownerid; /// The display name of the owner of a shared file late final String? ownerDisplay = props.ocownerdisplayname; /// Share note late final String? note = props.ncnote; /// Last modified date of the file late final DateTime? lastModified = () { if (props.davgetlastmodified != null) { return webdavDateFormat.parseUtc(props.davgetlastmodified!); } return null; }(); /// Upload date of the file late final DateTime? uploadedDate = props.ncuploadtime != null ? DateTime.fromMillisecondsSinceEpoch(props.ncuploadtime! * 1000) : null; /// Creation date of the file as provided by uploader late final DateTime? createdDate = props.nccreationtime != null ? DateTime.fromMillisecondsSinceEpoch(props.nccreationtime! * 1000) : null; /// Whether this file is marked as favorite late final bool? favorite = props.ocfavorite == null ? null : props.ocfavorite == 1; /// Whether this file has a preview image late final bool? hasPreview = props.nchaspreview; /// Returns the decoded name of the file / folder without the whole path late final String name = () { // normalised path (remove trailing slash) final end = path.endsWith('/') ? path.length - 1 : path.length; final segments = Uri.parse(path, 0, end).pathSegments; if (segments.isNotEmpty) { return segments.last; } return ''; }(); /// Returns if the file is a directory late final bool isDirectory = (isCollection ?? false) || path.endsWith('/'); }