1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.utils.also
4 import net.pterodactylus.sone.utils.emptyToNull
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
10 * AJAX page that lets the user bookmark a post.
12 class BookmarkAjaxPage(webInterface: WebInterface) : JsonPage("bookmark.ajax", webInterface) {
14 override fun requiresLogin() = false
16 override fun createJsonObject(request: FreenetRequest) =
17 request.parameters["post"].emptyToNull
18 ?.let(webInterface.core::getPost)
19 ?.also(webInterface.core::bookmarkPost)
20 ?.let { createSuccessJsonObject() }
21 ?: createErrorJsonObject("invalid-post-id")