Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Let you remove a book's cover and leave it with none

Barnabas3835da7fadae
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index f34ae37a..c7dfbe69 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -1610,6 +1610,10 @@
"asinLabel": "ASIN",
"isbnLabel": "ISBN",
"coverImage": "Cover Image",
+ "coverRemove": "Remove cover",
+ "coverRemoveConfirm": "Remove this book's cover? It will show the generated title card instead.",
+ "coverRemoved": "Cover removed",
+ "coverRemoveFailed": "Could not remove the cover",
"coverUrlLabel": "Cover URL",
"coverUrlHint": "https://...",
"localMetadata": "Local Metadata",
diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart
index 9a5db205..2002cc46 100644
--- a/lib/l10n/app_localizations.dart
+++ b/lib/l10n/app_localizations.dart
@@ -5950,6 +5950,30 @@ abstract class AppLocalizations {
/// **'Cover Image'**
String get coverImage;
+ /// No description provided for @coverRemove.
+ ///
+ /// In en, this message translates to:
+ /// **'Remove cover'**
+ String get coverRemove;
+
+ /// No description provided for @coverRemoveConfirm.
+ ///
+ /// In en, this message translates to:
+ /// **'Remove this book\'s cover? It will show the generated title card instead.'**
+ String get coverRemoveConfirm;
+
+ /// No description provided for @coverRemoved.
+ ///
+ /// In en, this message translates to:
+ /// **'Cover removed'**
+ String get coverRemoved;
+
+ /// No description provided for @coverRemoveFailed.
+ ///
+ /// In en, this message translates to:
+ /// **'Could not remove the cover'**
+ String get coverRemoveFailed;
+
/// No description provided for @coverUrlLabel.
///
/// In en, this message translates to:
diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart
index 7ebd310a..6c7f0dd0 100644
--- a/lib/l10n/app_localizations_de.dart
+++ b/lib/l10n/app_localizations_de.dart
@@ -3312,6 +3312,19 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get coverImage => 'Coverbild';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover-URL';
diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dart
index 40e57df3..7e9cc83b 100644
--- a/lib/l10n/app_localizations_el.dart
+++ b/lib/l10n/app_localizations_el.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsEl extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index cc8000d1..5c3d622a 100644
--- a/lib/l10n/app_localizations_en.dart
+++ b/lib/l10n/app_localizations_en.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart
index 2b3204f5..9af30a05 100644
--- a/lib/l10n/app_localizations_es.dart
+++ b/lib/l10n/app_localizations_es.dart
@@ -3265,6 +3265,19 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart
index e6aee2ca..9aa4d7a1 100644
--- a/lib/l10n/app_localizations_fr.dart
+++ b/lib/l10n/app_localizations_fr.dart
@@ -3310,6 +3310,19 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'URL de la couverture';
diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart
index 972983bb..a3003e7f 100644
--- a/lib/l10n/app_localizations_it.dart
+++ b/lib/l10n/app_localizations_it.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart
index c48b8029..80705f73 100644
--- a/lib/l10n/app_localizations_ja.dart
+++ b/lib/l10n/app_localizations_ja.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dart
index 75f87a04..f18e4418 100644
--- a/lib/l10n/app_localizations_no.dart
+++ b/lib/l10n/app_localizations_no.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsNo extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart
index 2046ef00..af0c15e4 100644
--- a/lib/l10n/app_localizations_pt.dart
+++ b/lib/l10n/app_localizations_pt.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dart
index 319b48df..c111806f 100644
--- a/lib/l10n/app_localizations_ro.dart
+++ b/lib/l10n/app_localizations_ro.dart
@@ -3263,6 +3263,19 @@ class AppLocalizationsRo extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart
index b8c199df..bbd53982 100644
--- a/lib/l10n/app_localizations_ru.dart
+++ b/lib/l10n/app_localizations_ru.dart
@@ -3267,6 +3267,19 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get coverImage => 'Cover Image';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => 'Cover URL';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index b18e1282..f5842258 100644
--- a/lib/l10n/app_localizations_zh.dart
+++ b/lib/l10n/app_localizations_zh.dart
@@ -3192,6 +3192,19 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get coverImage => '封面图片';
+ @override
+ String get coverRemove => 'Remove cover';
+
+ @override
+ String get coverRemoveConfirm =>
+ 'Remove this book\'s cover? It will show the generated title card instead.';
+
+ @override
+ String get coverRemoved => 'Cover removed';
+
+ @override
+ String get coverRemoveFailed => 'Could not remove the cover';
+
@override
String get coverUrlLabel => '封面 URL';
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index a23b3094..e409203d 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -3934,6 +3934,19 @@ class ApiService {
return false;
}
+ /// Remove a library item's cover, leaving it with none (admin only).
+ /// DELETE /api/items/:id/cover
+ Future<bool> removeItemCover(String itemId) async {
+ try {
+ final r = await _authDelete(
+ Uri.parse('$_cleanBaseUrl/api/items/$itemId/cover'),
+ timeout: const Duration(seconds: 30));
+ debugPrint('[API] removeItemCover $itemId -> ${r.statusCode}');
+ return r.statusCode == 200;
+ } catch (e) { debugPrint('removeItemCover error: $e'); }
+ return false;
+ }
+
/// Upload a cover image file for a library item (admin only)
Future<bool> uploadItemCover(String itemId, String filePath) async {
try {
diff --git a/lib/widgets/edit_metadata_sheet.dart b/lib/widgets/edit_metadata_sheet.dart
index f4bc6b23..c4c52207 100644
--- a/lib/widgets/edit_metadata_sheet.dart
+++ b/lib/widgets/edit_metadata_sheet.dart
@@ -660,6 +660,55 @@ class _MetadataEditViewState extends State<MetadataEditView>
}
}
+ /// Clear the cover entirely, so the book falls back to the generated
+ /// title card. Every other control here replaces one cover with another;
+ /// there was no way to end up with none.
+ Future<void> _removeCover() async {
+ final l = AppLocalizations.of(context)!;
+ final confirmed = await showDialog<bool>(
+ context: context,
+ builder: (ctx) => AlertDialog(
+ title: Text(l.coverRemove),
+ content: Text(l.coverRemoveConfirm),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.pop(ctx, false),
+ child: Text(l.cancel),
+ ),
+ FilledButton(
+ onPressed: () => Navigator.pop(ctx, true),
+ child: Text(l.remove),
+ ),
+ ],
+ ),
+ );
+ if (confirmed != true || !mounted) return;
+
+ final api = context.read<AuthProvider>().apiService;
+ if (api == null) return;
+ setState(() => _saving = true);
+ final ok = await api.removeItemCover(widget.itemId);
+ if (!mounted) return;
+ setState(() {
+ _saving = false;
+ if (ok) {
+ _coverVersion++;
+ _coverFilePath = null;
+ _coverUrlCtrl.clear();
+ }
+ });
+ if (ok) {
+ // The grid reads has-cover from the item payload, so refresh rather than
+ // leaving stale art behind on the shelves.
+ context.read<LibraryProvider>().refresh();
+ }
+ showOverlayToast(
+ context,
+ ok ? l.coverRemoved : l.coverRemoveFailed,
+ icon: ok ? Icons.check_circle_outline_rounded : Icons.error_outline_rounded,
+ );
+ }
+
String _safeString(dynamic value) {
if (value == null) return '';
if (value is String) return value;
@@ -1546,6 +1595,16 @@ class _MetadataEditViewState extends State<MetadataEditView>
),
),
),
+ if (base.isNotEmpty) ...[
+ const SizedBox(height: 8),
+ Center(
+ child: TextButton.icon(
+ onPressed: _saving ? null : _removeCover,
+ icon: Icon(Icons.hide_image_outlined, size: 18, color: cs.error),
+ label: Text(l.coverRemove, style: TextStyle(color: cs.error)),
+ ),
+ ),
+ ],
const SizedBox(height: 16),
Text(l.coverImage, style: tt.titleSmall?.copyWith(fontWeight: FontWeight.w600)),
const SizedBox(height: 8),