|
|
@@ -23,6 +23,7 @@ import net.mamoe.mirai.message.MessageReceipt
|
|
|
import net.mamoe.mirai.message.data.Image
|
|
|
import net.mamoe.mirai.message.data.sendTo
|
|
|
import net.mamoe.mirai.message.data.toLongUnsigned
|
|
|
+import net.mamoe.mirai.utils.internal.asReusableInput
|
|
|
import kotlin.jvm.JvmSynthetic
|
|
|
|
|
|
/**
|
|
|
@@ -33,37 +34,43 @@ import kotlin.jvm.JvmSynthetic
|
|
|
* @see ExternalImage.sendTo 上传图片并以纯图片消息发送给联系人
|
|
|
* @See ExternalImage.upload 上传图片并得到 [Image] 消息
|
|
|
*/
|
|
|
-class ExternalImage private constructor(
|
|
|
+@OptIn(MiraiInternalAPI::class)
|
|
|
+class ExternalImage internal constructor(
|
|
|
val md5: ByteArray,
|
|
|
- val input: Any, // Input from kotlinx.io, InputStream from kotlinx.io MPP, ByteReadChannel from ktor
|
|
|
- val inputSize: Long // dont be greater than Int.MAX
|
|
|
+ @Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR")
|
|
|
+ @MiraiInternalAPI("unstable API")
|
|
|
+ val input: ReusableInput, // Input from kotlinx.io, InputStream from kotlinx.io MPP, ByteReadChannel from ktor
|
|
|
+ @MiraiInternalAPI("unstable API")
|
|
|
+ val inputSize: Int // dont be greater than Int.MAX
|
|
|
) {
|
|
|
- @Deprecated("changing soon in 1.0.0", level = DeprecationLevel.ERROR)
|
|
|
+ @SinceMirai("1.0.0")
|
|
|
+ internal interface ReusableInput {
|
|
|
+ fun input(): Input
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
constructor(
|
|
|
md5: ByteArray,
|
|
|
input: ByteReadChannel,
|
|
|
inputSize: Long // dont be greater than Int.MAX
|
|
|
- ) : this(md5, input as Any, inputSize)
|
|
|
+ ) : this(md5, input.asReusableInput(), inputSize.coerceAtMost(Int.MAX_VALUE.toLongUnsigned()).toInt())
|
|
|
|
|
|
- @Deprecated("changing soon in 1.0.0", level = DeprecationLevel.ERROR)
|
|
|
constructor(
|
|
|
md5: ByteArray,
|
|
|
input: Input,
|
|
|
inputSize: Long // dont be greater than Int.MAX
|
|
|
- ) : this(md5, input as Any, inputSize)
|
|
|
+ ) : this(md5, input.asReusableInput(), inputSize.coerceAtMost(Int.MAX_VALUE.toLongUnsigned()).toInt())
|
|
|
|
|
|
- @Deprecated("changing soon in 1.0.0", level = DeprecationLevel.ERROR)
|
|
|
constructor(
|
|
|
md5: ByteArray,
|
|
|
input: ByteReadPacket
|
|
|
- ) : this(md5, input as Any, input.remaining)
|
|
|
+ ) : this(md5, input.asReusableInput(), input.remaining.coerceAtMost(Int.MAX_VALUE.toLongUnsigned()).toInt())
|
|
|
|
|
|
- @Deprecated("changing soon in 1.0.0", level = DeprecationLevel.ERROR)
|
|
|
@OptIn(InternalSerializationApi::class)
|
|
|
constructor(
|
|
|
md5: ByteArray,
|
|
|
input: InputStream
|
|
|
- ) : this(md5, input as Any, input.available().toLongUnsigned())
|
|
|
+ ) : this(md5, input.asReusableInput(), input.available())
|
|
|
|
|
|
init {
|
|
|
require(inputSize < 30L * 1024 * 1024) { "file is too big. Maximum is about 20MB" }
|