mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 12:08:43 +00:00
Compare commits
No commits in common. "a404a6c59cc31a3d8c02e46a0d0000fca61a1cbc" and "81ad55b19f9b5db9a6ef63ea3ef1d3b0e9842c1f" have entirely different histories.
a404a6c59c
...
81ad55b19f
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
* Fixes in `mention` creation
|
* Fixes in `mention` creation
|
||||||
* Deprecate `StorageFileInfo`
|
|
||||||
|
|
||||||
## 0.38.12
|
## 0.38.12
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.bot.Ktor.base
|
package dev.inmo.tgbotapi.bot.Ktor.base
|
||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.*
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
|
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
|
||||||
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
@ -25,16 +25,13 @@ object DownloadFileChannelRequestCallFactory : KtorCallFactory {
|
|||||||
val fullUrl = urlsKeeper.createFileLinkUrl(it.filePath)
|
val fullUrl = urlsKeeper.createFileLinkUrl(it.filePath)
|
||||||
|
|
||||||
ByteReadChannelAllocator {
|
ByteReadChannelAllocator {
|
||||||
val scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())
|
val scope = CoroutineScope(coroutineContext)
|
||||||
val outChannel = ByteChannel()
|
val outChannel = ByteChannel()
|
||||||
scope.launch {
|
scope.launchSafelyWithoutExceptions {
|
||||||
runCatchingSafely {
|
client.get<HttpStatement>(fullUrl).execute { httpResponse ->
|
||||||
client.get<HttpStatement>(fullUrl).execute { httpResponse ->
|
val channel: ByteReadChannel = httpResponse.receive()
|
||||||
val channel: ByteReadChannel = httpResponse.receive()
|
channel.copyAndClose(outChannel)
|
||||||
channel.copyAndClose(outChannel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
scope.cancel()
|
|
||||||
}
|
}
|
||||||
outChannel
|
outChannel
|
||||||
} as T
|
} as T
|
||||||
|
@ -61,9 +61,9 @@ object InputFileSerializer : KSerializer<InputFile> {
|
|||||||
@Serializable(InputFileSerializer::class)
|
@Serializable(InputFileSerializer::class)
|
||||||
data class MultipartFile (
|
data class MultipartFile (
|
||||||
val file: StorageFile,
|
val file: StorageFile,
|
||||||
val filename: String = file.fileName
|
val filename: String = file.storageFileInfo.fileName
|
||||||
) : InputFile() {
|
) : InputFile() {
|
||||||
override val fileId: String = file.generateCustomName()
|
override val fileId: String = file.storageFileInfo.generateCustomName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.utils
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
import com.benasher44.uuid.uuid4
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
import dev.inmo.micro_utils.common.filename
|
|
||||||
import io.ktor.utils.io.*
|
import io.ktor.utils.io.*
|
||||||
import io.ktor.utils.io.core.ByteReadPacket
|
import io.ktor.utils.io.core.ByteReadPacket
|
||||||
import io.ktor.utils.io.core.Input
|
import io.ktor.utils.io.core.Input
|
||||||
@ -15,7 +13,6 @@ import kotlinx.serialization.Serializable
|
|||||||
* @param fileName This filename will be used in telegram system as name of file
|
* @param fileName This filename will be used in telegram system as name of file
|
||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
@Deprecated("Will be removed soon")
|
|
||||||
data class StorageFileInfo(
|
data class StorageFileInfo(
|
||||||
val fileName: String
|
val fileName: String
|
||||||
) {
|
) {
|
||||||
@ -28,35 +25,18 @@ data class StorageFileInfo(
|
|||||||
/**
|
/**
|
||||||
* Contains info about file, which potentially can be sent to telegram system.
|
* Contains info about file, which potentially can be sent to telegram system.
|
||||||
*
|
*
|
||||||
* @param fileName Filename
|
* @param storageFileInfo Information about this file
|
||||||
* @param inputSource Lambda which able to allocate [Input] for uploading/manipulating data
|
* @param inputSource Lambda which able to allocate [Input] for uploading/manipulating data
|
||||||
*
|
*
|
||||||
* @see StorageFileInfo
|
* @see StorageFileInfo
|
||||||
* @see asStorageFile
|
* @see asStorageFile
|
||||||
*/
|
*/
|
||||||
data class StorageFile(
|
data class StorageFile(
|
||||||
val fileName: String,
|
val storageFileInfo: StorageFileInfo,
|
||||||
private val inputSource: () -> Input
|
private val inputSource: () -> Input
|
||||||
) {
|
) {
|
||||||
val input: Input
|
val input: Input
|
||||||
get() = inputSource()
|
get() = inputSource()
|
||||||
@Deprecated("This field will be removed soon. Use fileName instead of StorageFileInfo")
|
|
||||||
val storageFileInfo: StorageFileInfo
|
|
||||||
get() = StorageFileInfo(fileName)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This methods is required for random generation of name for keeping warranties about unique file name
|
|
||||||
*/
|
|
||||||
fun generateCustomName() = "${uuid4()}.${fileName.fileExtension}"
|
|
||||||
|
|
||||||
@Deprecated("This constructor will be removed soon. Use constructor with fileName instead of StorageFileInfo")
|
|
||||||
constructor(
|
|
||||||
storageFileInfo: StorageFileInfo,
|
|
||||||
inputSource: () -> Input
|
|
||||||
) : this(
|
|
||||||
storageFileInfo.fileName,
|
|
||||||
inputSource
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
@ -64,7 +44,7 @@ inline fun StorageFile(
|
|||||||
fileName: String,
|
fileName: String,
|
||||||
bytes: ByteArray
|
bytes: ByteArray
|
||||||
) = StorageFile(
|
) = StorageFile(
|
||||||
fileName
|
StorageFileInfo(fileName)
|
||||||
) {
|
) {
|
||||||
ByteReadPacket(bytes)
|
ByteReadPacket(bytes)
|
||||||
}
|
}
|
||||||
@ -74,8 +54,8 @@ suspend inline fun StorageFile(
|
|||||||
fileName: String,
|
fileName: String,
|
||||||
byteReadChannel: ByteReadChannel
|
byteReadChannel: ByteReadChannel
|
||||||
) = StorageFile(
|
) = StorageFile(
|
||||||
fileName,
|
StorageFileInfo(fileName),
|
||||||
inputSource = byteReadChannel.asInput().let { { it } }
|
byteReadChannel.asInput().let { { it } }
|
||||||
)
|
)
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
@ -7,7 +7,7 @@ import java.nio.file.Files
|
|||||||
fun StorageFile(
|
fun StorageFile(
|
||||||
file: File
|
file: File
|
||||||
) = StorageFile(
|
) = StorageFile(
|
||||||
file.name
|
StorageFileInfo(file.name)
|
||||||
) {
|
) {
|
||||||
file.inputStream().asInput()
|
file.inputStream().asInput()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user