diff --git a/.cspell/dart_flutter.txt b/.cspell/dart_flutter.txt index 0639e559..e0dd5859 100644 --- a/.cspell/dart_flutter.txt +++ b/.cspell/dart_flutter.txt @@ -1,4 +1,5 @@ autofocus +expando gapless lerp pubspec diff --git a/packages/neon/neon/lib/models.dart b/packages/neon/neon/lib/models.dart index 90ca9d97..f9ac5fc2 100644 --- a/packages/neon/neon/lib/models.dart +++ b/packages/neon/neon/lib/models.dart @@ -1,4 +1,3 @@ export 'package:neon/src/models/account.dart' hide Credentials, LoginQRcode; -export 'package:neon/src/models/app_ids.dart'; export 'package:neon/src/models/app_implementation.dart'; export 'package:neon/src/models/notifications_interface.dart'; diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index bb12f6e0..293d83fc 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -10,7 +10,6 @@ import 'package:neon/l10n/localizations.dart'; import 'package:neon/src/bloc/result_builder.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; -import 'package:neon/src/models/app_ids.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/models/notifications_interface.dart'; import 'package:neon/src/models/push_notification.dart'; diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index ae40f0be..f6d43310 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -16,6 +16,7 @@ import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/settings/models/storage.dart'; import 'package:neon/src/utils/account_options.dart'; import 'package:neon/src/utils/global_options.dart'; +import 'package:nextcloud/nextcloud.dart'; import 'package:rxdart/rxdart.dart'; const _keyAccounts = 'accounts'; diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 9733e0f6..4fe57871 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -7,7 +7,6 @@ import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/capabilities.dart'; import 'package:neon/src/models/account.dart'; -import 'package:neon/src/models/app_ids.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/models/notifications_interface.dart'; import 'package:neon/src/settings/models/options_collection.dart'; diff --git a/packages/neon/neon/lib/src/blocs/next_push.dart b/packages/neon/neon/lib/src/blocs/next_push.dart index 79ad6e62..04351230 100644 --- a/packages/neon/neon/lib/src/blocs/next_push.dart +++ b/packages/neon/neon/lib/src/blocs/next_push.dart @@ -6,6 +6,7 @@ import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; import 'package:neon/src/utils/global_options.dart'; +import 'package:nextcloud/nextcloud.dart'; import 'package:rxdart/rxdart.dart'; @internal diff --git a/packages/neon/neon/lib/src/models/app_ids.dart b/packages/neon/neon/lib/src/models/app_ids.dart deleted file mode 100644 index e4eaaaf3..00000000 --- a/packages/neon/neon/lib/src/models/app_ids.dart +++ /dev/null @@ -1,6 +0,0 @@ -sealed class AppIDs { - static const files = 'files'; - static const news = 'news'; - static const notes = 'notes'; - static const notifications = 'notifications'; -} diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index a66a881a..7cca87aa 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -16,6 +16,7 @@ import 'package:neon/src/widgets/app_bar.dart'; import 'package:neon/src/widgets/drawer.dart'; import 'package:neon/src/widgets/error.dart'; import 'package:neon/src/widgets/unified_search_results.dart'; +import 'package:nextcloud/nextcloud.dart'; import 'package:provider/provider.dart'; @internal diff --git a/packages/neon/neon/lib/src/settings/models/storage.dart b/packages/neon/neon/lib/src/settings/models/storage.dart index 307d9835..7e49d297 100644 --- a/packages/neon/neon/lib/src/settings/models/storage.dart +++ b/packages/neon/neon/lib/src/settings/models/storage.dart @@ -1,5 +1,5 @@ import 'package:meta/meta.dart'; -import 'package:neon/src/models/app_ids.dart'; +import 'package:nextcloud/ids.dart'; import 'package:shared_preferences/shared_preferences.dart'; @internal diff --git a/packages/neon/neon/lib/src/widgets/cached_image.dart b/packages/neon/neon/lib/src/widgets/cached_image.dart index 08a58bb6..077ec11c 100644 --- a/packages/neon/neon/lib/src/widgets/cached_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_image.dart @@ -5,12 +5,12 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import 'package:neon/nextcloud.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; import 'package:neon/src/utils/provider.dart'; import 'package:neon/src/widgets/error.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; +import 'package:nextcloud/nextcloud.dart'; typedef CacheReviver = FutureOr Function(CacheManager cacheManager); typedef ImageDownloader = FutureOr Function(); diff --git a/packages/neon/neon_files/lib/routes.dart b/packages/neon/neon_files/lib/routes.dart index ed634d9a..823bdc72 100644 --- a/packages/neon/neon_files/lib/routes.dart +++ b/packages/neon/neon_files/lib/routes.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; -import 'package:neon/models.dart'; +import 'package:neon/nextcloud.dart'; import 'package:neon/utils.dart'; import 'package:neon_files/neon_files.dart'; diff --git a/packages/neon/neon_news/lib/routes.dart b/packages/neon/neon_news/lib/routes.dart index 12f505de..359d2df5 100644 --- a/packages/neon/neon_news/lib/routes.dart +++ b/packages/neon/neon_news/lib/routes.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; -import 'package:neon/models.dart'; +import 'package:neon/nextcloud.dart'; import 'package:neon/utils.dart'; import 'package:neon_news/neon_news.dart'; diff --git a/packages/neon/neon_notes/lib/routes.dart b/packages/neon/neon_notes/lib/routes.dart index b4e00b50..4bfc0d47 100644 --- a/packages/neon/neon_notes/lib/routes.dart +++ b/packages/neon/neon_notes/lib/routes.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; -import 'package:neon/models.dart'; +import 'package:neon/nextcloud.dart'; import 'package:neon/utils.dart'; import 'package:neon_notes/neon_notes.dart'; diff --git a/packages/neon/neon_notifications/lib/routes.dart b/packages/neon/neon_notifications/lib/routes.dart index c2f57b75..233f8655 100644 --- a/packages/neon/neon_notifications/lib/routes.dart +++ b/packages/neon/neon_notifications/lib/routes.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; -import 'package:neon/models.dart'; +import 'package:neon/nextcloud.dart'; import 'package:neon/utils.dart'; import 'package:neon_notifications/neon_notifications.dart'; diff --git a/packages/nextcloud/bin/generate_exports.dart b/packages/nextcloud/bin/generate_exports.dart new file mode 100644 index 00000000..63adaa0a --- /dev/null +++ b/packages/nextcloud/bin/generate_exports.dart @@ -0,0 +1,62 @@ +// ignore_for_file: depend_on_referenced_packages +import 'dart:io'; + +import 'package:collection/collection.dart'; +import 'package:dynamite/src/helpers/dart_helpers.dart'; +import 'package:path/path.dart' as p; + +void main() { + final files = + Directory('lib/src/api').listSync().cast().where((final file) => file.path.endsWith('.openapi.dart')); + + final idStatements = []; + final exportStatements = [ + "export 'ids.dart';", + "export 'src/client.dart';", + "export 'webdav.dart';", + ]; + + for (final file in files) { + final basename = p.basename(file.path); + final id = basename.substring(0, basename.length - 13); + final variablePrefix = toDartName(id); + final classPrefix = toDartName(id, uppercaseFirstCharacter: true); + + idStatements.add(" static const $variablePrefix = '$id';"); + exportStatements.add("export '$id.dart';"); + + final exports = ["export 'src/api/$id.openapi.dart';"]; + if (File('lib/src/helpers/$id.dart').existsSync()) { + exports.add("export 'src/helpers/$id.dart';"); + } + + File('lib/$id.dart').writeAsStringSync(''' +import 'package:nextcloud/src/api/$id.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +${exports.join('\n')} + +// ignore: public_member_api_docs +extension ${classPrefix}Extension on NextcloudClient { + static final _$variablePrefix = Expando<${classPrefix}Client>(); + + /// Client for the $id APIs + ${classPrefix}Client get $variablePrefix => _$variablePrefix[this] ??= ${classPrefix}Client.fromClient(this); +} +'''); + } + + File('lib/ids.dart').writeAsStringSync(''' +// ignore_for_file: public_member_api_docs + +final class AppIDs { +${idStatements.join('\n')} +} +'''); + + File('lib/nextcloud.dart').writeAsStringSync(''' +export 'package:dynamite_runtime/http_client.dart' show CookieJar, DynamiteApiException, DynamiteRawResponse, DynamiteResponse; + +${exportStatements.sorted((final a, final b) => a.compareTo(b)).join('\n')} +'''); +} diff --git a/packages/nextcloud/lib/comments.dart b/packages/nextcloud/lib/comments.dart new file mode 100644 index 00000000..dfbc410d --- /dev/null +++ b/packages/nextcloud/lib/comments.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/comments.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/comments.openapi.dart'; + +// ignore: public_member_api_docs +extension CommentsExtension on NextcloudClient { + static final _comments = Expando(); + + /// Client for the comments APIs + CommentsClient get comments => _comments[this] ??= CommentsClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/core.dart b/packages/nextcloud/lib/core.dart new file mode 100644 index 00000000..f48993a4 --- /dev/null +++ b/packages/nextcloud/lib/core.dart @@ -0,0 +1,13 @@ +import 'package:nextcloud/src/api/core.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/core.openapi.dart'; +export 'src/helpers/core.dart'; + +// ignore: public_member_api_docs +extension CoreExtension on NextcloudClient { + static final _core = Expando(); + + /// Client for the core APIs + CoreClient get core => _core[this] ??= CoreClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/dashboard.dart b/packages/nextcloud/lib/dashboard.dart new file mode 100644 index 00000000..cf0167e0 --- /dev/null +++ b/packages/nextcloud/lib/dashboard.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/dashboard.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/dashboard.openapi.dart'; + +// ignore: public_member_api_docs +extension DashboardExtension on NextcloudClient { + static final _dashboard = Expando(); + + /// Client for the dashboard APIs + DashboardClient get dashboard => _dashboard[this] ??= DashboardClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/dav.dart b/packages/nextcloud/lib/dav.dart new file mode 100644 index 00000000..bb6ec898 --- /dev/null +++ b/packages/nextcloud/lib/dav.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/dav.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/dav.openapi.dart'; + +// ignore: public_member_api_docs +extension DavExtension on NextcloudClient { + static final _dav = Expando(); + + /// Client for the dav APIs + DavClient get dav => _dav[this] ??= DavClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/files.dart b/packages/nextcloud/lib/files.dart new file mode 100644 index 00000000..97b070db --- /dev/null +++ b/packages/nextcloud/lib/files.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/files.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/files.openapi.dart'; + +// ignore: public_member_api_docs +extension FilesExtension on NextcloudClient { + static final _files = Expando(); + + /// Client for the files APIs + FilesClient get files => _files[this] ??= FilesClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/files_external.dart b/packages/nextcloud/lib/files_external.dart new file mode 100644 index 00000000..86a33b72 --- /dev/null +++ b/packages/nextcloud/lib/files_external.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/files_external.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/files_external.openapi.dart'; + +// ignore: public_member_api_docs +extension FilesExternalExtension on NextcloudClient { + static final _filesExternal = Expando(); + + /// Client for the files_external APIs + FilesExternalClient get filesExternal => _filesExternal[this] ??= FilesExternalClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/files_reminders.dart b/packages/nextcloud/lib/files_reminders.dart new file mode 100644 index 00000000..41d1778c --- /dev/null +++ b/packages/nextcloud/lib/files_reminders.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/files_reminders.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/files_reminders.openapi.dart'; + +// ignore: public_member_api_docs +extension FilesRemindersExtension on NextcloudClient { + static final _filesReminders = Expando(); + + /// Client for the files_reminders APIs + FilesRemindersClient get filesReminders => _filesReminders[this] ??= FilesRemindersClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/files_sharing.dart b/packages/nextcloud/lib/files_sharing.dart new file mode 100644 index 00000000..b156e540 --- /dev/null +++ b/packages/nextcloud/lib/files_sharing.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/files_sharing.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/files_sharing.openapi.dart'; + +// ignore: public_member_api_docs +extension FilesSharingExtension on NextcloudClient { + static final _filesSharing = Expando(); + + /// Client for the files_sharing APIs + FilesSharingClient get filesSharing => _filesSharing[this] ??= FilesSharingClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/files_trashbin.dart b/packages/nextcloud/lib/files_trashbin.dart new file mode 100644 index 00000000..5b71e034 --- /dev/null +++ b/packages/nextcloud/lib/files_trashbin.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/files_trashbin.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/files_trashbin.openapi.dart'; + +// ignore: public_member_api_docs +extension FilesTrashbinExtension on NextcloudClient { + static final _filesTrashbin = Expando(); + + /// Client for the files_trashbin APIs + FilesTrashbinClient get filesTrashbin => _filesTrashbin[this] ??= FilesTrashbinClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/files_versions.dart b/packages/nextcloud/lib/files_versions.dart new file mode 100644 index 00000000..36d348d2 --- /dev/null +++ b/packages/nextcloud/lib/files_versions.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/files_versions.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/files_versions.openapi.dart'; + +// ignore: public_member_api_docs +extension FilesVersionsExtension on NextcloudClient { + static final _filesVersions = Expando(); + + /// Client for the files_versions APIs + FilesVersionsClient get filesVersions => _filesVersions[this] ??= FilesVersionsClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/ids.dart b/packages/nextcloud/lib/ids.dart new file mode 100644 index 00000000..1b44fe20 --- /dev/null +++ b/packages/nextcloud/lib/ids.dart @@ -0,0 +1,25 @@ +// ignore_for_file: public_member_api_docs + +final class AppIDs { + static const filesSharing = 'files_sharing'; + static const filesVersions = 'files_versions'; + static const files = 'files'; + static const updatenotification = 'updatenotification'; + static const dashboard = 'dashboard'; + static const uppush = 'uppush'; + static const settings = 'settings'; + static const dav = 'dav'; + static const userStatus = 'user_status'; + static const notifications = 'notifications'; + static const notes = 'notes'; + static const news = 'news'; + static const core = 'core'; + static const filesTrashbin = 'files_trashbin'; + static const comments = 'comments'; + static const sharebymail = 'sharebymail'; + static const filesExternal = 'files_external'; + static const filesReminders = 'files_reminders'; + static const provisioningApi = 'provisioning_api'; + static const theming = 'theming'; + static const weatherStatus = 'weather_status'; +} diff --git a/packages/nextcloud/lib/news.dart b/packages/nextcloud/lib/news.dart new file mode 100644 index 00000000..559519a7 --- /dev/null +++ b/packages/nextcloud/lib/news.dart @@ -0,0 +1,13 @@ +import 'package:nextcloud/src/api/news.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/news.openapi.dart'; +export 'src/helpers/news.dart'; + +// ignore: public_member_api_docs +extension NewsExtension on NextcloudClient { + static final _news = Expando(); + + /// Client for the news APIs + NewsClient get news => _news[this] ??= NewsClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/nextcloud.dart b/packages/nextcloud/lib/nextcloud.dart index 27cd9bef..aa7c9c1b 100644 --- a/packages/nextcloud/lib/nextcloud.dart +++ b/packages/nextcloud/lib/nextcloud.dart @@ -1,33 +1,27 @@ -export 'package:crypton/crypton.dart' show RSAKeypair, RSAPrivateKey, RSAPublicKey; +export 'package:dynamite_runtime/http_client.dart' + show CookieJar, DynamiteApiException, DynamiteRawResponse, DynamiteResponse; -export 'src/api/comments.openapi.dart'; -export 'src/api/core.openapi.dart'; -export 'src/api/dashboard.openapi.dart'; -export 'src/api/dav.openapi.dart'; -export 'src/api/files.openapi.dart'; -export 'src/api/files_external.openapi.dart'; -export 'src/api/files_reminders.openapi.dart'; -export 'src/api/files_sharing.openapi.dart'; -export 'src/api/files_trashbin.openapi.dart'; -export 'src/api/files_versions.openapi.dart'; -export 'src/api/news.openapi.dart'; -export 'src/api/notes.openapi.dart'; -export 'src/api/notifications.openapi.dart'; -export 'src/api/provisioning_api.openapi.dart'; -export 'src/api/settings.openapi.dart'; -export 'src/api/sharebymail.openapi.dart'; -export 'src/api/theming.openapi.dart'; -export 'src/api/updatenotification.openapi.dart'; -export 'src/api/uppush.openapi.dart'; -export 'src/api/user_status.openapi.dart'; -export 'src/api/weather_status.openapi.dart'; -export 'src/app_type.dart'; +export 'comments.dart'; +export 'core.dart'; +export 'dashboard.dart'; +export 'dav.dart'; +export 'files.dart'; +export 'files_external.dart'; +export 'files_reminders.dart'; +export 'files_sharing.dart'; +export 'files_trashbin.dart'; +export 'files_versions.dart'; +export 'ids.dart'; +export 'news.dart'; +export 'notes.dart'; +export 'notifications.dart'; +export 'provisioning_api.dart'; +export 'settings.dart'; +export 'sharebymail.dart'; export 'src/client.dart'; -export 'src/helpers/core.dart'; -export 'src/helpers/news.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'; -export 'src/webdav/webdav.dart'; +export 'theming.dart'; +export 'updatenotification.dart'; +export 'uppush.dart'; +export 'user_status.dart'; +export 'weather_status.dart'; +export 'webdav.dart'; diff --git a/packages/nextcloud/lib/notes.dart b/packages/nextcloud/lib/notes.dart new file mode 100644 index 00000000..1f2e447e --- /dev/null +++ b/packages/nextcloud/lib/notes.dart @@ -0,0 +1,13 @@ +import 'package:nextcloud/src/api/notes.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/notes.openapi.dart'; +export 'src/helpers/notes.dart'; + +// ignore: public_member_api_docs +extension NotesExtension on NextcloudClient { + static final _notes = Expando(); + + /// Client for the notes APIs + NotesClient get notes => _notes[this] ??= NotesClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/notifications.dart b/packages/nextcloud/lib/notifications.dart new file mode 100644 index 00000000..4b4d8145 --- /dev/null +++ b/packages/nextcloud/lib/notifications.dart @@ -0,0 +1,13 @@ +import 'package:nextcloud/src/api/notifications.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/notifications.openapi.dart'; +export 'src/helpers/notifications.dart'; + +// ignore: public_member_api_docs +extension NotificationsExtension on NextcloudClient { + static final _notifications = Expando(); + + /// Client for the notifications APIs + NotificationsClient get notifications => _notifications[this] ??= NotificationsClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/provisioning_api.dart b/packages/nextcloud/lib/provisioning_api.dart new file mode 100644 index 00000000..050f8d97 --- /dev/null +++ b/packages/nextcloud/lib/provisioning_api.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/provisioning_api.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/provisioning_api.openapi.dart'; + +// ignore: public_member_api_docs +extension ProvisioningApiExtension on NextcloudClient { + static final _provisioningApi = Expando(); + + /// Client for the provisioning_api APIs + ProvisioningApiClient get provisioningApi => _provisioningApi[this] ??= ProvisioningApiClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/settings.dart b/packages/nextcloud/lib/settings.dart new file mode 100644 index 00000000..cdd22878 --- /dev/null +++ b/packages/nextcloud/lib/settings.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/settings.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/settings.openapi.dart'; + +// ignore: public_member_api_docs +extension SettingsExtension on NextcloudClient { + static final _settings = Expando(); + + /// Client for the settings APIs + SettingsClient get settings => _settings[this] ??= SettingsClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/sharebymail.dart b/packages/nextcloud/lib/sharebymail.dart new file mode 100644 index 00000000..0a08a931 --- /dev/null +++ b/packages/nextcloud/lib/sharebymail.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/sharebymail.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/sharebymail.openapi.dart'; + +// ignore: public_member_api_docs +extension SharebymailExtension on NextcloudClient { + static final _sharebymail = Expando(); + + /// Client for the sharebymail APIs + SharebymailClient get sharebymail => _sharebymail[this] ??= SharebymailClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/src/app_type.dart b/packages/nextcloud/lib/src/app_type.dart deleted file mode 100644 index a71771da..00000000 --- a/packages/nextcloud/lib/src/app_type.dart +++ /dev/null @@ -1,18 +0,0 @@ -/// Different app types to register for -enum AppType { - /// Will only receive Talk notifications - talk('Mozilla/5.0 (Android) Nextcloud-Talk'), - - /// Will receive all notifications except Talk notifications if another Talk - /// app is already registered for the user - nextcloud('Mozilla/5.0 (Android) Nextcloud-android'), - - /// Default. Same problem with notifications as the [nextcloud] type - unknown(null); - - // ignore: public_member_api_docs - const AppType(this.userAgent); - - // ignore: public_member_api_docs - final String? userAgent; -} diff --git a/packages/nextcloud/lib/src/client.dart b/packages/nextcloud/lib/src/client.dart index c42c66ca..e8c47bd4 100644 --- a/packages/nextcloud/lib/src/client.dart +++ b/packages/nextcloud/lib/src/client.dart @@ -1,4 +1,23 @@ -import 'package:nextcloud/nextcloud.dart'; +import 'package:dynamite_runtime/http_client.dart'; + +/// Different app types to register for +enum AppType { + /// Will only receive Talk notifications + talk('Mozilla/5.0 (Android) Nextcloud-Talk'), + + /// Will receive all notifications except Talk notifications if another Talk + /// app is already registered for the user + nextcloud('Mozilla/5.0 (Android) Nextcloud-android'), + + /// Default. Same problem with notifications as the [nextcloud] type + unknown(null); + + // ignore: public_member_api_docs + const AppType(this.userAgent); + + // ignore: public_member_api_docs + final String? userAgent; +} // ignore: public_member_api_docs class NextcloudClient extends DynamiteClient { @@ -32,91 +51,4 @@ class NextcloudClient extends DynamiteClient { /// Identifier used for authentication. This can be the username or email or something else. final String? loginName; - - WebDavClient? _webdav; - CommentsClient? _comments; - CoreClient? _core; - DashboardClient? _dashboard; - DavClient? _dav; - FilesClient? _files; - FilesExternalClient? _filesExternal; - FilesRemindersClient? _filesReminders; - FilesSharingClient? _filesSharing; - FilesTrashbinClient? _filesTrashbin; - FilesVersionsClient? _filesVersions; - NewsClient? _news; - NotesClient? _notes; - NotificationsClient? _notifications; - ProvisioningApiClient? _provisioningApi; - SettingsClient? _settings; - ThemingClient? _theming; - UpdatenotificationClient? _updatenotification; - UppushClient? _uppush; - UserStatusClient? _userStatus; - WeatherStatusClient? _weatherStatus; - - /// Client for WebDAV - WebDavClient get webdav => _webdav ??= WebDavClient(this); - - /// Client for the comments APIs - CommentsClient get comments => _comments ??= CommentsClient.fromClient(this); - - /// Client for the core APIs - CoreClient get core => _core ??= CoreClient.fromClient(this); - - /// Client for the dashboard APIs - DashboardClient get dashboard => _dashboard ??= DashboardClient.fromClient(this); - - /// Client for the dav APIs - /// - /// This client does not expose WebDAV functionality. Use [webdav] instead. - DavClient get dav => _dav ??= DavClient.fromClient(this); - - /// Client for the files APIs - FilesClient get files => _files ??= FilesClient.fromClient(this); - - /// Client for the files external APIs - FilesExternalClient get filesExternal => _filesExternal ??= FilesExternalClient.fromClient(this); - - /// Client for the files reminders APIs - FilesRemindersClient get filesReminders => _filesReminders ??= FilesRemindersClient.fromClient(this); - - /// Client for the files sharing APIs - FilesSharingClient get filesSharing => _filesSharing ??= FilesSharingClient.fromClient(this); - - /// Client for the files trashbin APIs - FilesTrashbinClient get filesTrashbin => _filesTrashbin ??= FilesTrashbinClient.fromClient(this); - - /// Client for the files versions APIs - FilesVersionsClient get filesVersions => _filesVersions ??= FilesVersionsClient.fromClient(this); - - /// Client for the news app APIs - NewsClient get news => _news ??= NewsClient.fromClient(this); - - /// Client for the notes app APIs - NotesClient get notes => _notes ??= NotesClient.fromClient(this); - - /// Client for the notifications app APIs - NotificationsClient get notifications => _notifications ??= NotificationsClient.fromClient(this); - - /// Client for the provisioning APIs - ProvisioningApiClient get provisioningApi => _provisioningApi ??= ProvisioningApiClient.fromClient(this); - - /// Client for the settings APIs - SettingsClient get settings => _settings ??= SettingsClient.fromClient(this); - - /// Client for the theming APIs - ThemingClient get theming => _theming ??= ThemingClient.fromClient(this); - - /// Client for the updatenotification APIs - UpdatenotificationClient get updatenotification => _updatenotification ??= UpdatenotificationClient.fromClient(this); - - /// Client for the uppush app APIs - UppushClient get uppush => _uppush ??= UppushClient.fromClient(this); - - /// Client for the user status APIs - UserStatusClient get userStatus => _userStatus ??= UserStatusClient.fromClient(this); - - /// Client for the weather status APIs - WeatherStatusClient get weatherStatus => _weatherStatus ??= WeatherStatusClient.fromClient(this); } 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/helpers/notifications.dart b/packages/nextcloud/lib/src/helpers/notifications.dart index 821b68a2..a86f3aef 100644 --- a/packages/nextcloud/lib/src/helpers/notifications.dart +++ b/packages/nextcloud/lib/src/helpers/notifications.dart @@ -6,6 +6,8 @@ import 'package:crypto/crypto.dart'; import 'package:crypton/crypton.dart'; import 'package:json_annotation/json_annotation.dart'; +export 'package:crypton/crypton.dart' show RSAKeypair, RSAPrivateKey, RSAPublicKey; + part 'notifications.g.dart'; /// Generates the push token hash which is just sha512 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, - ); -} diff --git a/packages/nextcloud/lib/theming.dart b/packages/nextcloud/lib/theming.dart new file mode 100644 index 00000000..29bf633c --- /dev/null +++ b/packages/nextcloud/lib/theming.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/theming.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/theming.openapi.dart'; + +// ignore: public_member_api_docs +extension ThemingExtension on NextcloudClient { + static final _theming = Expando(); + + /// Client for the theming APIs + ThemingClient get theming => _theming[this] ??= ThemingClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/updatenotification.dart b/packages/nextcloud/lib/updatenotification.dart new file mode 100644 index 00000000..35c2db5b --- /dev/null +++ b/packages/nextcloud/lib/updatenotification.dart @@ -0,0 +1,13 @@ +import 'package:nextcloud/src/api/updatenotification.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/updatenotification.openapi.dart'; + +// ignore: public_member_api_docs +extension UpdatenotificationExtension on NextcloudClient { + static final _updatenotification = Expando(); + + /// Client for the updatenotification APIs + UpdatenotificationClient get updatenotification => + _updatenotification[this] ??= UpdatenotificationClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/uppush.dart b/packages/nextcloud/lib/uppush.dart new file mode 100644 index 00000000..afcbe078 --- /dev/null +++ b/packages/nextcloud/lib/uppush.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/uppush.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/uppush.openapi.dart'; + +// ignore: public_member_api_docs +extension UppushExtension on NextcloudClient { + static final _uppush = Expando(); + + /// Client for the uppush APIs + UppushClient get uppush => _uppush[this] ??= UppushClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/user_status.dart b/packages/nextcloud/lib/user_status.dart new file mode 100644 index 00000000..140c224c --- /dev/null +++ b/packages/nextcloud/lib/user_status.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/user_status.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/user_status.openapi.dart'; + +// ignore: public_member_api_docs +extension UserStatusExtension on NextcloudClient { + static final _userStatus = Expando(); + + /// Client for the user_status APIs + UserStatusClient get userStatus => _userStatus[this] ??= UserStatusClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/weather_status.dart b/packages/nextcloud/lib/weather_status.dart new file mode 100644 index 00000000..d1c7fb33 --- /dev/null +++ b/packages/nextcloud/lib/weather_status.dart @@ -0,0 +1,12 @@ +import 'package:nextcloud/src/api/weather_status.openapi.dart'; +import 'package:nextcloud/src/client.dart'; + +export 'src/api/weather_status.openapi.dart'; + +// ignore: public_member_api_docs +extension WeatherStatusExtension on NextcloudClient { + static final _weatherStatus = Expando(); + + /// Client for the weather_status APIs + WeatherStatusClient get weatherStatus => _weatherStatus[this] ??= WeatherStatusClient.fromClient(this); +} diff --git a/packages/nextcloud/lib/webdav.dart b/packages/nextcloud/lib/webdav.dart new file mode 100644 index 00000000..0ff111e6 --- /dev/null +++ b/packages/nextcloud/lib/webdav.dart @@ -0,0 +1,15 @@ +import 'package:nextcloud/src/client.dart'; +import 'package:nextcloud/src/webdav/client.dart'; + +export 'src/webdav/client.dart'; +export 'src/webdav/file.dart'; +export 'src/webdav/props.dart'; +export 'src/webdav/webdav.dart'; + +// ignore: public_member_api_docs +extension WebDAVExtension on NextcloudClient { + static final _webdav = Expando(); + + /// Client for WebDAV + WebDavClient get webdav => _webdav[this] ??= WebDavClient(this); +} diff --git a/packages/nextcloud/pubspec.yaml b/packages/nextcloud/pubspec.yaml index 624ac68b..7cebcfad 100644 --- a/packages/nextcloud/pubspec.yaml +++ b/packages/nextcloud/pubspec.yaml @@ -36,6 +36,7 @@ dev_dependencies: git: url: https://github.com/nextcloud/neon path: packages/neon_lints + path: ^1.8.3 process_run: ^0.13.1 test: ^1.24.6 xml_serializable: ^2.3.0 diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index df5d05aa..561fc1b5 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/packages/nextcloud/test/core_test.dart @@ -1,4 +1,4 @@ -import 'package:nextcloud/nextcloud.dart'; +import 'package:nextcloud/core.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/dashboard_test.dart b/packages/nextcloud/test/dashboard_test.dart index f529f82c..9dc244dd 100644 --- a/packages/nextcloud/test/dashboard_test.dart +++ b/packages/nextcloud/test/dashboard_test.dart @@ -1,3 +1,4 @@ +import 'package:nextcloud/dashboard.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index bac182e2..6db044a7 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:io'; -import 'package:nextcloud/nextcloud.dart'; +import 'package:nextcloud/news.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/notes_test.dart b/packages/nextcloud/test/notes_test.dart index c8f8b429..25f3fda9 100644 --- a/packages/nextcloud/test/notes_test.dart +++ b/packages/nextcloud/test/notes_test.dart @@ -1,4 +1,5 @@ -import 'package:nextcloud/nextcloud.dart'; +import 'package:nextcloud/core.dart'; +import 'package:nextcloud/notes.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/notifications_test.dart b/packages/nextcloud/test/notifications_test.dart index 4afc936f..f34cbb05 100644 --- a/packages/nextcloud/test/notifications_test.dart +++ b/packages/nextcloud/test/notifications_test.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:nextcloud/nextcloud.dart'; +import 'package:nextcloud/notifications.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/provisioning_api_test.dart b/packages/nextcloud/test/provisioning_api_test.dart index 0df22560..d830c6b2 100644 --- a/packages/nextcloud/test/provisioning_api_test.dart +++ b/packages/nextcloud/test/provisioning_api_test.dart @@ -1,3 +1,4 @@ +import 'package:nextcloud/provisioning_api.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/settings_test.dart b/packages/nextcloud/test/settings_test.dart index dd6036ab..29906645 100644 --- a/packages/nextcloud/test/settings_test.dart +++ b/packages/nextcloud/test/settings_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:nextcloud/settings.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/uppush_test.dart b/packages/nextcloud/test/uppush_test.dart index e521a5cc..dd93f61f 100644 --- a/packages/nextcloud/test/uppush_test.dart +++ b/packages/nextcloud/test/uppush_test.dart @@ -1,3 +1,4 @@ +import 'package:nextcloud/uppush.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/packages/nextcloud/test/user_status_test.dart b/packages/nextcloud/test/user_status_test.dart index 4d11ec88..4dc98350 100644 --- a/packages/nextcloud/test/user_status_test.dart +++ b/packages/nextcloud/test/user_status_test.dart @@ -1,4 +1,4 @@ -import 'package:nextcloud/nextcloud.dart'; +import 'package:nextcloud/user_status.dart'; import 'package:test/test.dart'; import 'helper.dart'; diff --git a/tool/generate-nextcloud.sh b/tool/generate-nextcloud.sh index feb2ab1a..40145abc 100755 --- a/tool/generate-nextcloud.sh +++ b/tool/generate-nextcloud.sh @@ -7,6 +7,7 @@ cd "$(dirname "$0")/.." rm -rf .dart_tool/build fvm dart run nextcloud:generate_props fvm dart pub run build_runner build --delete-conflicting-outputs + fvm dart run nextcloud:generate_exports # For some reason we need to fix and format twice, otherwise not everything gets fixed fvm dart fix --apply lib/src/api/ melos run format