A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

220 lines
6.8 KiB

// ignore_for_file: camel_case_types
// ignore_for_file: discarded_futures
// ignore_for_file: public_member_api_docs
// ignore_for_file: unreachable_switch_case
import 'dart:typed_data';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:collection/collection.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:meta/meta.dart';
import 'package:universal_io/io.dart';
part 'files_trashbin.openapi.g.dart';
class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
super.authentications,
});
Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
PreviewClient get preview => PreviewClient(this);
}
class PreviewClient {
PreviewClient(this._rootClient);
final Client _rootClient;
/// Get the preview for a file.
///
/// Returns a [Future] containing a [DynamiteResponse] with the status code, deserialized body and headers.
/// Throws a [DynamiteApiException] if the API call does not return an expected status code.
///
/// Parameters:
/// * [fileId] ID of the file. Defaults to `-1`.
/// * [x] Width of the preview. Defaults to `32`.
/// * [y] Height of the preview. Defaults to `32`.
/// * [a] Whether to not crop the preview. Defaults to `0`.
///
/// Status codes:
/// * 200: Preview returned
/// * 400: Getting preview is not possible
/// * 404: Preview not found
///
/// See:
/// * [getPreviewRaw] for an experimental operation that returns a [DynamiteRawResponse] that can be serialized.
Future<DynamiteResponse<Uint8List, void>> getPreview({
final int fileId = -1,
final int x = 32,
final int y = 32,
final int a = 0,
}) async {
final rawResponse = getPreviewRaw(
fileId: fileId,
x: x,
y: y,
a: a,
);
return rawResponse.future;
}
/// Get the preview for a file.
///
/// This method and the response it returns is experimental. The API might change without a major version bump.
///
/// Returns a [Future] containing a [DynamiteRawResponse] with the raw [HttpClientResponse] and serialization helpers.
/// Throws a [DynamiteApiException] if the API call does not return an expected status code.
///
/// Parameters:
/// * [fileId] ID of the file. Defaults to `-1`.
/// * [x] Width of the preview. Defaults to `32`.
/// * [y] Height of the preview. Defaults to `32`.
/// * [a] Whether to not crop the preview. Defaults to `0`.
///
/// Status codes:
/// * 200: Preview returned
/// * 400: Getting preview is not possible
/// * 404: Preview not found
///
/// See:
/// * [getPreview] for an operation that returns a [DynamiteResponse] with a stable API.
@experimental
DynamiteRawResponse<Uint8List, void> getPreviewRaw({
final int fileId = -1,
final int x = 32,
final int y = 32,
final int a = 0,
}) {
final queryParameters = <String, dynamic>{};
final headers = <String, String>{
'Accept': '*/*',
};
Uint8List? body;
// coverage:ignore-start
final authentication = _rootClient.authentications.firstWhereOrNull(
(final auth) => switch (auth) {
DynamiteHttpBearerAuthentication() || DynamiteHttpBasicAuthentication() => true,
_ => false,
},
);
if (authentication != null) {
headers.addAll(
authentication.headers,
);
} else {
throw Exception('Missing authentication for bearer_auth or basic_auth');
}
// coverage:ignore-end
if (fileId != -1) {
queryParameters['fileId'] = fileId.toString();
}
if (x != 32) {
queryParameters['x'] = x.toString();
}
if (y != 32) {
queryParameters['y'] = y.toString();
}
if (a != 0) {
queryParameters['a'] = a.toString();
}
const path = '/index.php/apps/files_trashbin/preview';
final uri = Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null);
return DynamiteRawResponse<Uint8List, void>(
response: _rootClient.executeRequest(
'get',
uri,
headers,
body,
const {200},
),
bodyType: const FullType(Uint8List),
headersType: null,
serializers: _jsonSerializers,
);
}
}
@BuiltValue(instantiable: false)
abstract interface class Capabilities_FilesInterface {
bool get undelete;
}
abstract class Capabilities_Files
implements Capabilities_FilesInterface, Built<Capabilities_Files, Capabilities_FilesBuilder> {
factory Capabilities_Files([final void Function(Capabilities_FilesBuilder)? b]) = _$Capabilities_Files;
// coverage:ignore-start
const Capabilities_Files._();
// coverage:ignore-end
// coverage:ignore-start
factory Capabilities_Files.fromJson(final Map<String, dynamic> json) =>
_jsonSerializers.deserializeWith(serializer, json)!;
// coverage:ignore-end
// coverage:ignore-start
Map<String, dynamic> toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>;
// coverage:ignore-end
static Serializer<Capabilities_Files> get serializer => _$capabilitiesFilesSerializer;
}
@BuiltValue(instantiable: false)
abstract interface class CapabilitiesInterface {
Capabilities_Files get files;
}
abstract class Capabilities implements CapabilitiesInterface, Built<Capabilities, CapabilitiesBuilder> {
factory Capabilities([final void Function(CapabilitiesBuilder)? b]) = _$Capabilities;
// coverage:ignore-start
const Capabilities._();
// coverage:ignore-end
// coverage:ignore-start
factory Capabilities.fromJson(final Map<String, dynamic> json) => _jsonSerializers.deserializeWith(serializer, json)!;
// coverage:ignore-end
// coverage:ignore-start
Map<String, dynamic> toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>;
// coverage:ignore-end
static Serializer<Capabilities> get serializer => _$capabilitiesSerializer;
}
// coverage:ignore-start
final Serializers _serializers = (Serializers().toBuilder()
..addBuilderFactory(const FullType(Capabilities), Capabilities.new)
..add(Capabilities.serializer)
..addBuilderFactory(const FullType(Capabilities_Files), Capabilities_Files.new)
..add(Capabilities_Files.serializer))
.build();
final Serializers _jsonSerializers = (_serializers.toBuilder()
..add(DynamiteDoubleSerializer())
..addPlugin(StandardJsonPlugin())
..addPlugin(const ContentStringPlugin()))
.build();
// coverage:ignore-end