From e85d833bad0fb8e427c30832169798973aa76c33 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 13 Jan 2025 20:30:46 -0600 Subject: [PATCH] When adding an artwork ebook URL, confirm that that ebook exists --- lib/Artwork.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Artwork.php b/lib/Artwork.php index 694f2f0a..feb0f961 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -496,11 +496,15 @@ class Artwork{ } // Check the ebook URL. - // We don't check if it exists, because the book might not be published yet. - // But we do a basic check that URL has the correct prefix and that it contains a slash between the author(s) and title. if($this->EbookUrl !== null){ - if(!preg_match('|^https://standardebooks.org/ebooks/[^/]+?/[^/]+?|ius', $this->EbookUrl)){ - $error->Add(new Exceptions\EbookNotFoundException('Invalid ebook URL. Check that it matches the URL in dc:identifier.')); + try{ + Ebook::GetByIdentifier('url:' . $this->EbookUrl); + + // Ebook found, continue. + } + catch(Exceptions\EbookNotFoundException){ + // Ebook not found, error! + $error->Add(new Exceptions\EbookNotFoundException('Couldn’t find an ebook with that URL.')); } }