Use Picasso stableKey for better caching against pre-signed URLs

This commit is contained in:
Ryan Harg 2022-12-08 13:29:34 +00:00
parent 708daa8464
commit 566dca1518
5 changed files with 9 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.databinding.RowPlaylistBinding
import audio.funkwhale.ffa.fragments.FFAAdapter
import audio.funkwhale.ffa.model.Playlist
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.toDurationString
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
@ -80,7 +81,7 @@ class PlaylistsAdapter(
}
Picasso.get()
.load(url)
.maybeLoad(url)
.transform(RoundedCornersTransformation(32, 0, corner))
.into(imageView)
}

View File

@ -15,6 +15,7 @@ import audio.funkwhale.ffa.R
import audio.funkwhale.ffa.activities.MainActivity
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.AppContext
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import com.squareup.picasso.Picasso
import kotlinx.coroutines.CoroutineScope
@ -68,7 +69,7 @@ class MediaControlsManager(
.run {
coverUrl?.let {
try {
setLargeIcon(Picasso.get().load(coverUrl).get())
setLargeIcon(Picasso.get().maybeLoad(coverUrl).get())
} catch (_: Exception) {
}

View File

@ -28,6 +28,7 @@ import audio.funkwhale.ffa.utils.Request
import audio.funkwhale.ffa.utils.RequestBus
import audio.funkwhale.ffa.utils.Response
import audio.funkwhale.ffa.utils.log
import audio.funkwhale.ffa.utils.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.onApi
import com.google.android.exoplayer2.C
@ -376,7 +377,7 @@ class PlayerService : Service() {
runBlocking(IO) {
this@apply.putBitmap(
MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
Picasso.get().load(coverUrl).get()
Picasso.get().maybeLoad(coverUrl).get()
)
}
} catch (e: Exception) {

View File

@ -62,6 +62,8 @@ fun <T, U> Int.onApi(block: () -> T, elseBlock: (() -> U)) {
fun Picasso.maybeLoad(url: String?): RequestCreator {
return if (url == null) load(R.drawable.cover)
else load(url)
// Remote storage may have (pre-signed) ephemeral credentials in the query string
.stableKey(url.replace(Regex("\\?.*$"), ""))
}
fun Request.authorize(context: Context, oAuth: OAuth): Request {

View File

@ -0,0 +1 @@
Use Picasso stableKey for better caching against pre-signed URLs (thanks @rickosborne)