Files
ComfyUI/composeApp/src/commonMain/kotlin/moe/uni/comfyKmp/data/CoverImageUtils.kt
T
anran e5a779e48a
CI / android (push) Failing after 2m14s
chore: move package
2026-01-31 02:51:56 +08:00

25 lines
677 B
Kotlin

package moe.uni.comfyKmp.data
import okio.FileSystem
import okio.Path.Companion.toPath
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
expect fun saveCoverImage(bytes: ByteArray, filenameHint: String): String
@OptIn(ExperimentalEncodingApi::class)
fun loadCoverImageBytes(coverImage: String): ByteArray? {
val cleaned = coverImage.removePrefix("file://")
val path = cleaned.toPath()
if (FileSystem.SYSTEM.exists(path)) {
return FileSystem.SYSTEM.read(path) {
readByteArray()
}
}
return try {
Base64.decode(coverImage)
} catch (_: IllegalArgumentException) {
null
}
}