mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
filename created
This commit is contained in:
parent
d2228e274c
commit
c91426a910
@ -51,6 +51,9 @@
|
|||||||
|
|
||||||
### 0.27.11
|
### 0.27.11
|
||||||
|
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Extension `String#filenameFromUrl` was created
|
||||||
|
* Extension `PathedFile#filename` was created
|
||||||
* `TelegramBotAPI-extensions-utils`:
|
* `TelegramBotAPI-extensions-utils`:
|
||||||
* `Flow<Iterable<T>>.flatMap` extension was added
|
* `Flow<Iterable<T>>.flatMap` extension was added
|
||||||
* Extensions for `FlowUpdatesFilter` were added:
|
* Extensions for `FlowUpdatesFilter` were added:
|
||||||
|
@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -20,5 +20,7 @@ data class PathedFile(
|
|||||||
override val fileSize: Long? = null
|
override val fileSize: Long? = null
|
||||||
): TelegramMediaFile
|
): TelegramMediaFile
|
||||||
|
|
||||||
|
val PathedFile.filename: FileName
|
||||||
|
get() = filePath.filenameFromUrl
|
||||||
fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}"
|
fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}"
|
||||||
fun PathedFile.fullUrl(keeper: TelegramAPIUrlsKeeper): String = keeper.resolveFileURL(this)
|
fun PathedFile.fullUrl(keeper: TelegramAPIUrlsKeeper): String = keeper.resolveFileURL(this)
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
private val filenameRegex = Regex("[^/]*$")
|
||||||
private val extensionRegex = Regex("[^.]*$")
|
private val extensionRegex = Regex("[^.]*$")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File name like hello.jpg
|
||||||
|
*/
|
||||||
|
typealias FileName = String
|
||||||
|
|
||||||
|
val String.filenameFromUrl: FileName
|
||||||
|
get() = filenameRegex.find(this) ?.value ?: ""
|
||||||
|
|
||||||
val String.fileExtension
|
val String.fileExtension
|
||||||
get() = extensionRegex.find(this) ?.value ?: ""
|
get() = extensionRegex.find(this) ?.value ?: ""
|
||||||
|
Loading…
Reference in New Issue
Block a user