34 lines
1.3 KiB
Dart
34 lines
1.3 KiB
Dart
import '../../model/account_data.dart';
|
|
import '../../model/endpoint_data.dart';
|
|
|
|
/// Shared helpers for Nextcloud OCS v2 endpoints.
|
|
///
|
|
/// Three call sites previously duplicated the same header dictionary and the
|
|
/// same URI scaffolding (TalkApi, AutocompleteApi, FileSharingApi). Anything
|
|
/// that talks to `https://<domain>/<base>/ocs/v2.php/...` should go through
|
|
/// these two helpers so additions like a new header or a different auth
|
|
/// scheme only need to change here.
|
|
class NextcloudOcs {
|
|
NextcloudOcs._();
|
|
|
|
/// The standard OCS request header set: JSON accept, OCS API marker,
|
|
/// HTTP Basic auth from the active [AccountData].
|
|
static Map<String, String> headers() => {
|
|
'Accept': 'application/json',
|
|
'OCS-APIRequest': 'true',
|
|
'Authorization': AccountData().getBasicAuthHeader(),
|
|
};
|
|
|
|
/// Builds an OCS URI by appending [pathSuffix] under `/ocs/v2.php/` of
|
|
/// the configured Nextcloud endpoint. Query parameters are converted to
|
|
/// strings (Uri rejects non-string values).
|
|
static Uri uri(String pathSuffix, {Map<String, dynamic>? queryParameters}) {
|
|
final endpoint = EndpointData().nextcloud();
|
|
return Uri.https(
|
|
endpoint.domain,
|
|
'${endpoint.path}/ocs/v2.php/$pathSuffix',
|
|
queryParameters?.map((key, value) => MapEntry(key, value.toString())),
|
|
);
|
|
}
|
|
}
|