From 563bd36f81b43c571be1a2df7e18b07d7b5d56a1 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 29 Sep 2023 07:04:01 +0200 Subject: [PATCH] refactor(nextcloud): Move version support to helpers Signed-off-by: jld3103 --- packages/nextcloud/lib/nextcloud.dart | 2 +- packages/nextcloud/lib/src/helpers/core.dart | 20 +++++++ packages/nextcloud/lib/src/helpers/news.dart | 18 ++++++ packages/nextcloud/lib/src/helpers/notes.dart | 21 +++++++ .../nextcloud/lib/src/version_supported.dart | 59 ------------------- 5 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 packages/nextcloud/lib/src/helpers/notes.dart delete mode 100644 packages/nextcloud/lib/src/version_supported.dart diff --git a/packages/nextcloud/lib/nextcloud.dart b/packages/nextcloud/lib/nextcloud.dart index 27cd9bef..1a34fc93 100644 --- a/packages/nextcloud/lib/nextcloud.dart +++ b/packages/nextcloud/lib/nextcloud.dart @@ -25,8 +25,8 @@ export 'src/app_type.dart'; export 'src/client.dart'; export 'src/helpers/core.dart'; export 'src/helpers/news.dart'; +export 'src/helpers/notes.dart'; export 'src/helpers/notifications.dart'; -export 'src/version_supported.dart'; export 'src/webdav/client.dart'; export 'src/webdav/file.dart'; export 'src/webdav/props.dart'; diff --git a/packages/nextcloud/lib/src/helpers/core.dart b/packages/nextcloud/lib/src/helpers/core.dart index fa9bf6a4..1ee7482a 100644 --- a/packages/nextcloud/lib/src/helpers/core.dart +++ b/packages/nextcloud/lib/src/helpers/core.dart @@ -1,5 +1,25 @@ // ignore_for_file: public_member_api_docs +import 'package:nextcloud/src/api/core.openapi.dart'; + +/// Version of core/Server supported +const coreSupportedVersion = 27; + +extension CoreVersionSupported on CoreClient { + /// Check if the core/Server version is supported by this client + /// + /// Also returns the supported version number + (bool, int) isSupported(final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) => ( + capabilities.version.major == coreSupportedVersion, + coreSupportedVersion, + ); +} + +extension CoreStatusVersionSupported on CoreStatus { + /// Check if the core/Server version is supported + bool get isSupported => version.startsWith('$coreSupportedVersion.'); +} + enum ShareType { user, group, diff --git a/packages/nextcloud/lib/src/helpers/news.dart b/packages/nextcloud/lib/src/helpers/news.dart index b6833654..f5942fed 100644 --- a/packages/nextcloud/lib/src/helpers/news.dart +++ b/packages/nextcloud/lib/src/helpers/news.dart @@ -1,5 +1,23 @@ // ignore_for_file: public_member_api_docs +import 'package:nextcloud/src/api/news.openapi.dart'; + +/// API version of the news app supported +const newsSupportedVersion = 'v1-3'; + +extension NewsVersionSupported on NewsClient { + /// Check if the news app version is supported by this client + /// + /// Also returns the supported API version number + Future<(bool, String)> isSupported() async { + final response = await getSupportedApiVersions(); + return ( + response.body.apiLevels!.contains(newsSupportedVersion), + newsSupportedVersion, + ); + } +} + /// See https://github.com/nextcloud/news/blob/4a107b3d53c4fe651ac704251b99e04a53cd587f/lib/Db/ListType.php enum NewsListType { feed, diff --git a/packages/nextcloud/lib/src/helpers/notes.dart b/packages/nextcloud/lib/src/helpers/notes.dart new file mode 100644 index 00000000..afcbf2a1 --- /dev/null +++ b/packages/nextcloud/lib/src/helpers/notes.dart @@ -0,0 +1,21 @@ +import 'package:collection/collection.dart'; +import 'package:nextcloud/src/api/core.openapi.dart'; +import 'package:nextcloud/src/api/notes.openapi.dart'; +import 'package:version/version.dart'; + +/// API version of the notes app supported +const notesSupportedVersion = 1; + +// ignore: public_member_api_docs +extension NotesVersionSupported on NotesClient { + /// Check if the notes app version is supported by this client + /// + /// Also returns the supported API version number + (bool, int) isSupported(final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) => ( + capabilities.capabilities.notesCapabilities?.notes.apiVersion + ?.map(Version.parse) + .firstWhereOrNull((final version) => version.major == notesSupportedVersion) != + null, + notesSupportedVersion, + ); +} diff --git a/packages/nextcloud/lib/src/version_supported.dart b/packages/nextcloud/lib/src/version_supported.dart deleted file mode 100644 index 7ef7e169..00000000 --- a/packages/nextcloud/lib/src/version_supported.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:nextcloud/src/api/core.openapi.dart'; -import 'package:nextcloud/src/api/news.openapi.dart'; -import 'package:nextcloud/src/api/notes.openapi.dart'; -import 'package:version/version.dart'; - -/// Version of core/Server supported -const coreSupportedVersion = 27; - -/// API version of the news app supported -const newsSupportedVersion = 'v1-3'; - -/// API version of the notes app supported -const notesSupportedVersion = 1; - -// ignore: public_member_api_docs -extension CoreVersionSupported on CoreClient { - /// Check if the core/Server version is supported by this client - /// - /// Also returns the supported version number - (bool, int) isSupported(final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) => ( - capabilities.version.major == coreSupportedVersion, - coreSupportedVersion, - ); -} - -// ignore: public_member_api_docs -extension CoreStatusVersionSupported on CoreStatus { - /// Check if the core/Server version is supported - bool get isSupported => version.startsWith('$coreSupportedVersion.'); -} - -// ignore: public_member_api_docs -extension NewsVersionSupported on NewsClient { - /// Check if the news app version is supported by this client - /// - /// Also returns the supported API version number - Future<(bool, String)> isSupported() async { - final response = await getSupportedApiVersions(); - return ( - response.body.apiLevels!.contains(newsSupportedVersion), - newsSupportedVersion, - ); - } -} - -// ignore: public_member_api_docs -extension NotesVersionSupported on NotesClient { - /// Check if the notes app version is supported by this client - /// - /// Also returns the supported API version number - (bool, int) isSupported(final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) => ( - capabilities.capabilities.notesCapabilities?.notes.apiVersion - ?.map(Version.parse) - .firstWhereOrNull((final version) => version.major == notesSupportedVersion) != - null, - notesSupportedVersion, - ); -}