mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-09 02:10:10 +08:00
parent
0ebffb735d
commit
525830739c
mirai-core-api/src
commonMain/kotlin/utils/internal
jvmMain/kotlin/utils/internal
mirai-core/src/commonMain/kotlin/contact
@ -16,4 +16,5 @@ internal expect class DeferredReusableInput(input: Any, extraArg: Any?) : Reusab
|
||||
|
||||
|
||||
suspend fun init(strategy: FileCacheStrategy)
|
||||
|
||||
}
|
@ -23,4 +23,6 @@ internal interface ReusableInput {
|
||||
* Remember to close.
|
||||
*/
|
||||
fun asInput(): Input
|
||||
|
||||
fun release()
|
||||
}
|
@ -57,5 +57,9 @@ internal actual class DeferredReusableInput actual constructor(
|
||||
return delegate?.asInput() ?: error("DeferredReusableInput not yet initialized")
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
return delegate?.release() ?: error("DeferredReusableInput not yet initialized")
|
||||
}
|
||||
|
||||
actual val initialized: Boolean get() = delegate != null
|
||||
}
|
@ -51,6 +51,10 @@ internal actual fun ByteArray.asReusableInput(): ReusableInput {
|
||||
override fun asInput(): Input {
|
||||
return ByteArrayInputStream(this@asReusableInput).asInput()
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +73,6 @@ internal fun File.asReusableInput(deleteOnClose: Boolean): ReusableInput {
|
||||
|
||||
override fun close() {
|
||||
stream.close()
|
||||
if (deleteOnClose) this@asReusableInput.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,6 +84,11 @@ internal fun File.asReusableInput(deleteOnClose: Boolean): ReusableInput {
|
||||
override fun asInput(): Input {
|
||||
return inputStream().asInput()
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
if (deleteOnClose) this@asReusableInput.delete()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +107,6 @@ internal fun File.asReusableInput(deleteOnClose: Boolean, md5: ByteArray): Reusa
|
||||
|
||||
override fun close() {
|
||||
stream.close()
|
||||
if (deleteOnClose) this@asReusableInput.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,6 +118,10 @@ internal fun File.asReusableInput(deleteOnClose: Boolean, md5: ByteArray): Reusa
|
||||
override fun asInput(): Input {
|
||||
return inputStream().asInput()
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
if (deleteOnClose) this@asReusableInput.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import kotlinx.atomicfu.AtomicInt
|
||||
import kotlinx.atomicfu.atomic
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.io.core.Closeable
|
||||
import net.mamoe.mirai.LowLevelApi
|
||||
import net.mamoe.mirai.contact.Friend
|
||||
import net.mamoe.mirai.data.FriendInfo
|
||||
@ -110,8 +109,8 @@ internal class FriendImpl(
|
||||
}
|
||||
|
||||
@JvmSynthetic
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
override suspend fun uploadImage(image: ExternalImage): Image = try {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
if (image.input is net.mamoe.mirai.utils.internal.DeferredReusableInput) {
|
||||
image.input.init(bot.configuration.fileCacheStrategy)
|
||||
}
|
||||
@ -178,7 +177,6 @@ internal class FriendImpl(
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
(image.input as? Closeable)?.close()
|
||||
image.input.release()
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ package net.mamoe.mirai.internal.contact
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.io.core.Closeable
|
||||
import net.mamoe.mirai.LowLevelApi
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.contact.*
|
||||
@ -403,11 +402,10 @@ internal class GroupImpl(
|
||||
return result.getOrThrow()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Suppress("DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@OptIn(ExperimentalTime::class)
|
||||
@JvmSynthetic
|
||||
override suspend fun uploadImage(image: ExternalImage): Image = try {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
if (image.input is net.mamoe.mirai.utils.internal.DeferredReusableInput) {
|
||||
image.input.init(bot.configuration.fileCacheStrategy)
|
||||
}
|
||||
@ -451,7 +449,7 @@ internal class GroupImpl(
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
(image.input as? Closeable)?.close()
|
||||
image.input.release()
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user