commonMain.io.github.jan.supabase.imageloader.SupabaseStorageFetcher.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of imageloader-integration Show documentation
Show all versions of imageloader-integration Show documentation
Extends supabase-kt with a Compose-ImageLoader integration for easy image loading
package io.github.jan.supabase.imageloader
import com.seiko.imageloader.component.fetcher.FetchResult
import com.seiko.imageloader.component.fetcher.Fetcher
import com.seiko.imageloader.model.extraData
import io.github.jan.supabase.storage.Storage
import io.github.jan.supabase.storage.StorageItem
import io.ktor.http.ContentType
import io.ktor.http.defaultForFileExtension
import okio.Buffer
import kotlin.collections.set
internal class SupabaseStorageFetcher(
private val storage: Storage,
private val item: StorageItem
) : Fetcher {
override suspend fun fetch(): FetchResult {
val bucket = storage[item.bucketId]
val data = if (item.authenticated) {
bucket.downloadAuthenticated(item.path)
} else {
bucket.downloadPublic(item.path)
}
return FetchResult.OfSource(
source = Buffer().write(data),
extra = extraData {
this["KEY_MIME_TYPE"] =
ContentType.defaultForFileExtension(item.path.substringAfterLast(".")).toString()
}
)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy