This commit is contained in:
lunaticbum
2024-10-24 18:04:29 +09:00
parent 21df7cd3c3
commit 5979281bab
13 changed files with 194 additions and 36 deletions
@@ -18,7 +18,6 @@ import org.springframework.core.io.Resource
import org.springframework.core.io.UrlResource
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import org.springframework.web.reactive.function.client.WebClient
@@ -32,7 +31,9 @@ import java.util.*
@RestController
@RequestMapping("/blog")
class BlogController() {
companion object {
val TEMPTOKEN = "TEMP_TOKEN_VIBUM"
}
@Autowired
lateinit var globalEvv : GlobalEnvironment
@@ -48,7 +49,7 @@ class BlogController() {
@GetMapping("write/{token}","write")
fun writ(@PathVariable token : String? ) : ModelAndView{
val vm = ModelAndView("content/blog/write")
if (token.equals("TEMP_TOKEN_VIBUM")) {
if (token.equals(TEMPTOKEN)) {
vm.modelMap.put(WRITE_PERMISSION_KEY,"OK")
vm.modelMap.put(EncTypeKey, EncType11)
vm.modelMap.put(ApiKeyWordKey,"WRITE")
@@ -88,16 +89,20 @@ class BlogController() {
var fullData = arrayListOf<String>()
for (idx in 0..max) { if (idx % 2 == 0) { if (nb.size > 0) { fullData.add(nb.removeLast()) } } else { if (na.size > 0) { fullData.add(na.removeLast()) } } }
logService.log(fullData.joinToString(""))
val target = Gson().fromJson(fullData.joinToString(""), Post::class.java) ?: Post()
var target = Gson().fromJson(fullData.joinToString(""), Post::class.java) ?: Post()
if (target.writeTime < 1L) {
target.id = null
target.writeTime = System.currentTimeMillis()
} else {
logService.log("target.writeTime >>> ${target.writeTime}")
target.modifyTime = System.currentTimeMillis()
postManageg.save(target)
target = Gson().fromJson(fullData.joinToString(""), Post::class.java) ?: Post()
target.originId = target.id
target.id = null
target.modifyTime = System.currentTimeMillis()
}
var user = postManageg.save(target)
if (user != null) {
var postMono = postManageg.save(target)
if (postMono != null) {
lResultMsg = "save post"
lResultCode = 0
} else {
@@ -134,20 +139,36 @@ class BlogController() {
}
@GetMapping("modify")
fun modify() : ModelAndView{
fun modify(@RequestParam("token") token : String?) : ModelAndView{
logService.log("incoming modify")
val vm = ModelAndView("content/blog/modify")
postManageg.find20()?.apply {
forEach { it.title = URLDecoder.decode(it.title)}
vm.modelMap.put("posts",this)
if (TEMPTOKEN.equals(token)) {
postManageg.find20()?.apply {
forEach {
it.title = URLDecoder.decode(it.title)
it.content = URLDecoder.decode(it.content)
}
vm.modelMap.put("chunkedPosts", this.chunked(3))
}
vm.modelMap.put(WRITE_PERMISSION_KEY,"OK")
vm.modelMap.put("path","editor/")
vm.modelMap.put("SK",token)
} else {
vm.modelMap.put(WRITE_PERMISSION_KEY,"NO")
}
vm.modelMap.put("rowKey","chunkedPosts_")
return vm
}
@GetMapping("editor/{postId}")
fun editor(@PathVariable postId : String) : ModelAndView{
fun editor(@PathVariable postId : String, @RequestParam("token") token : String?) : ModelAndView{
val vm = ModelAndView("content/blog/editor")
vm.modelMap.put("srcPost",postManageg.getPost(postId).block().apply { })
if (TEMPTOKEN.equals(token)) {
vm.modelMap.put(WRITE_PERMISSION_KEY,"OK")
} else {
vm.modelMap.put(WRITE_PERMISSION_KEY,"NO")
}
return vm
}
@@ -1,6 +1,7 @@
package kr.lunaticbum.back.lun.controllers
import com.google.gson.Gson
import jakarta.servlet.http.HttpServletResponse
import kr.lunaticbum.back.lun.model.PostManageg
import kr.lunaticbum.back.lun.utils.LogService
import org.springframework.beans.factory.annotation.Autowired
@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.ModelAndView
import java.net.http.HttpClient.Redirect
@RestController
@RequestMapping()
@@ -29,7 +31,10 @@ class Home {
})
return vm
}
@GetMapping("/login")
fun login(response: HttpServletResponse) {
response.sendRedirect("/user/login")
}
@GetMapping("/licenses")
fun licenses() : ModelAndView {
@@ -61,7 +61,7 @@ class UserController {
return vm
}
@GetMapping("login")
@GetMapping("login","login")
fun userLogin(httpServletRequest: HttpServletRequest): ModelAndView {
logService.log("onJoin")
val vm = ModelAndView("content/user/login")
@@ -17,6 +17,7 @@ import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Repository
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import java.time.Duration
@@ -50,7 +51,7 @@ class Post {
@Repository
interface PostRepository : ReactiveMongoRepository<Post, String> {
fun findAllByModifyTime(time : Long? = 0): Flux<Post>
}
@@ -64,9 +65,10 @@ class PostManageg {
@Autowired
private lateinit var bCryptPasswordEncoder: PasswordEncoder
fun getPost(id : String) : Mono<Post> = postRepository.findById(id)
fun find20() : List<Post> {
return postRepository.findAll().takeLast(20).buffer(20).blockLast(Duration.ofSeconds(30)) ?: listOf()
return postRepository.findAllByModifyTime(0).takeLast(20).buffer(20).blockLast(Duration.ofSeconds(30)) ?: listOf()
}
fun save(post: Post): Mono<Post> {
@@ -9,6 +9,12 @@ open class ResponceResult {
var resultMsg: String? = null
}
@Getter
open class LoginResult : ResponceResult() {
var token: String? = null
}
@Getter
class FileSaveResult : ResponceResult() {
var fileName : String? = null
@@ -0,0 +1,22 @@
package kr.lunaticbum.back.lun.model
import lombok.AllArgsConstructor
import lombok.Data
import lombok.NoArgsConstructor
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.index.Indexed
import org.springframework.data.mongodb.core.mapping.Document
import java.util.*
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "TokenData")
class TokenData {
@Indexed(expireAfterSeconds = 60 * 5)
var expireAt: Date? = null
@Id
var tokenKey : String? = null
var refreshToken : String? = null
}
@@ -2,6 +2,9 @@ package kr.lunaticbum.back.lun.model
import kr.lunaticbum.back.lun.utils.LogService
import lombok.*
import org.bson.BsonType
import org.bson.codecs.pojo.annotations.BsonId
import org.bson.codecs.pojo.annotations.BsonRepresentation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
@@ -22,6 +25,11 @@ import java.time.Duration
@AllArgsConstructor
@Document(collection = "User")
class User {
@BsonId
@BsonRepresentation(BsonType.OBJECT_ID)
var userId: String? = null
@Id
var user_id: String? = null
var user_pw: String? = null