diff --git a/.github/actions/validate-ae/action.yml b/.github/actions/validate-ae/action.yml index 9dacfe2f..a73b6b26 100644 --- a/.github/actions/validate-ae/action.yml +++ b/.github/actions/validate-ae/action.yml @@ -24,7 +24,7 @@ runs: working-directory: app run: | dart analyze lib - flutter test test/add_instance_flow_test.dart test/instance_serialization_test.dart + flutter test test/add_instance_flow_test.dart test/instance_serialization_test.dart test/bindery_brand_icon_test.dart - if: inputs.suite == 'all' || inputs.suite == 'bindery' shell: bash working-directory: packages/core_models @@ -32,4 +32,4 @@ runs: - if: inputs.suite == 'all' || inputs.suite == 'bindery' shell: bash working-directory: packages/core_networking - run: flutter test test/service_health_test.dart test/service_auth_headers_test.dart + run: flutter test test/service_health_test.dart test/service_auth_headers_test.dart test/bindery_key_test.dart diff --git a/.github/workflows/bindery-validate.yml b/.github/workflows/bindery-validate.yml new file mode 100644 index 00000000..7c7a157d --- /dev/null +++ b/.github/workflows/bindery-validate.yml @@ -0,0 +1,25 @@ +name: Validate Bindery foundation +on: + workflow_dispatch: + push: + branches: + - 'feature/bindery/**' +permissions: + contents: read +jobs: + validate: + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && !github.event.created && !github.event.deleted && !contains(github.event.head_commit.message, '[build apk]') && !contains(github.event.head_commit.message, '[validate ae]') && contains(github.event.head_commit.message, '[validate bindery]')) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v5 + - uses: subosito/flutter-action@v2 + with: + flutter-version: '3.41.9' + channel: stable + cache: true + - run: flutter pub get --enforce-lockfile + working-directory: app + - run: dart run tool/build_all.dart + - uses: ./.github/actions/validate-ae + with: + suite: bindery diff --git a/app/assets/service_icons/BINDERY-LICENSE.txt b/app/assets/service_icons/BINDERY-LICENSE.txt new file mode 100644 index 00000000..b03b388d --- /dev/null +++ b/app/assets/service_icons/BINDERY-LICENSE.txt @@ -0,0 +1,23 @@ +Bindery logo: https://github.com/vavallee/bindery/blob/v1.53.0/web/src/assets/logo.png + +MIT License + +Copyright (c) 2026 vavallee + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app/assets/service_icons/bindery.png b/app/assets/service_icons/bindery.png new file mode 100644 index 00000000..a0097e1a Binary files /dev/null and b/app/assets/service_icons/bindery.png differ diff --git a/app/lib/src/screens/bindery_foundation_screen.dart b/app/lib/src/screens/bindery_foundation_screen.dart new file mode 100644 index 00000000..9cf0a470 --- /dev/null +++ b/app/lib/src/screens/bindery_foundation_screen.dart @@ -0,0 +1,66 @@ +import 'package:core_models/core_models.dart'; +import 'package:core_networking/core_networking.dart'; +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../service_icon.dart'; + +final binderyVersionProvider = + FutureProvider.autoDispose.family((ref, instance) async { + final Dio dio = await ref.watch(dioFactoryProvider).create(instance); + try { + final response = await dio.get('api/v1/system/status'); + final data = response.data; + if (data is! Map || data['version'] is! String || + (data['version'] as String).isEmpty) { + throw const FormatException('Invalid Bindery status response'); + } + return data['version'] as String; + } finally { + dio.close(force: true); + } +}); + +class BinderyFoundationScreen extends ConsumerWidget { + const BinderyFoundationScreen({required this.instance, super.key}); + final Instance instance; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final version = ref.watch(binderyVersionProvider(instance)); + return ListView( + padding: const EdgeInsets.all(16), + children: [ + Card( + child: ListTile( + leading: const ServiceIcon(kind: ServiceKind.bindery), + title: const Text('Bindery server'), + subtitle: version.when( + skipLoadingOnRefresh: false, + data: (value) => Text('Connected • Version $value'), + loading: () => const Text('Connecting…'), + error: (_, __) => const Text('Unable to read server status'), + ), + trailing: IconButton( + tooltip: 'Refresh server status', + icon: version.isLoading + ? const SizedBox.square( + dimension: 20, + child: CircularProgressIndicator(strokeWidth: 2), + ) + : const Icon(Icons.refresh), + onPressed: version.isLoading + ? null + : () => ref.invalidate(binderyVersionProvider(instance)), + ), + ), + ), + const Padding( + padding: EdgeInsets.all(16), + child: Text('Library browsing and management are coming in later beta updates.'), + ), + ], + ); + } +} diff --git a/app/lib/src/screens/dashboard_screen.dart b/app/lib/src/screens/dashboard_screen.dart index d94d85e1..b3cd4693 100644 --- a/app/lib/src/screens/dashboard_screen.dart +++ b/app/lib/src/screens/dashboard_screen.dart @@ -12,6 +12,7 @@ import 'package:go_router/go_router.dart'; import '../dashboard/dashboard_board.dart'; import '../health_providers.dart'; +import '../service_icon.dart'; import 'reorder_sidebar_screen.dart'; /// Home screen. Services live in the navigation drawer (the sidebar); the @@ -502,6 +503,9 @@ class _HealthAwareTile extends ConsumerWidget { final Health health = asyncHealth.value ?? Health.unknown; return ServiceTile( instance: instance, + serviceIcon: instance.kind == ServiceKind.bindery + ? Center(child: ServiceIcon(kind: instance.kind)) + : null, health: health, onTap: () { final GoRouter router = GoRouter.of(context); diff --git a/app/lib/src/screens/service_detail_screen.dart b/app/lib/src/screens/service_detail_screen.dart index 7a969b96..4d1791c2 100644 --- a/app/lib/src/screens/service_detail_screen.dart +++ b/app/lib/src/screens/service_detail_screen.dart @@ -1,4 +1,5 @@ import 'package:core_models/core_models.dart'; +import 'bindery_foundation_screen.dart'; import 'package:core_profile/core_profile.dart'; import 'package:core_ui/core_ui.dart'; import 'package:flutter/material.dart'; @@ -416,6 +417,7 @@ class _ServiceDetailScreenState extends ConsumerState { ServiceKind.cleanuparr => const SizedBox.shrink(), // Owns its own scaffold, handled above. ServiceKind.slskd => const SizedBox.shrink(), + ServiceKind.bindery => BinderyFoundationScreen(instance: instance), }; } } diff --git a/app/test/bindery_brand_icon_test.dart b/app/test/bindery_brand_icon_test.dart new file mode 100644 index 00000000..bf8286c9 --- /dev/null +++ b/app/test/bindery_brand_icon_test.dart @@ -0,0 +1,18 @@ +import 'package:core_models/core_models.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +/// bindery has its own icon in the service picker. +/// +/// The picker loads `assets/service_icons/.png` and falls back to a +/// generic server icon when there is none. +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('the icon the picker asks for is bundled', () async { + final ByteData icon = await rootBundle + .load('assets/service_icons/${ServiceKind.bindery.name}.png'); + + expect(icon.lengthInBytes, greaterThan(0)); + }); +} diff --git a/packages/core_models/lib/src/service_kind.dart b/packages/core_models/lib/src/service_kind.dart index c91a41b9..24207b59 100644 --- a/packages/core_models/lib/src/service_kind.dart +++ b/packages/core_models/lib/src/service_kind.dart @@ -33,7 +33,8 @@ enum ServiceKind { adguardHome, aria2, cleanuparr, - slskd; + slskd, + bindery; /// All [ServiceKind] entries sorted alphabetically by their display name. static List get sortedValues => @@ -82,6 +83,7 @@ extension ServiceKindX on ServiceKind { ServiceKind.aria2 => 'aria2', ServiceKind.cleanuparr => 'Cleanuparr', ServiceKind.slskd => 'slskd', + ServiceKind.bindery => 'Bindery', }; /// One-line role description. @@ -116,6 +118,7 @@ extension ServiceKindX on ServiceKind { ServiceKind.aria2 => 'Download client', ServiceKind.cleanuparr => 'Malware blocker & cleaner', ServiceKind.slskd => 'Soulseek client', + ServiceKind.bindery => 'Books', }; /// Whether this service's integration is still in beta. Surfaced as a @@ -126,6 +129,7 @@ extension ServiceKindX on ServiceKind { ServiceKind.rtorrent || ServiceKind.aria2 || ServiceKind.cleanuparr || + ServiceKind.bindery || ServiceKind.slskd => true, _ => false, @@ -174,6 +178,7 @@ extension ServiceKindX on ServiceKind { ServiceKind.cleanuparr => 11011, // slskd default HTTP/API port. ServiceKind.slskd => 5030, + ServiceKind.bindery => 8787, }; /// What auth flow the service uses by default. Some services (Jellyfin) can @@ -192,6 +197,7 @@ extension ServiceKindX on ServiceKind { ServiceKind.gluetun || ServiceKind.myspeed || ServiceKind.cleanuparr || + ServiceKind.bindery || ServiceKind.ombi => AuthStyle.apiKey, // aria2's credential is its `--rpc-secret`, which is sent as the @@ -232,7 +238,8 @@ extension ServiceKindX on ServiceKind { ServiceKind.radarr || ServiceKind.prowlarr || ServiceKind.bazarr || - ServiceKind.lidarr => + ServiceKind.lidarr || + ServiceKind.bindery => ServiceRole.automation, ServiceKind.seerr || ServiceKind.ombi => ServiceRole.requests, ServiceKind.tautulli || ServiceKind.tracearr => ServiceRole.analytics, diff --git a/packages/core_models/test/service_kind_test.dart b/packages/core_models/test/service_kind_test.dart index 41b3be0b..1d172306 100644 --- a/packages/core_models/test/service_kind_test.dart +++ b/packages/core_models/test/service_kind_test.dart @@ -39,6 +39,7 @@ void main() { 'aria2', 'cleanuparr', 'slskd', + 'bindery', ], ); }); @@ -169,6 +170,15 @@ void main() { expect(ServiceKind.slskd.acceptsTorrents, isFalse); }); + test('Bindery is a beta API-key automation service', () { + expect(ServiceKind.bindery.displayName, 'Bindery'); + expect(ServiceKind.bindery.isBeta, isTrue); + expect(ServiceKind.bindery.defaultPort, 8787); + expect(ServiceKind.bindery.authStyle, AuthStyle.apiKey); + expect(ServiceKind.bindery.role, ServiceRole.automation); + expect(ServiceKind.bindery.acceptsTorrents, isFalse); + }); + test('existing services retain their default ports', () { expect(ServiceKind.sonarr.defaultPort, 8989); expect(ServiceKind.glances.defaultPort, 61208); diff --git a/packages/core_networking/lib/src/service_health.dart b/packages/core_networking/lib/src/service_health.dart index f1d7a5db..037ee5d2 100644 --- a/packages/core_networking/lib/src/service_health.dart +++ b/packages/core_networking/lib/src/service_health.dart @@ -40,6 +40,7 @@ enum _HealthMode { case ServiceKind.sonarr: case ServiceKind.radarr: return (path: 'api/v3/system/status', mode: _HealthMode.authed); + case ServiceKind.bindery: case ServiceKind.lidarr: case ServiceKind.prowlarr: return (path: 'api/v1/system/status', mode: _HealthMode.authed); @@ -253,6 +254,19 @@ class HealthProbe { ? await dio.get(path, options: options) : await dio.post(path, data: body, options: options); final int status = resp.statusCode ?? 0; + if (instance.kind == ServiceKind.bindery && connectionOnly && + interpretServiceHealthResponse(instance.kind, status, resp.data, + contentType: resp.headers.value(Headers.contentTypeHeader)) == Health.ok) { + // LAN bypass can accept an incorrect key. Compare against the + // admin auth configuration in memory; never log or store its key. + final config = await dio.get('api/v1/auth/config', + options: Options(validateStatus: (_) => true, + followRedirects: false, receiveTimeout: const Duration(seconds: 8))); + final auth = instance.auth; + return auth is InstanceAuthApiKey && config.statusCode == 200 && + binderyKeyMatches(auth.apiKey, config.data) + ? Health.ok : Health.warning; + } return interpretServiceHealthResponse( instance.kind, status, @@ -312,6 +326,11 @@ Health interpretServiceHealthResponse( switch (mode) { case _HealthMode.authed: if (status >= 200 && status < 300) { + if (kind == ServiceKind.bindery && + !(data is Map && data['version'] is String && + (data['version'] as String).isNotEmpty)) { + return Health.warning; + } if (kind == ServiceKind.speedtestTracker && !_isSpeedtestResultsEnvelope(data)) { // The host answered, but not with the authenticated API contract. @@ -437,3 +456,8 @@ bool _subsonicSaysOk(Object? data) { final Object? envelope = data['subsonic-response']; return envelope is Map && envelope['status'] == 'ok'; } + +/// Compare the configured key without exposing the server credential. +bool binderyKeyMatches(String supplied, Object? config) => + supplied.isNotEmpty && config is Map && config['apiKey'] is String && + config['apiKey'] == supplied; diff --git a/packages/core_networking/test/bindery_key_test.dart b/packages/core_networking/test/bindery_key_test.dart new file mode 100644 index 00000000..d15bb32d --- /dev/null +++ b/packages/core_networking/test/bindery_key_test.dart @@ -0,0 +1,12 @@ +import 'package:core_networking/src/service_health.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('Bindery key verification requires an exact nonempty match', () { + expect(binderyKeyMatches('test-key', {'apiKey': 'test-key'}), isTrue); + expect(binderyKeyMatches('hello', {'apiKey': 'test-key'}), isFalse); + expect(binderyKeyMatches('', {'apiKey': ''}), isFalse); + expect(binderyKeyMatches('test-key', {'mode': 'local_only'}), isFalse); + expect(binderyKeyMatches('test-key', null), isFalse); + }); +} diff --git a/packages/core_networking/test/service_health_test.dart b/packages/core_networking/test/service_health_test.dart index 2ca210bb..8faac2fe 100644 --- a/packages/core_networking/test/service_health_test.dart +++ b/packages/core_networking/test/service_health_test.dart @@ -3,6 +3,23 @@ import 'package:core_networking/core_networking.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + group('Bindery authenticated health', () { + test('version response is healthy', () { + expect(interpretServiceHealthResponse(ServiceKind.bindery, 200, + {'version': '1.53.0'}), Health.ok); + }); + test('refused credentials and invalid responses warn', () { + for (final int status in [401, 403, 404, 503]) { + expect(interpretServiceHealthResponse(ServiceKind.bindery, status, + null), Health.warning); + } + for (final Object? body in [null, '', {}]) { + expect(interpretServiceHealthResponse(ServiceKind.bindery, 200, + body), Health.warning); + } + }); + }); + group('aria2 JSON-RPC health', _aria2Tests); group('AdGuard Home anonymous health', _adguardHomeTests); group('proxy interception', _interceptionTests); diff --git a/packages/core_ui/lib/src/service_visuals.dart b/packages/core_ui/lib/src/service_visuals.dart index 257791c9..06d4ad85 100644 --- a/packages/core_ui/lib/src/service_visuals.dart +++ b/packages/core_ui/lib/src/service_visuals.dart @@ -38,6 +38,7 @@ abstract final class ServiceVisuals { ServiceKind.aria2 => Icons.download_for_offline_outlined, ServiceKind.cleanuparr => Icons.cleaning_services_outlined, ServiceKind.slskd => Icons.library_music_outlined, + ServiceKind.bindery => Icons.menu_book_outlined, }; static Color accent(ServiceKind kind) => switch (kind) { @@ -71,6 +72,7 @@ abstract final class ServiceVisuals { ServiceKind.aria2 => const Color(0xFF2F6FA8), ServiceKind.cleanuparr => const Color(0xFF7C3AED), ServiceKind.slskd => const Color(0xFF007ACC), + ServiceKind.bindery => const Color(0xFF8B7355), }; /// Human label for a [ServiceRole] section header. diff --git a/packages/core_ui/lib/src/widgets/service_tile.dart b/packages/core_ui/lib/src/widgets/service_tile.dart index e40cc00f..1b8a72d6 100644 --- a/packages/core_ui/lib/src/widgets/service_tile.dart +++ b/packages/core_ui/lib/src/widgets/service_tile.dart @@ -13,6 +13,7 @@ class ServiceTile extends StatelessWidget { required this.instance, this.health = Health.unknown, this.subtitle, + this.serviceIcon, this.onTap, this.onLongPress, super.key, @@ -20,6 +21,7 @@ class ServiceTile extends StatelessWidget { final Instance instance; final Health health; + final Widget? serviceIcon; /// Overrides the default subtitle (the service tagline) when provided - /// e.g., a queue count or "3 missing". @@ -39,7 +41,7 @@ class ServiceTile extends StatelessWidget { color: accent.withValues(alpha: 0.18), borderRadius: BorderRadius.circular(Radii.sm), ), - child: Icon(ServiceVisuals.icon(instance.kind), color: accent), + child: serviceIcon ?? Icon(ServiceVisuals.icon(instance.kind), color: accent), ), title: Row( children: [