Browse Source

Merge pull request #1162 from nextcloud/feat/dynamite/parse_xml

pull/1166/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
6279fbfbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart
  2. 2
      packages/dynamite/dynamite_runtime/pubspec.yaml
  3. 3
      packages/nextcloud/lib/src/webdav/client.dart

20
packages/dynamite/dynamite_runtime/lib/src/http_extensions.dart

@ -3,13 +3,18 @@ import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';
import 'package:xml/xml.dart';
import 'package:xml/xml_events.dart';
/// A stream of bytes. /// A stream of bytes.
/// ///
/// Usually a `Stream<Uint8List>`. /// Usually a `Stream<Uint8List>`.
typedef BytesStream = Stream<List<int>>; typedef BytesStream = Stream<List<int>>;
final _utf8JsonDecoder = utf8.decoder.fuse(json.decoder); final _jsonBytesConverter = utf8.decoder.fuse(json.decoder);
final _xmlBytesConverter =
utf8.decoder.fuse(XmlEventDecoder()).fuse(const XmlNormalizeEvents()).fuse(const XmlNodeDecoder());
/// Extension on byte streams that enable efficient transformations. /// Extension on byte streams that enable efficient transformations.
extension BytesStreamExtension on BytesStream { extension BytesStreamExtension on BytesStream {
@ -26,7 +31,18 @@ extension BytesStreamExtension on BytesStream {
Future<String> get string => transform(utf8.decoder).join(); Future<String> get string => transform(utf8.decoder).join();
/// Converts the stream into a JSON using the [utf8] encoding. /// Converts the stream into a JSON using the [utf8] encoding.
Future<Object?> get json => transform(_utf8JsonDecoder).first; Future<Object?> get json => transform(_jsonBytesConverter).first;
/// Converts the stream into XML using the [utf8] encoding.
///
/// Returns the root element of this stream.
Future<XmlElement> get xml async {
final element = await transform(_xmlBytesConverter)
.expand((final events) => events)
.firstWhere((final element) => element is XmlElement);
return element as XmlElement;
}
} }
/// Extension on a http responses. /// Extension on a http responses.

2
packages/dynamite/dynamite_runtime/pubspec.yaml

@ -8,9 +8,11 @@ environment:
dependencies: dependencies:
built_collection: ^5.0.0 built_collection: ^5.0.0
built_value: ^8.0.1 built_value: ^8.0.1
collection: ^1.0.0
cookie_jar: ^4.0.7 cookie_jar: ^4.0.7
meta: ^1.0.0 meta: ^1.0.0
universal_io: ^2.0.0 universal_io: ^2.0.0
xml: ^6.0.0
dev_dependencies: dev_dependencies:
build_runner: ^2.4.6 build_runner: ^2.4.6

3
packages/nextcloud/lib/src/webdav/client.dart

@ -8,7 +8,6 @@ import 'package:nextcloud/src/webdav/path_uri.dart';
import 'package:nextcloud/src/webdav/props.dart'; import 'package:nextcloud/src/webdav/props.dart';
import 'package:nextcloud/src/webdav/webdav.dart'; import 'package:nextcloud/src/webdav/webdav.dart';
import 'package:universal_io/io.dart'; import 'package:universal_io/io.dart';
import 'package:xml/xml.dart' as xml;
/// Base path used on the server /// Base path used on the server
final webdavBase = PathUri.parse('/remote.php/webdav'); final webdavBase = PathUri.parse('/remote.php/webdav');
@ -73,7 +72,7 @@ class WebDavClient {
} }
Future<WebDavMultistatus> _parseResponse(final HttpClientResponse response) async => Future<WebDavMultistatus> _parseResponse(final HttpClientResponse response) async =>
WebDavMultistatus.fromXmlElement(xml.XmlDocument.parse(await response.string).rootElement); WebDavMultistatus.fromXmlElement(await response.xml);
Map<String, String> _getUploadHeaders({ Map<String, String> _getUploadHeaders({
required final DateTime? lastModified, required final DateTime? lastModified,

Loading…
Cancel
Save