Adjusted logs

This commit is contained in:
emeric
2025-09-13 18:14:55 +02:00
parent 90fc3fc04b
commit f786b8b705
3 changed files with 56 additions and 49 deletions
@@ -112,15 +112,16 @@ namespace lms::podcast
const std::string url{ episode->getImageUrl() }; const std::string url{ episode->getImageUrl() };
const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() }; const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() };
LMS_LOG(PODCAST, DEBUG, "Downloading episode artwork for episode '" << episode->getTitle() << "' from '" << url << "' in file '" << finalFilePath << "'");
core::http::ClientGETRequestParameters params; core::http::ClientGETRequestParameters params;
params.relativeUrl = episode->getImageUrl(); params.relativeUrl = episode->getImageUrl();
params.onFailureFunc = [this, episode] { params.onFailureFunc = [=, this] {
LMS_LOG(PODCAST, ERROR, "Failed to download episode image from '" << episode->getImageUrl() << "'"); LMS_LOG(PODCAST, ERROR, "Failed to download episode artwork for episode '" << episode->getTitle() << "' from '" << url << "'");
processNext(); processNext();
}; };
params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) { params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) {
const std::string body{ msg.body() }; // API enforces a copy here getExecutor().post([=, this] {
std::ofstream file{ finalFilePath, std::ios::binary | std::ios::trunc }; std::ofstream file{ finalFilePath, std::ios::binary | std::ios::trunc };
if (!file) if (!file)
{ {
@@ -130,6 +131,7 @@ namespace lms::podcast
return; return;
} }
const std::string body{ msg.body() }; // API enforces a copy here
file.write(body.data(), body.size()); file.write(body.data(), body.size());
if (!file) if (!file)
{ {
@@ -139,11 +141,12 @@ namespace lms::podcast
return; return;
} }
LMS_LOG(PODCAST, INFO, "Downloaded episode artwork for episode '" << episode->getTitle() << "'");
const std::string* contentType{ msg.getHeader("Content-Type") }; const std::string* contentType{ msg.getHeader("Content-Type") };
LMS_LOG(PODCAST, INFO, "Downloaded episode artwork for episode '" << episode->getTitle() << "' to " << finalFilePath << " with content type '" << (contentType ? *contentType : "unknown") << "', size = " << body.size() << " bytes");
createEpisodeArtwork(getDb().getTLSSession(), episodeId, finalFilePath, contentType ? *contentType : "application/octet-stream"); createEpisodeArtwork(getDb().getTLSSession(), episodeId, finalFilePath, contentType ? *contentType : "application/octet-stream");
processNext(); processNext();
});
}; };
params.onAbortFunc = [this] { params.onAbortFunc = [this] {
onAbort(); onAbort();
@@ -182,7 +182,7 @@ namespace lms::podcast
// TODO: now the file is complete, should we attempt to read it and get the real information like duration and size? // TODO: now the file is complete, should we attempt to read it and get the real information like duration and size?
LMS_LOG(PODCAST, INFO, "Successfully downloaded episode '" << episode->getTitle() << "'"); LMS_LOG(PODCAST, INFO, "Downloaded episode '" << episode->getTitle() << "'");
processNext(); processNext();
}); });
}; };
@@ -111,6 +111,8 @@ namespace lms::podcast
const std::string url{ podcast->getImageUrl() }; const std::string url{ podcast->getImageUrl() };
const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() }; const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() };
LMS_LOG(PODCAST, DEBUG, "Downloading podcast artwork '" << podcast->getTitle() << "' from '" << url << "' in file '" << finalFilePath << "'");
core::http::ClientGETRequestParameters params; core::http::ClientGETRequestParameters params;
params.relativeUrl = podcast->getImageUrl(); params.relativeUrl = podcast->getImageUrl();
params.onFailureFunc = [this, podcast] { params.onFailureFunc = [this, podcast] {
@@ -118,6 +120,7 @@ namespace lms::podcast
processNext(); processNext();
}; };
params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) { params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) {
getExecutor().post([=, this] {
const std::string body{ msg.body() }; // API enforces a copy here const std::string body{ msg.body() }; // API enforces a copy here
std::ofstream file{ finalFilePath, std::ios::binary | std::ios::app }; std::ofstream file{ finalFilePath, std::ios::binary | std::ios::app };
@@ -138,11 +141,12 @@ namespace lms::podcast
return; return;
} }
LMS_LOG(PODCAST, INFO, "Downloaded podcast artwork for podcast '" << podcast->getTitle());
const std::string* contentType{ msg.getHeader("Content-Type") }; const std::string* contentType{ msg.getHeader("Content-Type") };
LMS_LOG(PODCAST, INFO, "Downloaded podcast artwork for podcast '" << podcast->getTitle() << "' to " << finalFilePath << " with content type '" << (contentType ? *contentType : "unknown") << "', size = " << body.size());
createPodcastArtwork(getDb().getTLSSession(), podcastId, finalFilePath, contentType ? *contentType : "application/octet-stream"); createPodcastArtwork(getDb().getTLSSession(), podcastId, finalFilePath, contentType ? *contentType : "application/octet-stream");
processNext(); processNext();
});
}; };
params.onAbortFunc = [this] { params.onAbortFunc = [this] {
onAbort(); onAbort();