Fix copyTo

This commit is contained in:
Him188 2020-02-28 22:02:34 +08:00
parent da8a78af12
commit 01ff846929
5 changed files with 37 additions and 34 deletions

View File

@ -118,16 +118,17 @@ internal class QQImpl(
} }
is LongConn.OffPicUp.Response.RequireUpload -> { is LongConn.OffPicUp.Response.RequireUpload -> {
Http.postImage("0x6ff0070", bot.uin, null, imageInput = image.input, inputSize = image.inputSize, uKeyHex = response.uKey.toUHexString("")) Http.postImage("0x6ff0070", bot.uin, null, imageInput = image.input, inputSize = image.inputSize, uKeyHex = response.uKey.toUHexString(""))
// HighwayHelper.uploadImage( //HighwayHelper.uploadImage(
// client = bot.client, // client = bot.client,
// serverIp = response.serverIp[0].toIpV4AddressString(), // serverIp = response.serverIp[0].toIpV4AddressString(),
// serverPort = response.serverPort[0], // serverPort = response.serverPort[0],
// imageInput = image.input, // imageInput = image.input,
// inputSize = image.inputSize.toInt(), // inputSize = image.inputSize.toInt(),
// md5 = image.md5, // fileMd5 = image.md5,
// uKey = response.uKey, // uKey = response.uKey,
// commandId = 1 // commandId = 1
// ) //)
// 为什么不能 ??
return NotOnlineImageFromFile( return NotOnlineImageFromFile(
filepath = response.resourceId, filepath = response.resourceId,

View File

@ -112,7 +112,7 @@ internal open class QQAndroidClient(
private val highwayDataTransSequenceIdForGroup: AtomicInt = atomic(87017) private val highwayDataTransSequenceIdForGroup: AtomicInt = atomic(87017)
internal fun nextHighwayDataTransSequenceIdForGroup(): Int = highwayDataTransSequenceIdForGroup.getAndAdd(2) internal fun nextHighwayDataTransSequenceIdForGroup(): Int = highwayDataTransSequenceIdForGroup.getAndAdd(2)
private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(40717) private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(43973)
internal fun nextHighwayDataTransSequenceIdForFriend(): Int = highwayDataTransSequenceIdForFriend.getAndAdd(2) internal fun nextHighwayDataTransSequenceIdForFriend(): Int = highwayDataTransSequenceIdForFriend.getAndAdd(2)
val appClientVersion: Int = 0 val appClientVersion: Int = 0

View File

@ -72,15 +72,17 @@ internal suspend fun HttpClient.postImage(
when (imageInput) { when (imageInput) {
is Input -> { is Input -> {
var size: Int var size: Int
while (imageInput.readAvailable(buffer).also { size = it } != 0) { while (imageInput.readAvailable(buffer).also { size = it } > 0) {
channel.writeFully(buffer, 0, size) channel.writeFully(buffer, 0, size)
channel.flush()
} }
} }
is ByteReadChannel -> imageInput.copyAndClose(channel) is ByteReadChannel -> imageInput.copyAndClose(channel)
is InputStream -> { is InputStream -> {
var size: Int var size: Int
while (imageInput.read(buffer).also { size = it } != 0) { while (imageInput.read(buffer).also { size = it } > 0) {
channel.writeFully(buffer, 0, size) channel.writeFully(buffer, 0, size)
channel.flush()
} }
} }
else -> error("unsupported imageInput: ${imageInput::class.simpleName}") else -> error("unsupported imageInput: ${imageInput::class.simpleName}")

View File

@ -69,7 +69,7 @@ internal fun createImageDataPacketSequence( // RequestDataTrans
localeId = localId localeId = localId
), ),
msgSeghead = CSDataHighwayHead.SegHead( msgSeghead = CSDataHighwayHead.SegHead(
cacheAddr = 812157193, // cacheAddr = 812157193,
datalength = chunkedInput.bufferSize, datalength = chunkedInput.bufferSize,
dataoffset = offset, dataoffset = offset,
filesize = dataSize.toLong(), filesize = dataSize.toLong(),

View File

@ -30,11 +30,11 @@ import kotlin.jvm.JvmName
*/ */
suspend fun ByteReadChannel.copyTo(dst: OutputStream) { suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance { ByteArrayPool.useInstance { buffer ->
do { var size: Int
val size = this.readAvailable(it) while (this.readAvailable(buffer).also { size = it } > 0) {
dst.write(it, 0, size) dst.write(buffer, 0, size)
} while (size != 0) }
} }
} }
@ -43,11 +43,11 @@ suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
*/ */
suspend fun ByteReadChannel.copyTo(dst: Output) { suspend fun ByteReadChannel.copyTo(dst: Output) {
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance { ByteArrayPool.useInstance { buffer ->
do { var size: Int
val size = this.readAvailable(it) while (this.readAvailable(buffer).also { size = it } > 0) {
dst.writeFully(it, 0, size) dst.writeFully(buffer, 0, size)
} while (size != 0) }
} }
} }
@ -75,11 +75,11 @@ suspend fun ByteReadChannel.copyTo(dst: kotlinx.coroutines.io.ByteWriteChannel)
suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) { suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) {
try { try {
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance { ByteArrayPool.useInstance { buffer ->
do { var size: Int
val size = this.readAvailable(it) while (this.readAvailable(buffer).also { size = it } > 0) {
dst.write(it, 0, size) dst.write(buffer, 0, size)
} while (size != 0) }
} }
} finally { } finally {
dst.close() dst.close()
@ -92,11 +92,11 @@ suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) {
suspend fun ByteReadChannel.copyAndClose(dst: Output) { suspend fun ByteReadChannel.copyAndClose(dst: Output) {
try { try {
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
ByteArrayPool.useInstance { ByteArrayPool.useInstance { buffer ->
do { var size: Int
val size = this.readAvailable(it) while (this.readAvailable(buffer).also { size = it } > 0) {
dst.writeFully(it, 0, size) dst.writeFully(buffer, 0, size)
} while (size != 0) }
} }
} finally { } finally {
dst.close() dst.close()