From: David ‘Bombe’ Roden Date: Sat, 18 May 2019 09:34:53 +0000 (+0200) Subject: ✨ Use @ToadletPath for JSON pages, too X-Git-Tag: v79^2~13 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ca45de0dcbd2e361ab630bbee1d47ff6cf34d97c;p=Sone.git ✨ Use @ToadletPath for JSON pages, too --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt index 74fec61..e9a1a50 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt @@ -3,13 +3,14 @@ package net.pterodactylus.sone.web.ajax 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 +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user bookmark a post. */ -class BookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage("bookmark.ajax", webInterface) { +@ToadletPath("bookmark.ajax") +class BookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt index 00bc6c2..79e66ad 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.kt @@ -10,7 +10,8 @@ import javax.inject.* /** * AJAX handler that creates a new post. */ -class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("createPost.ajax", webInterface) { +@ToadletPath("createPost.ajax") +class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["text"].emptyToNull diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.kt index 7cb9752..df86dc0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.kt @@ -10,7 +10,8 @@ import javax.inject.* /** * This AJAX page create a reply. */ -class CreateReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("createReply.ajax", webInterface) { +@ToadletPath("createReply.ajax") +class CreateReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest): JsonReturnObject = request.parameters["post"].emptyToNull diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt index 4696cc5..3dca438 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt @@ -9,7 +9,8 @@ import javax.inject.* /** * This AJAX page deletes a post. */ -class DeletePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("deletePost.ajax", webInterface) { +@ToadletPath("deletePost.ajax") +class DeletePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["post"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt index 0697320..6daa4da 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt @@ -3,14 +3,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user delete a profile field. */ -class DeleteProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("deleteProfileField.ajax", webInterface) { +@ToadletPath("deleteProfileField.ajax") +class DeleteProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.kt index a7ef1a1..b558356 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.kt @@ -9,8 +9,8 @@ import javax.inject.* /** * This AJAX page deletes a reply. */ -class DeleteReplyAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("deleteReply.ajax", webInterface) { +@ToadletPath("deleteReply.ajax") +class DeleteReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["reply"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt index d755060..06fe51b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.kt @@ -4,14 +4,14 @@ import net.pterodactylus.sone.utils.ifTrue import net.pterodactylus.sone.utils.let import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user dismiss a notification. */ -class DismissNotificationAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("dismissNotification.ajax", webInterface) { +@ToadletPath("dismissNotification.ajax") +class DismissNotificationAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt index e4f2327..cbeed6e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt @@ -12,8 +12,8 @@ import javax.inject.* * * @see Core.distrustSone(Sone, Sone) */ -class DistrustAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("distrustSone.ajax", webInterface) { +@ToadletPath("distrustSone.ajax") +class DistrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["sone"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.kt index 9cb3acf..39442f0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.kt @@ -5,13 +5,14 @@ import net.pterodactylus.sone.utils.headers import net.pterodactylus.sone.utils.ifTrue import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * Page that stores a user’s album modifications. */ -class EditAlbumAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage("editAlbum.ajax", webInterface) { +@ToadletPath("editAlbum.ajax") +class EditAlbumAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override fun createJsonObject(request: FreenetRequest) = request.parameters["album"]!! diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.kt index b0ce048..7012cdc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.kt @@ -8,17 +8,18 @@ import net.pterodactylus.sone.utils.headers import net.pterodactylus.sone.utils.ifTrue import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.TemplateContext import javax.inject.Inject /** * Page that stores a user’s image modifications. */ +@ToadletPath("editImage.ajax") class EditImageAjaxPage @Inject constructor(webInterface: WebInterface, private val parserFilter: ParserFilter, private val shortenFilter: ShortenFilter, - private val renderFilter: RenderFilter) : JsonPage("editImage.ajax", webInterface) { + private val renderFilter: RenderFilter) : JsonPage(webInterface) { override fun createJsonObject(request: FreenetRequest) = request.parameters["image"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt index 7e7581d..9d5346c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt @@ -4,14 +4,14 @@ import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.ifFalse import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user rename a profile field. */ -class EditProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("editProfileField.ajax", webInterface) { +@ToadletPath("editProfileField.ajax") +class EditProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.kt index 32591b5..eea5120 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.kt @@ -3,14 +3,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets a Sone follow another Sone. */ -class FollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("followSone.ajax", webInterface) { +@ToadletPath("followSone.ajax") +class FollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["sone"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt index f0b0012..1175b2b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt @@ -6,15 +6,15 @@ import net.pterodactylus.sone.utils.jsonArray import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that retrieves the number of “likes” a [net.pterodactylus.sone.data.Post] * or [net.pterodactylus.sone.data.PostReply] has. */ -class GetLikesAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("getLikes.ajax", webInterface) { +@ToadletPath("getLikes.ajax") +class GetLikesAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val needsFormPassword = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt index 760c1de..115370a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLinkedElementAjaxPage.kt @@ -8,14 +8,15 @@ import net.pterodactylus.sone.template.LinkedElementRenderFilter import net.pterodactylus.sone.utils.jsonArray import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * Renders linked elements after they have been loaded. */ +@ToadletPath("getLinkedElement.ajax") class GetLinkedElementAjaxPage @Inject constructor(webInterface: WebInterface, private val elementLoader: ElementLoader, private val linkedElementRenderFilter: LinkedElementRenderFilter): - JsonPage("getLinkedElement.ajax", webInterface) { + JsonPage(webInterface) { override val needsFormPassword = false override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt index f3b370d..db6e5c5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt @@ -6,7 +6,7 @@ import net.pterodactylus.sone.main.SonePlugin import net.pterodactylus.sone.utils.jsonArray import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.notify.TemplateNotification import java.io.StringWriter @@ -15,8 +15,8 @@ import javax.inject.Inject /** * AJAX handler to return all current notifications. */ -class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("getNotifications.ajax", webInterface) { +@ToadletPath("getNotifications.ajax") +class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val needsFormPassword = false override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt index 7f1ce6e..1aedd49 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt @@ -6,15 +6,15 @@ import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.utils.render import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.Template import javax.inject.Inject /** * This AJAX handler retrieves information and rendered representation of a [Post]. */ -class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val postTemplate: Template) : - LoggedInJsonPage("getPost.ajax", webInterface) { +@ToadletPath("getPost.ajax") +class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val postTemplate: Template) : LoggedInJsonPage(webInterface) { override val needsFormPassword = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt index 119a622..ec5a5ac 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.kt @@ -6,15 +6,15 @@ import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.utils.render import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.template.Template import javax.inject.Inject /** * This AJAX page returns the details of a reply. */ -class GetReplyAjaxPage @Inject constructor(webInterface: WebInterface, private val template: Template) : - LoggedInJsonPage("getReply.ajax", webInterface) { +@ToadletPath("getReply.ajax") +class GetReplyAjaxPage @Inject constructor(webInterface: WebInterface, private val template: Template) : LoggedInJsonPage(webInterface) { override val needsFormPassword = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt index 0017a32..75f3c3c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt @@ -14,7 +14,7 @@ import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.toArray import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import java.text.SimpleDateFormat import java.util.TimeZone import javax.inject.Inject @@ -23,8 +23,9 @@ import javax.inject.Inject * The “get status” AJAX handler returns all information that is necessary to * update the web interface in real-time. */ +@ToadletPath("getStatus.ajax") class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone): - JsonPage("getStatus.ajax", webInterface) { + JsonPage(webInterface) { @Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter): this(webInterface, elementLoader, timeTextConverter, l10nFilter, TimeZone.getDefault()) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt index 233cf75..ef4a0db 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt @@ -5,7 +5,7 @@ import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import java.text.SimpleDateFormat import java.util.TimeZone import javax.inject.Inject @@ -13,10 +13,11 @@ import javax.inject.Inject /** * Ajax page that returns a formatted, relative timestamp for replies or posts. */ +@ToadletPath("getTimes.ajax") class GetTimesAjaxPage @Inject constructor(webInterface: WebInterface, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, - timeZone: TimeZone) : JsonPage("getTimes.ajax", webInterface) { + timeZone: TimeZone) : JsonPage(webInterface) { private val dateTimeFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply { this.timeZone = timeZone diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt index 99429e4..41188ea 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTranslationAjaxPage.kt @@ -2,14 +2,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * Returns the translation for a given key as JSON object. */ -class GetTranslationAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("getTranslation.ajax", webInterface) { +@ToadletPath("getTranslation.ajax") +class GetTranslationAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val needsFormPassword = false override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt index 5b56031..99c0828 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/JsonPage.kt @@ -5,7 +5,7 @@ import freenet.clients.http.ToadletContext import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.SessionProvider import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.web.Page import net.pterodactylus.util.web.Response import java.io.ByteArrayOutputStream @@ -15,13 +15,13 @@ import java.io.PrintStream * A JSON page is a specialized [Page] that will always return a JSON * object to the browser, e.g. for use with AJAX or other scripting frameworks. */ -abstract class JsonPage(private val path: String, protected val webInterface: WebInterface) : Page { +abstract class JsonPage(protected val webInterface: WebInterface) : Page { private val objectMapper = ObjectMapper() private val sessionProvider: SessionProvider = webInterface protected val core = webInterface.core - override fun getPath() = path + override fun getPath() = toadletPath override fun isPrefixPage() = false open val needsFormPassword = true diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt index fe52c9d..b2993f4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt @@ -3,14 +3,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user like a [net.pterodactylus.sone.data.Post]. */ -class LikeAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("like.ajax", webInterface) { +@ToadletPath("like.ajax") +class LikeAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = when (request.parameters["type"]) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt index c11dd0c..c177041 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.kt @@ -2,14 +2,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * Lets the user [lock][net.pterodactylus.sone.core.Core.lockSone] a [Sone][net.pterodactylus.sone.data.Sone]. */ -class LockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("lockSone.ajax", webInterface) { +@ToadletPath("lockSone.ajax") +class LockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt index 388c289..d1afaec 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPage.kt @@ -7,7 +7,7 @@ import net.pterodactylus.sone.web.page.FreenetRequest /** * Base JSON page for all pages that require the user to be logged in. */ -open class LoggedInJsonPage(path: String, webInterface: WebInterface) : JsonPage(path, webInterface) { +open class LoggedInJsonPage(webInterface: WebInterface) : JsonPage(webInterface) { final override val requiresLogin = true diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt index 4ab6d18..808d2fa 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt @@ -2,15 +2,15 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s, * [net.pterodactylus.sone.data.Post]s, or [net.pterodactylus.sone.data.Reply]s as known. */ -class MarkAsKnownAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("markAsKnown.ajax", webInterface) { +@ToadletPath("markAsKnown.ajax") +class MarkAsKnownAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.kt index 6bc129b..0b2c5ab 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.kt @@ -5,7 +5,7 @@ import net.pterodactylus.sone.data.Profile.Field import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** @@ -14,8 +14,8 @@ import javax.inject.Inject * @see net.pterodactylus.sone.data.Profile#moveFieldUp(Field) * @see net.pterodactylus.sone.data.Profile#moveFieldDown(Field) */ -class MoveProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("moveProfileField.ajax", webInterface) { +@ToadletPath("moveProfileField.ajax") +class MoveProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt index bfb88b7..9f0de87 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt @@ -11,8 +11,8 @@ import javax.inject.* * * @see net.pterodactylus.sone.core.Core.trustSone */ -class TrustAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("trustSone.ajax", webInterface) { +@ToadletPath("trustSone.ajax") +class TrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["sone"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt index bfab41c..bc61b21 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.kt @@ -2,14 +2,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user unbookmark a post. */ -class UnbookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("unbookmark.ajax", webInterface) { +@ToadletPath("unbookmark.ajax") +class UnbookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.kt index b1bca19..d8b8290 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.kt @@ -3,14 +3,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets a Sone unfollow another Sone. */ -class UnfollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("unfollowSone.ajax", webInterface) { +@ToadletPath("unfollowSone.ajax") +class UnfollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["sone"] diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.kt index e2277c9..a8da594 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.kt @@ -4,14 +4,14 @@ import net.pterodactylus.sone.data.Sone 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 +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user unlike a [net.pterodactylus.sone.data.Post]. */ -class UnlikeAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("unlike.ajax", webInterface) { +@ToadletPath("unlike.ajax") +class UnlikeAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = when (request.parameters["type"]) { "post" -> request.processEntity("post", currentSone::removeLikedPostId) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt index efa70f1..130d102 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.kt @@ -2,14 +2,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * Lets the user [unlock][net.pterodactylus.sone.core.Core.unlockSone] a [Sone][net.pterodactylus.sone.data.Sone]. */ -class UnlockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : - JsonPage("unlockSone.ajax", webInterface) { +@ToadletPath("unlockSone.ajax") +class UnlockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { override val requiresLogin = false diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt index 95dca17..e4b5edb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt @@ -3,14 +3,14 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import javax.inject.Inject /** * AJAX page that lets the user [untrust][net.pterodactylus.sone.core.Core.untrustSone] a [Sone]. */ -class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) : - LoggedInJsonPage("untrustSone.ajax", webInterface) { +@ToadletPath("untrustSone.ajax") +class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["sone"] diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt index 5e32a7d..f9554f3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt @@ -23,7 +23,7 @@ class JsonPageBaseTest : TestObjects() { private val outputStream = ByteArrayOutputStream() private val response = Response(outputStream) - private val page = object : JsonPage("path.html", webInterface) { + private val page = object : JsonPage(webInterface) { override val needsFormPassword get() = this@JsonPageBaseTest.needsFormPassword diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPageTest.kt index 9578d45..edc8c25 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/LoggedInJsonPageTest.kt @@ -1,6 +1,12 @@ package net.pterodactylus.sone.web.ajax +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* + /** * Unit test for [LoggedInJsonPageTest]. */ -class LoggedInJsonPageTest : JsonPageTest("path", requiresLogin = true, pageSupplier = { webInterface -> LoggedInJsonPage("path", webInterface) }) +class LoggedInJsonPageTest : JsonPageTest("path", requiresLogin = true, pageSupplier = ::TestPage) + +@ToadletPath("path") +class TestPage(webInterface: WebInterface) : LoggedInJsonPage(webInterface)