mirror of https://github.com/usbharu/Hideout.git
feat: OGP用のクラスを追加
This commit is contained in:
parent
48d325deed
commit
c8a8e77021
|
@ -1,11 +1,11 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.springframework
|
package dev.usbharu.hideout.core.infrastructure.springframework
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.interfaces.web.common.OGP
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import jakarta.servlet.http.HttpServletResponse
|
import jakarta.servlet.http.HttpServletResponse
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import org.springframework.web.servlet.HandlerInterceptor
|
import org.springframework.web.servlet.HandlerInterceptor
|
||||||
import org.springframework.web.servlet.ModelAndView
|
import org.springframework.web.servlet.ModelAndView
|
||||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class SPAInterceptor : HandlerInterceptor {
|
class SPAInterceptor : HandlerInterceptor {
|
||||||
|
@ -29,18 +29,12 @@ class SPAInterceptor : HandlerInterceptor {
|
||||||
if (request.session.getAttribute("s") == "f") {
|
if (request.session.getAttribute("s") == "f") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val title = modelAndView?.modelMap?.getOrDefault("title", "")
|
|
||||||
val url = modelAndView?.modelMap?.getOrDefault(
|
val ogp = modelAndView?.modelMap?.get("ogp") as? OGP
|
||||||
"url",
|
|
||||||
ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString() + '?' + request.queryString
|
|
||||||
)
|
|
||||||
val description = modelAndView?.modelMap?.getOrDefault("description", "")
|
|
||||||
val image = modelAndView?.modelMap?.get("image")
|
|
||||||
|
|
||||||
modelAndView?.clear()
|
modelAndView?.clear()
|
||||||
modelAndView?.addObject("nsUrl", request.requestURI + "?s=f" + request.queryString?.let { "&$it" }.orEmpty())
|
modelAndView?.addObject("nsUrl", request.requestURI + "?s=f" + request.queryString?.let { "&$it" }.orEmpty())
|
||||||
modelAndView?.addAllObjects(mapOf("title" to title, "url" to url, "description" to description))
|
modelAndView?.addObject("ogp", ogp)
|
||||||
image?.let { modelAndView?.addObject("image", it) }
|
|
||||||
modelAndView?.viewName = "index"
|
modelAndView?.viewName = "index"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue