Fixed termination when a podcast updates its image url
This commit is contained in:
@@ -36,18 +36,18 @@ namespace lms::podcast
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
void removeArtwork(db::Session& session, const db::Artwork::pointer& artwork)
|
void removeArtwork(const db::Artwork::pointer& artwork)
|
||||||
{
|
{
|
||||||
const auto underlyingImageId{ artwork->getUnderlyingId() };
|
const auto underlyingImageId{ artwork->getUnderlyingId() };
|
||||||
const auto* imageId{ std::get_if<db::ImageId>(&underlyingImageId) };
|
db::Image::pointer image{ artwork->getImage() };
|
||||||
assert(imageId); // these artworks can only be an image
|
assert(image); // these artworks can only be an image
|
||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
std::filesystem::remove(artwork->getAbsoluteFilePath(), ec);
|
std::filesystem::remove(artwork->getAbsoluteFilePath(), ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
LMS_LOG(PODCAST, WARNING, "Failed to remove old podcast artwork file '" << artwork->getAbsoluteFilePath() << "': " << ec.message());
|
LMS_LOG(PODCAST, WARNING, "Failed to remove old podcast artwork file '" << artwork->getAbsoluteFilePath() << "': " << ec.message());
|
||||||
|
|
||||||
session.destroy<db::Image>(*imageId);
|
image.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePodcast(db::Session& session, db::PodcastId podcastId, const Podcast& podcast)
|
void updatePodcast(db::Session& session, db::PodcastId podcastId, const Podcast& podcast)
|
||||||
@@ -83,7 +83,7 @@ namespace lms::podcast
|
|||||||
{
|
{
|
||||||
LMS_LOG(PODCAST, INFO, "Podcast '" << podcast.title << "' : image url changed from '" << previousUrl << "' to '" << podcast.imageUrl << "'");
|
LMS_LOG(PODCAST, INFO, "Podcast '" << podcast.title << "' : image url changed from '" << previousUrl << "' to '" << podcast.imageUrl << "'");
|
||||||
if (db::Artwork::pointer currentArtwork{ dbPodcast->getArtwork() })
|
if (db::Artwork::pointer currentArtwork{ dbPodcast->getArtwork() })
|
||||||
removeArtwork(session, currentArtwork);
|
removeArtwork(currentArtwork);
|
||||||
|
|
||||||
dbPodcast.modify()->setImageUrl(podcast.imageUrl);
|
dbPodcast.modify()->setImageUrl(podcast.imageUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user