From 52f17178ab861186cfea772b3a63bc2d1702f7e5 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Fri, 12 Jul 2024 22:05:54 +0300 Subject: [PATCH] moving to an explicit API mode refactored `files` package --- .../extensions/api/files/DownloadFile.kt | 10 ++++----- .../api/files/DownloadFileStream.kt | 21 ++++++++++--------- .../api/files/DownloadFileStreamAllocator.kt | 21 ++++++++++--------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFile.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFile.kt index 305abd5f38..d611aca3f2 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFile.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFile.kt @@ -8,31 +8,31 @@ import dev.inmo.tgbotapi.types.files.PathedFile import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.message.content.MediaContent -suspend fun TelegramBot.downloadFile( +public suspend fun TelegramBot.downloadFile( filePath: String ): ByteArray = execute( DownloadFile(filePath) ) -suspend fun TelegramBot.downloadFile( +public suspend fun TelegramBot.downloadFile( pathedFile: PathedFile ): ByteArray = downloadFile( pathedFile.filePath ) -suspend fun TelegramBot.downloadFile( +public suspend fun TelegramBot.downloadFile( fileId: FileId ): ByteArray = downloadFile( getFileAdditionalInfo(fileId) ) -suspend fun TelegramBot.downloadFile( +public suspend fun TelegramBot.downloadFile( file: TelegramMediaFile ): ByteArray = downloadFile( getFileAdditionalInfo(file) ) -suspend fun TelegramBot.downloadFile( +public suspend fun TelegramBot.downloadFile( file: MediaContent ): ByteArray = downloadFile( getFileAdditionalInfo(file.media) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStream.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStream.kt index 02abcc05fe..536ab66395 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStream.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStream.kt @@ -6,23 +6,24 @@ import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.files.PathedFile import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.message.content.MediaContent +import io.ktor.utils.io.* -suspend fun TelegramBot.downloadFileStream( +public suspend fun TelegramBot.downloadFileStream( filePath: String -) = downloadFileStreamAllocator(filePath).invoke() +): ByteReadChannel = downloadFileStreamAllocator(filePath).invoke() -suspend fun TelegramBot.downloadFileStream( +public suspend fun TelegramBot.downloadFileStream( pathedFile: PathedFile -) = downloadFileStream(pathedFile.filePath) +): ByteReadChannel = downloadFileStream(pathedFile.filePath) -suspend fun TelegramBot.downloadFileStream( +public suspend fun TelegramBot.downloadFileStream( fileId: FileId -) = downloadFileStream(getFileAdditionalInfo(fileId)) +): ByteReadChannel = downloadFileStream(getFileAdditionalInfo(fileId)) -suspend fun TelegramBot.downloadFileStream( +public suspend fun TelegramBot.downloadFileStream( file: TelegramMediaFile -) = downloadFileStream(getFileAdditionalInfo(file)) +): ByteReadChannel = downloadFileStream(getFileAdditionalInfo(file)) -suspend fun TelegramBot.downloadFileStream( +public suspend fun TelegramBot.downloadFileStream( file: MediaContent -) = downloadFileStream(getFileAdditionalInfo(file.media)) +): ByteReadChannel = downloadFileStream(getFileAdditionalInfo(file.media)) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStreamAllocator.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStreamAllocator.kt index 187caba19d..88b6c02333 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStreamAllocator.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileStreamAllocator.kt @@ -7,23 +7,24 @@ import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.files.PathedFile import dev.inmo.tgbotapi.types.files.TelegramMediaFile import dev.inmo.tgbotapi.types.message.content.MediaContent +import dev.inmo.tgbotapi.utils.ByteReadChannelAllocator -suspend fun TelegramBot.downloadFileStreamAllocator( +public suspend fun TelegramBot.downloadFileStreamAllocator( filePath: String -) = execute(DownloadFileStream(filePath)) +): ByteReadChannelAllocator = execute(DownloadFileStream(filePath)) -suspend fun TelegramBot.downloadFileStreamAllocator( +public suspend fun TelegramBot.downloadFileStreamAllocator( pathedFile: PathedFile -) = downloadFileStreamAllocator(pathedFile.filePath) +): ByteReadChannelAllocator = downloadFileStreamAllocator(pathedFile.filePath) -suspend fun TelegramBot.downloadFileStreamAllocator( +public suspend fun TelegramBot.downloadFileStreamAllocator( fileId: FileId -) = downloadFileStreamAllocator(getFileAdditionalInfo(fileId)) +): ByteReadChannelAllocator = downloadFileStreamAllocator(getFileAdditionalInfo(fileId)) -suspend fun TelegramBot.downloadFileStreamAllocator( +public suspend fun TelegramBot.downloadFileStreamAllocator( file: TelegramMediaFile -) = downloadFileStreamAllocator(getFileAdditionalInfo(file)) +): ByteReadChannelAllocator = downloadFileStreamAllocator(getFileAdditionalInfo(file)) -suspend fun TelegramBot.downloadFileStreamAllocator( +public suspend fun TelegramBot.downloadFileStreamAllocator( file: MediaContent -) = downloadFileStreamAllocator(getFileAdditionalInfo(file.media)) +): ByteReadChannelAllocator = downloadFileStreamAllocator(getFileAdditionalInfo(file.media))