private val cache: Cache<Iterable<Phrase>, Pagination<Post>> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build()
- override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
val phrases = try {
- request.parameters["query"].emptyToNull?.parse()
+ freenetRequest.parameters["query"].emptyToNull?.parse()
} catch (te: TextException) {
redirect("index.html")
}
0 -> redirect("index.html")
1 -> phrases.first().phrase.also { word ->
when {
- word.removePrefix("sone://").let(webInterface.core::getSone).isPresent -> redirect("viewSone.html?sone=${word.removePrefix("sone://")}")
- word.removePrefix("post://").let(webInterface.core::getPost).isPresent -> redirect("viewPost.html?post=${word.removePrefix("post://")}")
- word.removePrefix("reply://").let(webInterface.core::getPostReply).isPresent -> redirect("viewPost.html?post=${word.removePrefix("reply://").let(webInterface.core::getPostReply).get().postId}")
+ word.removePrefix("sone://").let(webInterface.core::getSone) != null -> redirect("viewSone.html?sone=${word.removePrefix("sone://")}")
+ word.removePrefix("post://").let(webInterface.core::getPost) != null -> redirect("viewPost.html?post=${word.removePrefix("post://")}")
+ word.removePrefix("reply://").let(webInterface.core::getPostReply) != null -> redirect("viewPost.html?post=${word.removePrefix("reply://").let(webInterface.core::getPostReply)?.postId}")
word.removePrefix("album://").let(webInterface.core::getAlbum) != null -> redirect("imageBrowser.html?album=${word.removePrefix("album://")}")
word.removePrefix("image://").let { webInterface.core.getImage(it, false) } != null -> redirect("imageBrowser.html?image=${word.removePrefix("image://")}")
}
val sonePagination = webInterface.core.sones
.scoreAndPaginate(phrases) { it.allText() }
- .apply { page = request.parameters["sonePage"].emptyToNull?.toIntOrNull() ?: 0 }
+ .apply { page = freenetRequest.parameters["sonePage"].emptyToNull?.toIntOrNull() ?: 0 }
val postPagination = cache.get(phrases) {
webInterface.core.sones
.flatMap(Sone::getPosts)
.filter { Post.FUTURE_POSTS_FILTER.apply(it) }
.scoreAndPaginate(phrases) { it.allText() }
- }.apply { page = request.parameters["postPage"].emptyToNull?.toIntOrNull() ?: 0 }
+ }.apply { page = freenetRequest.parameters["postPage"].emptyToNull?.toIntOrNull() ?: 0 }
templateContext["sonePagination"] = sonePagination
templateContext["soneHits"] = sonePagination.items