mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-05 08:09:21 +00:00
rework of multipart files with fixes in new sticker sets
This commit is contained in:
@@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
||||
import dev.inmo.tgbotapi.types.message.content.MediaContent
|
||||
import io.ktor.util.cio.use
|
||||
import io.ktor.util.cio.writeChannel
|
||||
import io.ktor.utils.io.copyAndClose
|
||||
import io.ktor.utils.io.copyTo
|
||||
import kotlinx.coroutines.job
|
||||
import java.io.File
|
||||
@@ -25,7 +26,7 @@ suspend fun TelegramBot.downloadFile(
|
||||
doOutsideOfCoroutine { destFile.createNewFile() }
|
||||
|
||||
destFile.writeChannel(coroutineContext.job).use {
|
||||
readChannel.copyTo(this)
|
||||
readChannel.copyAndClose(this)
|
||||
}
|
||||
|
||||
return destFile
|
||||
|
@@ -30,11 +30,17 @@ suspend fun TelegramBot.downloadFileToTemp(
|
||||
|
||||
suspend fun TelegramBot.downloadFileToTemp(
|
||||
pathedFile: PathedFile
|
||||
) = downloadFileToTemp(
|
||||
): File = downloadFileToTemp(
|
||||
pathedFile.filePath
|
||||
).apply {
|
||||
runCatching {
|
||||
renameTo(File(parentFile, "$nameWithoutExtension.${pathedFile.fileName.fileExtension}"))
|
||||
).run {
|
||||
val newFile = File(parentFile, "$nameWithoutExtension.${pathedFile.fileName.fileExtension}")
|
||||
val success = runCatching {
|
||||
renameTo(newFile)
|
||||
}.getOrElse { false }
|
||||
if (success) {
|
||||
newFile
|
||||
} else {
|
||||
this@run
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user