1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-12-17 19:55:49 +00:00

remove mime types from requests

This commit is contained in:
2021-08-13 14:02:39 +06:00
parent 58dcbe8751
commit e75c93d626
6 changed files with 51 additions and 87 deletions

View File

@@ -11,35 +11,28 @@ import dev.inmo.tgbotapi.utils.*
suspend fun convertToStorageFile(
downloadStreamAllocator: ByteReadChannelAllocator,
pathedFile: PathedFile,
mimeType: MimeType
pathedFile: PathedFile
): StorageFile {
return downloadStreamAllocator.asStorageFile(
pathedFile.fileName,
mimeType
pathedFile.fileName
)
}
suspend fun TelegramBot.convertToStorageFile(
pathedFile: PathedFile,
mimeType: MimeType
pathedFile: PathedFile
): StorageFile = convertToStorageFile(
execute(DownloadFileStream(pathedFile.filePath)),
pathedFile,
mimeType
pathedFile
)
suspend fun TelegramBot.convertToStorageFile(
fileId: FileId,
mimeType: MimeType
): StorageFile = convertToStorageFile(execute(GetFile(fileId)), mimeType)
fileId: FileId
): StorageFile = convertToStorageFile(execute(GetFile(fileId)))
suspend fun TelegramBot.convertToStorageFile(
file: TelegramMediaFile,
mimeType: MimeType
): StorageFile = convertToStorageFile(file.fileId, mimeType)
file: TelegramMediaFile
): StorageFile = convertToStorageFile(file.fileId)
suspend fun TelegramBot.convertToStorageFile(
content: MediaContent,
mimeType: MimeType
): StorageFile = convertToStorageFile(content.media, mimeType)
content: MediaContent
): StorageFile = convertToStorageFile(content.media)

View File

@@ -1,45 +0,0 @@
package dev.inmo.tgbotapi.extensions.utils.types.files
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.asMimedMediaFile
import dev.inmo.tgbotapi.requests.DownloadFileStream
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.get.GetFile
import dev.inmo.tgbotapi.types.files.PathedFile
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
import dev.inmo.tgbotapi.utils.*
import java.nio.file.Files
import kotlin.io.path.Path
suspend fun convertToStorageFile(
downloadStreamAllocator: ByteReadChannelAllocator,
pathedFile: PathedFile
): StorageFile {
return downloadStreamAllocator.asStorageFile(
pathedFile.fileName,
Files.probeContentType(Path(pathedFile.fileName)).asMimeType()
)
}
suspend fun TelegramBot.convertToStorageFile(
pathedFile: PathedFile
): StorageFile = convertToStorageFile(
execute(DownloadFileStream(pathedFile.filePath)),
pathedFile
)
suspend fun TelegramBot.convertToStorageFile(
fileId: FileId
): StorageFile = convertToStorageFile(execute(GetFile(fileId)))
suspend fun TelegramBot.convertToStorageFile(
file: TelegramMediaFile
): StorageFile = file.asMimedMediaFile() ?.mimeType ?.let {
convertToStorageFile(file.fileId, it)
} ?: convertToStorageFile(file.fileId)
suspend fun TelegramBot.convertToStorageFile(
content: MediaContent
): StorageFile = convertToStorageFile(content.media)