X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FBookmarkAjaxPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FBookmarkAjaxPage.kt;h=fd22f06dcb096e3a1237a913ec28e3530e3a6aa7;hp=0000000000000000000000000000000000000000;hb=70328c1ee52a67654eaa899ab951d4c1dbe3a697;hpb=acab609befb73e27ee91cfeae4966aaf76236b5f diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt new file mode 100644 index 0000000..fd22f06 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt @@ -0,0 +1,23 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.utils.also +import net.pterodactylus.sone.utils.emptyToNull +import net.pterodactylus.sone.utils.parameters +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest + +/** + * AJAX page that lets the user bookmark a post. + */ +class BookmarkAjaxPage(webInterface: WebInterface) : JsonPage("bookmark.ajax", webInterface) { + + override fun requiresLogin() = false + + override fun createJsonObject(request: FreenetRequest) = + request.parameters["post"].emptyToNull + ?.let(webInterface.core::getPost) + ?.also(webInterface.core::bookmarkPost) + ?.let { createSuccessJsonObject() } + ?: createErrorJsonObject("invalid-post-id") + +}