mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
add js target
This commit is contained in:
parent
b582adc3a0
commit
0c1df47dbb
18
build.gradle
18
build.gradle
@ -31,15 +31,17 @@ repositories {
|
|||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm()
|
jvm()
|
||||||
// js()
|
js()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin('stdlib')
|
implementation kotlin('stdlib')
|
||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
||||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||||
|
|
||||||
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
||||||
|
api "com.benasher44:uuid:$uuid_version"
|
||||||
|
|
||||||
api "io.ktor:ktor-client-core:$ktor_version"
|
api "io.ktor:ktor-client-core:$ktor_version"
|
||||||
}
|
}
|
||||||
@ -68,10 +70,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// jsMain {
|
jsMain {
|
||||||
// dependencies {
|
dependencies {
|
||||||
// api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
||||||
// }
|
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
||||||
// }
|
api "io.ktor:ktor-client-js:$ktor_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ kotlin_version=1.3.61
|
|||||||
kotlin_coroutines_version=1.3.2
|
kotlin_coroutines_version=1.3.2
|
||||||
kotlin_serialisation_runtime_version=0.14.0
|
kotlin_serialisation_runtime_version=0.14.0
|
||||||
klock_version=1.8.0
|
klock_version=1.8.0
|
||||||
|
uuid_version=0.0.6
|
||||||
ktor_version=1.2.6
|
ktor_version=1.2.6
|
||||||
|
|
||||||
gradle_bintray_plugin_version=1.8.4
|
gradle_bintray_plugin_version=1.8.4
|
||||||
|
@ -3,7 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
const val inputMediaFileAttachmentNameTemplate = "attach://%s"
|
fun String.toInputMediaFileAttachmentName() = "attach://$this"
|
||||||
|
|
||||||
@Serializable(InputMediaSerializer::class)
|
@Serializable(InputMediaSerializer::class)
|
||||||
interface InputMedia {
|
interface InputMedia {
|
||||||
|
@ -5,7 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.format
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ data class InputMediaAnimation(
|
|||||||
get() = file.let {
|
get() = file.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is FileId -> it.fileId
|
is FileId -> it.fileId
|
||||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
is MultipartFile -> it.fileId.toInputMediaFileAttachmentName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.format
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ data class InputMediaAudio(
|
|||||||
get() = file.let {
|
get() = file.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is FileId -> it.fileId
|
is FileId -> it.fileId
|
||||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
is MultipartFile -> it.fileId.toInputMediaFileAttachmentName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.format
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ data class InputMediaDocument(
|
|||||||
get() = file.let {
|
get() = file.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is FileId -> it.fileId
|
is FileId -> it.fileId
|
||||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
is MultipartFile -> it.fileId.toInputMediaFileAttachmentName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.format
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -22,7 +21,7 @@ data class InputMediaPhoto(
|
|||||||
@SerialName(mediaField)
|
@SerialName(mediaField)
|
||||||
val media: String = when (file) {
|
val media: String = when (file) {
|
||||||
is FileId -> file.fileId
|
is FileId -> file.fileId
|
||||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(file.fileId)
|
is MultipartFile -> file.fileId.toInputMediaFileAttachmentName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
|
@ -4,7 +4,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.format
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -25,7 +24,7 @@ data class InputMediaVideo(
|
|||||||
@SerialName(mediaField)
|
@SerialName(mediaField)
|
||||||
val media: String = when (file) {
|
val media: String = when (file) {
|
||||||
is FileId -> file.fileId
|
is FileId -> file.fileId
|
||||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(file.fileId)
|
is MultipartFile -> file.fileId.toInputMediaFileAttachmentName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
|
@ -2,7 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.thumbField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.thumbField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.format
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ interface ThumbedInputMedia : InputMedia {
|
|||||||
get() = thumb ?.let {
|
get() = thumb ?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is FileId -> it.fileId
|
is FileId -> it.fileId
|
||||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
is MultipartFile -> it.fileId.toInputMediaFileAttachmentName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,5 +137,3 @@ infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
|||||||
is HTML -> commandHTML()
|
is HTML -> commandHTML()
|
||||||
is Markdown -> commandMarkdown()
|
is Markdown -> commandMarkdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
expect fun String.format(vararg args: Any?): String
|
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
|
import kotlinx.io.core.Input
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
actual data class StorageFile(
|
||||||
|
actual val contentType: String,
|
||||||
|
actual val fileName: String,
|
||||||
|
@Transient
|
||||||
|
val inputGetter: () -> Input = throw IllegalStateException("Can't create object without input"),
|
||||||
|
@Transient
|
||||||
|
val extension: String = throw IllegalStateException("Can't create object without extension")
|
||||||
|
) {
|
||||||
|
actual fun asInput(): Input = inputGetter()
|
||||||
|
actual fun generateCustomName(): String = "${uuid4()}.$extension"
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
import kotlinx.io.core.Input
|
import kotlinx.io.core.Input
|
||||||
import kotlinx.io.streams.asInput
|
import kotlinx.io.streams.asInput
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
actual class StorageFile(
|
actual class StorageFile(
|
||||||
@ -15,6 +15,6 @@ actual class StorageFile(
|
|||||||
) {
|
) {
|
||||||
actual val contentType: String = Files.probeContentType(file.toPath())
|
actual val contentType: String = Files.probeContentType(file.toPath())
|
||||||
actual val fileName: String = file.name
|
actual val fileName: String = file.name
|
||||||
actual fun generateCustomName(): String = "${UUID.randomUUID()}.${file.extension}"
|
actual fun generateCustomName(): String = "${uuid4()}.${file.extension}"
|
||||||
actual fun asInput(): Input = Files.newInputStream(file.toPath()).asInput()
|
actual fun asInput(): Input = Files.newInputStream(file.toPath()).asInput()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
|
||||||
|
|
||||||
import kotlin.text.format
|
|
||||||
|
|
||||||
actual fun String.format(vararg args: Any?): String = format(*args)
|
|
Loading…
Reference in New Issue
Block a user