-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for image cache downloading without image Feature #460
Conversation
…es enable_cover_image_cache app.toml option instead
spotify_player/src/client/mod.rs
Outdated
if configs.app_config.enable_cover_image_cache{ | ||
if !state.data.read().caches.images.contains_key(url) { | ||
let bytes = self | ||
.retrieve_image(url, &path, configs.app_config.enable_cover_image_cache) | ||
.await?; | ||
let image = | ||
image::load_from_memory(&bytes).context("Failed to load image from memory")?; | ||
state | ||
.data | ||
.write() | ||
.caches | ||
.images | ||
.insert(url.to_owned(), image, *TTL_CACHE_DURATION); | ||
} | ||
} | ||
|
||
|
||
#[cfg(any(feature = "image", feature = "notify"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can keep MemoryCaches
and image
feature optional by updating the logic to retrieve and save image separately if the image cache is enabled
if configs.app_config.enable_cover_image_cache{ | |
if !state.data.read().caches.images.contains_key(url) { | |
let bytes = self | |
.retrieve_image(url, &path, configs.app_config.enable_cover_image_cache) | |
.await?; | |
let image = | |
image::load_from_memory(&bytes).context("Failed to load image from memory")?; | |
state | |
.data | |
.write() | |
.caches | |
.images | |
.insert(url.to_owned(), image, *TTL_CACHE_DURATION); | |
} | |
} | |
#[cfg(any(feature = "image", feature = "notify"))] | |
if configs.app_config.enable_cover_image_cache{ | |
self | |
.retrieve_image(url, &path, true) | |
.await?; | |
} | |
#[cfg(feature = "image")] | |
if !state.data.read().caches.images.contains_key(url) { | |
let bytes = self | |
.retrieve_image(url, &path, false) | |
.await?; | |
let image = | |
image::load_from_memory(&bytes).context("Failed to load image from memory")?; | |
state | |
.data | |
.write() | |
.caches | |
.images | |
.insert(url.to_owned(), image, *TTL_CACHE_DURATION); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah, that makes sense; I don't know why I was trying to avoid adding that extra code block. I'll add those checks back in and recommit. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the suggested changes and removed the loose Feature check since it was no longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you undo the change in Cargo.toml
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh whoops, absolutely. Re-pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change. I did some extra cleanup myself, which is also relevant to this PR
Resolves #458
Image cache download is now solely based upon the
enable_cover_image_cache
option regardless if theimage
feature is used or not.