...
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package kr.lunaticbum.back.lun.controllers
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -12,11 +14,15 @@ import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.scheduling.annotation.Scheduled
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.reactive.function.BodyInserter
|
||||
import org.springframework.web.reactive.function.BodyInserters
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import java.math.BigDecimal
|
||||
import java.math.RoundingMode
|
||||
import java.net.URLEncoder
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
@RestController
|
||||
@@ -47,25 +53,63 @@ class Telegram {
|
||||
@PostMapping("webhook")
|
||||
fun test(httpServletRequest: HttpServletRequest, @RequestBody update : kr.lunaticbum.back.lun.model.Result) : String {
|
||||
try {
|
||||
logService.log("test strat ${Gson().toJson(update)}")
|
||||
// logService.log("test strat ${Gson().toJson(update)}")
|
||||
logService.log("test strat ${httpServletRequest.requestURI}")
|
||||
update?.message?.let {
|
||||
if(it.text?.startsWith("/") == true) {
|
||||
it.text?.split(" ")?.let { cmds ->
|
||||
println("test strat ${Gson().toJson(update)}")
|
||||
|
||||
println("test strat ${httpServletRequest.requestURI}")
|
||||
update?.message?.let { msg ->
|
||||
if(msg.text?.startsWith("/") == true) {
|
||||
msg.text?.split(" ")?.let { cmds ->
|
||||
cmds[0].let { cmd ->
|
||||
when(cmd.trim()) {
|
||||
"/get" ->{}
|
||||
"/jf" ->{
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
logService.log("${cmd[0]} Start ${cmd[1]}")
|
||||
String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9qYXZtb3N0LnRvL3NlYXJjaC9tb3ZpZS8lcw==".toByteArray())),cmd[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService) }
|
||||
logService.log("${cmd[0]} END ${cmd[1]}")
|
||||
logService.log("${cmd} Start ${cmds[1]}")
|
||||
String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9qYXZtb3N0LnRvL3NlYXJjaC9tb3ZpZS8lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService) }
|
||||
logService.log("${cmd} END ${cmds[1]}")
|
||||
}
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
logService.log("on Cmd JF with SO")
|
||||
logService.log("${cmd[0]} Start ${cmd[1]}")
|
||||
String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmd[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)}
|
||||
logService.log("${cmd} Start ${cmds[1]}")
|
||||
String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)}
|
||||
logService.log("${cmd} END ${cmds[1]}")
|
||||
}
|
||||
}
|
||||
"/lama" -> {
|
||||
val req = BumlamaReq(msg.text!!.replace(cmd,""))
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val fullUrl =
|
||||
"https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=lama 에게 전송 ${req.reqMsg}"
|
||||
logService.log("fullUrl >>> ${fullUrl}")
|
||||
WebClient.create().get()
|
||||
.uri(fullUrl)
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block()
|
||||
}
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
logService.log("${cmd} Start ${cmds[1]}")
|
||||
// msg.chat?.id
|
||||
try {
|
||||
val client = WebClient.create()
|
||||
client.post()
|
||||
.uri("https://lama.lunaticbum.kr/api/generate")
|
||||
.body(BodyInserters.fromValue(Gson().toJson(req)))
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).timeout(Duration.ofSeconds(6000L)).block()?.let { result ->
|
||||
Gson().fromJson(result, BumlamaResp::class.java)?.let { sss ->
|
||||
println(Gson().toJson(sss))
|
||||
val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${sss.response}"
|
||||
logService.log("fullUrl >>> ${fullUrl}")
|
||||
WebClient.create().get()
|
||||
.uri(fullUrl)
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
logService.log("${cmd[0]} END ${cmd[1]}")
|
||||
}
|
||||
}
|
||||
@@ -73,45 +117,96 @@ class Telegram {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (it.text?.contains(" ") == true) {
|
||||
if (msg.text?.contains(" ") == true) {
|
||||
|
||||
} else {
|
||||
val req = BumlamaReq(msg.text)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val fullUrl =
|
||||
"https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=lama 에게 전송 => ${req.reqMsg}"
|
||||
logService.log("fullUrl >>> ${fullUrl}")
|
||||
WebClient.create().get()
|
||||
.uri(fullUrl)
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block()
|
||||
}
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
if (req.reqMsg?.contains("검색") == true) {
|
||||
val gSearch = "https://www.googleapis.com/customsearch/v1?key=AIzaSyARLXyvmr_554tOy3UCh3naFlZQS3-qQQM&cx=207f328d3ad7242f2&q=${req.reqMsg}&num=5&lr=kr"
|
||||
WebClient.create().post()
|
||||
.uri(gSearch)
|
||||
.body(BodyInserters.fromValue(Gson().toJson(req)))
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).timeout(Duration.ofSeconds(6000L)).block()?.let { result ->
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
val client = WebClient.create()
|
||||
client.post()
|
||||
.uri("https://lama.lunaticbum.kr/api/generate")
|
||||
.body(BodyInserters.fromValue(Gson().toJson(req)))
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).timeout(Duration.ofSeconds(6000L)).block()?.let { result ->
|
||||
Gson().fromJson(result, BumlamaResp::class.java)?.let { sss ->
|
||||
println(Gson().toJson(sss))
|
||||
val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${req.reqMsg}의 대답이 도착했어요.\n\n${sss.response}"
|
||||
logService.log("fullUrl >>> ${fullUrl}")
|
||||
WebClient.create().get()
|
||||
.uri(fullUrl)
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else if (msg.text?.contains("어디") == true) {
|
||||
msg.from?.id?.let { sendMsg(it.toString()) }
|
||||
} else {
|
||||
|
||||
}
|
||||
if (it.text?.contains("어디") == true) { it.from?.id?.let { sendMsg(it.toString()) } }
|
||||
}
|
||||
// val client0 = WebClient.create()
|
||||
// client0.get()
|
||||
// .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates")
|
||||
// .retrieve()
|
||||
// .bodyToMono(String::class.java).subscribe { result ->
|
||||
logService.log("test $httpServletRequest.requestURI")
|
||||
// var sss = Gson().fromJson<TelegramUpdate>(jsonString, TelegramUpdate::class.java)
|
||||
// if (sss.ok) {
|
||||
// var doSend = false
|
||||
// sss.result?.forEach {
|
||||
// if (!doSend) doSend = it.message?.text?.contains("어디") ?: false
|
||||
// }
|
||||
// if (doSend) {
|
||||
// val client = WebClient.create()
|
||||
// client.get()
|
||||
// .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=OK")
|
||||
// .retrieve()
|
||||
// .bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
// }
|
||||
// logger.log("test OK")
|
||||
// }
|
||||
// }
|
||||
} catch (e : Exception) {
|
||||
//=======
|
||||
// fun test(@RequestBody str : String) {
|
||||
// println("path >>> $str")
|
||||
//>>>>>>> ab915d0a416c69708f1df1ad76d7a14c779c1f59
|
||||
}
|
||||
return "Success"
|
||||
}
|
||||
|
||||
inner class BumlamaReq {
|
||||
private constructor()
|
||||
constructor(reqMsg: String?) {
|
||||
this.reqMsg = reqMsg
|
||||
}
|
||||
|
||||
@SerializedName("prompt")
|
||||
var reqMsg : String? = ""
|
||||
var model : String = "phi4:14b"
|
||||
// var format : String = "json"
|
||||
var stream = false
|
||||
}
|
||||
|
||||
inner class BumlamaResp {
|
||||
|
||||
var model : String? = ""//"phi4:14b",
|
||||
var created_at : String? = ""// "": "2025-02-13T06:38:53.619359Z",
|
||||
var response : String? = ""// "{ \n \"response\": \"Hello! How can I assist you today?\" \n}",
|
||||
var done : Boolean? = true
|
||||
var done_reason : String? = "stop"
|
||||
var context : ArrayList<Long>? = arrayListOf()
|
||||
var total_duration : Long = 0L//: 1600246875,
|
||||
var load_duration : Long = 0L//: 27544792,
|
||||
var prompt_eval_count : Long = 0L//: 11,
|
||||
var prompt_eval_duration : Long = 0L//: 279000000,
|
||||
var eval_count : Long = 0L//: 19,
|
||||
var eval_duration : Long = 0L//: 1292000000
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -58,6 +58,7 @@ class Message {
|
||||
var text: String? = null
|
||||
@BsonIgnore
|
||||
var entities: ArrayList<Entity>? = null
|
||||
var location : String? = null
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -84,10 +84,15 @@ class JwtService {
|
||||
}
|
||||
|
||||
fun validateRefreshToken(token: String?, refreshToken: String?): Boolean {
|
||||
val isRefreshValid = jwtUtil.getTokenStatus(refreshToken, jwtUtil.getSigningKey(globalEvv.REFRESH_SECRET_KEY)) == TokenStatus.AUTHENTICATED
|
||||
val storedToken: TokenData? = tokenRepository.findBytokenKey(token ?: "").block(Duration.ofSeconds(10))
|
||||
val isTokenMatched: Boolean = storedToken?.refreshToken.equals(refreshToken)
|
||||
return isRefreshValid && isTokenMatched
|
||||
try {
|
||||
val isRefreshValid = jwtUtil.getTokenStatus(refreshToken, jwtUtil.getSigningKey(globalEvv.REFRESH_SECRET_KEY)) == TokenStatus.AUTHENTICATED
|
||||
val storedToken: TokenData? = tokenRepository.findBytokenKey(token ?: "").block(Duration.ofSeconds(10))
|
||||
val isTokenMatched: Boolean = storedToken?.refreshToken.equals(refreshToken)
|
||||
return isRefreshValid && isTokenMatched
|
||||
} catch (e :Exception){
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun resolveTokenFromCookie(request: HttpServletRequest, tokenPrefix: JwtRule?): String {
|
||||
|
||||
Reference in New Issue
Block a user