From: David ‘Bombe’ Roden Date: Sun, 28 Jul 2019 18:59:18 +0000 (+0200) Subject: ♻️ Move throwing redirect exception into method X-Git-Tag: v81^2~162 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=aaf780d3c2a6f5ce47295786f3963c8b93f6a145 ♻️ Move throwing redirect exception into method --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt index 2dcef51..540f36e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt @@ -98,6 +98,9 @@ open class FreenetTemplatePage( /* do nothing. */ } + fun redirectTo(target: String?): Nothing = + throw RedirectException(target) + class RedirectException(val target: String?) : Exception() { override fun toString(): String = format("RedirectException{target='%s'}", target) } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt index 1dc12e4..c03a299 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt @@ -21,7 +21,7 @@ class BookmarkPage @Inject constructor(webInterface: WebInterface, loaders: Load soneRequest.core.getPost(postId)?.let { soneRequest.core.bookmarkPost(it) } - throw RedirectException(returnPage) + redirectTo(returnPage) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt index a00b4bf..b6ce673 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt @@ -35,10 +35,10 @@ class CreateAlbumPage @Inject constructor(webInterface: WebInterface, loaders: L setDescription(TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), description)) }.update() } catch (e: AlbumTitleMustNotBeEmpty) { - throw RedirectException("emptyAlbumTitle.html") + redirectTo("emptyAlbumTitle.html") } soneRequest.core.touchConfiguration() - throw RedirectException("imageBrowser.html?album=${album.id}") + redirectTo("imageBrowser.html?album=${album.id}") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt index 2f8e054..515de60 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt @@ -29,7 +29,7 @@ class CreatePostPage @Inject constructor(webInterface: WebInterface, loaders: Lo val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone val recipient = soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("recipient", 43)) soneRequest.core.createPost(sender, recipient, TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text)) - throw RedirectException(returnPage) + redirectTo(returnPage) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt index 562e647..7714b77 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt @@ -26,10 +26,10 @@ class CreateReplyPage @Inject constructor(webInterface: WebInterface, loaders: L templateContext["errorTextEmpty"] = true return } - val post = soneRequest.core.getPost(postId) ?: throw RedirectException("noPermission.html") + val post = soneRequest.core.getPost(postId) ?: redirectTo("noPermission.html") val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone soneRequest.core.createReply(sender, post, TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text)) - throw RedirectException(returnPage) + redirectTo(returnPage) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt index b2056c2..0b690da 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt @@ -31,7 +31,7 @@ class CreateSonePage @Inject constructor(webInterface: WebInterface, loaders: Lo logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: $ownIdentity") } setCurrentSone(soneRequest.toadletContext, sone) - throw RedirectException("index.html") + redirectTo("index.html") } templateContext["errorNoIdentity"] = true } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt index 29a8f8c..824f6ef 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt @@ -12,7 +12,7 @@ class DebugPage @Inject constructor(webInterface: WebInterface, loaders: Loaders override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { soneRequest.core.setDebug() - throw RedirectException("./") + redirectTo("./") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt index d55c7cb..bd86c95 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt @@ -18,18 +18,18 @@ class DeleteAlbumPage @Inject constructor(webInterface: WebInterface, loaders: L override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") + val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: redirectTo("invalid.html") if (!album.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } if (soneRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") { - throw RedirectException("imageBrowser.html?album=${album.id}") + redirectTo("imageBrowser.html?album=${album.id}") } soneRequest.core.deleteAlbum(album) - throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}") + redirectTo(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}") } val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getParam("album")) - templateContext["album"] = album ?: throw RedirectException("invalid.html") + templateContext["album"] = album ?: redirectTo("invalid.html") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt index a9d601c..6459bfd 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt @@ -18,19 +18,19 @@ class DeleteImagePage @Inject constructor(webInterface: WebInterface, loaders: L override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html") + val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: redirectTo("invalid.html") if (!image.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } if (soneRequest.httpRequest.isPartSet("abortDelete")) { - throw RedirectException("imageBrowser.html?image=${image.id}") + redirectTo("imageBrowser.html?image=${image.id}") } soneRequest.core.deleteImage(image) - throw RedirectException("imageBrowser.html?album=${image.album.id}") + redirectTo("imageBrowser.html?album=${image.album.id}") } - val image = soneRequest.core.getImage(soneRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html") + val image = soneRequest.core.getImage(soneRequest.httpRequest.getParam("image")) ?: redirectTo("invalid.html") if (!image.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } templateContext["image"] = image } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt index b3749b3..2396370 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -18,22 +18,22 @@ class DeletePostPage @Inject constructor(webInterface: WebInterface, loaders: Lo override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val post = soneRequest.core.getPost(soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html") + val post = soneRequest.core.getPost(soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: redirectTo("noPermission.html") val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (!post.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } if (soneRequest.httpRequest.isPartSet("confirmDelete")) { soneRequest.core.deletePost(post) - throw RedirectException(returnPage) + redirectTo(returnPage) } else if (soneRequest.httpRequest.isPartSet("abortDelete")) { - throw RedirectException(returnPage) + redirectTo(returnPage) } templateContext["post"] = post templateContext["returnPage"] = returnPage return } - templateContext["post"] = soneRequest.core.getPost(soneRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html") + templateContext["post"] = soneRequest.core.getPost(soneRequest.httpRequest.getParam("post")) ?: redirectTo("noPermission.html") templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt index 0fabad9..6303b11 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt @@ -18,13 +18,13 @@ class DeleteProfileFieldPage @Inject constructor(webInterface: WebInterface, loa override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") + val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: redirectTo("invalid.html") if (soneRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") { currentSone.profile = currentSone.profile.apply { removeField(field) } } - throw RedirectException("editProfile.html#profile-fields") + redirectTo("editProfile.html#profile-fields") } - val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html") + val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: redirectTo("invalid.html") templateContext["field"] = field } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt index e3f30ce..e6fbce8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt @@ -19,17 +19,17 @@ class DeleteReplyPage @Inject constructor(webInterface: WebInterface, loaders: L override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { val replyId = soneRequest.httpRequest.getPartAsStringFailsafe("reply", 36) - val reply = soneRequest.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html") + val reply = soneRequest.core.getPostReply(replyId) ?: redirectTo("noPermission.html") if (!reply.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (soneRequest.httpRequest.isPartSet("confirmDelete")) { soneRequest.core.deleteReply(reply) - throw RedirectException(returnPage) + redirectTo(returnPage) } if (soneRequest.httpRequest.isPartSet("abortDelete")) { - throw RedirectException(returnPage) + redirectTo(returnPage) } templateContext["reply"] = replyId templateContext["returnPage"] = returnPage diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt index f65e378..3f99730 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt @@ -24,7 +24,7 @@ class DeleteSonePage @Inject constructor(webInterface: WebInterface, loaders: Lo if (soneRequest.httpRequest.isPartSet("deleteSone")) { soneRequest.core.deleteSone(currentSone) } - throw RedirectException("index.html") + redirectTo("index.html") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt index 862db67..cd348e7 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt @@ -17,7 +17,7 @@ class DismissNotificationPage @Inject constructor(webInterface: WebInterface, lo val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) val notificationId = soneRequest.httpRequest.getPartAsStringFailsafe("notification", 36) soneRequest.webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss() - throw RedirectException(returnPage) + redirectTo(returnPage) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt index f2115e5..dd3ad8c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt @@ -22,7 +22,7 @@ class DistrustPage @Inject constructor(webInterface: WebInterface, loaders: Load if (soneRequest.isPOST) { soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("sone", 44)) ?.run { soneRequest.core.distrustSone(currentSone, this) } - throw RedirectException(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)) + redirectTo(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt index aeaf14e..4569e9a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt @@ -18,16 +18,16 @@ class EditAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loa override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") - album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") } + val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: redirectTo("invalid.html") + album.takeUnless { it.sone.isLocal }?.run { redirectTo("noPermission.html") } if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") { album.parent?.moveAlbumUp(album) soneRequest.core.touchConfiguration() - throw RedirectException("imageBrowser.html?album=${album.parent?.id}") + redirectTo("imageBrowser.html?album=${album.parent?.id}") } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") { album.parent?.moveAlbumDown(album) soneRequest.core.touchConfiguration() - throw RedirectException("imageBrowser.html?album=${album.parent?.id}") + redirectTo("imageBrowser.html?album=${album.parent?.id}") } else { try { album.modify() @@ -35,10 +35,10 @@ class EditAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loa .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000)) .update() } catch (e: AlbumTitleMustNotBeEmpty) { - throw RedirectException("emptyAlbumTitle.html") + redirectTo("emptyAlbumTitle.html") } soneRequest.core.touchConfiguration() - throw RedirectException("imageBrowser.html?album=${album.id}") + redirectTo("imageBrowser.html?album=${album.id}") } } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt index 76f6e23..5443d28 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt @@ -19,9 +19,9 @@ class EditImagePage @Inject constructor(webInterface: WebInterface, loaders: Loa override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html") + val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: redirectTo("invalid.html") if (!image.sone.isLocal) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage -> if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") { @@ -38,10 +38,10 @@ class EditImagePage @Inject constructor(webInterface: WebInterface, loaders: Loa .update() soneRequest.core.touchConfiguration() } catch (e: ImageTitleMustNotBeEmpty) { - throw RedirectException("emptyImageTitle.html") + redirectTo("emptyImageTitle.html") } } - throw RedirectException(returnPage) + redirectTo(returnPage) } } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt index 386f66b..be97e80 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt @@ -20,23 +20,23 @@ class EditProfileFieldPage @Inject constructor(webInterface: WebInterface, loade currentSone.profile.let { profile -> if (soneRequest.isPOST) { if (soneRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") { - throw RedirectException("editProfile.html#profile-fields") + redirectTo("editProfile.html#profile-fields") } - val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") + val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: redirectTo("invalid.html") soneRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name -> try { if (name != field.name) { field.name = name currentSone.profile = profile } - throw RedirectException("editProfile.html#profile-fields") + redirectTo("editProfile.html#profile-fields") } catch (e: IllegalArgumentException) { templateContext["duplicateFieldName"] = true return } } } - templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html") + templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: redirectTo("invalid.html") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt index 54b7efd..93393ba 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt @@ -43,31 +43,31 @@ class EditProfilePage @Inject constructor(webInterface: WebInterface, loaders: L } currentSone.profile = profile soneRequest.core.touchConfiguration() - throw RedirectException("editProfile.html") + redirectTo("editProfile.html") } else if (soneRequest.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") { val fieldName = soneRequest.httpRequest.getPartAsStringFailsafe("field-name", 100) try { profile.addField(fieldName) currentSone.profile = profile soneRequest.core.touchConfiguration() - throw RedirectException("editProfile.html#profile-fields") + redirectTo("editProfile.html#profile-fields") } catch (e: DuplicateField) { templateContext["fieldName"] = fieldName templateContext["duplicateFieldName"] = true } } else profile.fields.forEach { field -> if (soneRequest.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") { - throw RedirectException("deleteProfileField.html?field=${field.id}") + redirectTo("deleteProfileField.html?field=${field.id}") } else if (soneRequest.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") { - throw RedirectException("editProfileField.html?field=${field.id}") + redirectTo("editProfileField.html?field=${field.id}") } else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") { profile.moveFieldDown(field) currentSone.profile = profile - throw RedirectException("editProfile.html#profile-fields") + redirectTo("editProfile.html#profile-fields") } else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") { profile.moveFieldUp(field) currentSone.profile = profile - throw RedirectException("editProfile.html#profile-fields") + redirectTo("editProfile.html#profile-fields") } } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt index 244cb52..5fd06ce 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt @@ -24,7 +24,7 @@ class FollowSonePage @Inject constructor(webInterface: WebInterface, loaders: Lo soneRequest.core.followSone(currentSone, sone.first) soneRequest.core.markSoneKnown(sone.second) } - throw RedirectException(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)) + redirectTo(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt index cc5043f..c8369e9 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt @@ -23,7 +23,7 @@ class LikePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, "reply" -> currentSone.addLikedReplyId(soneRequest.parameters["reply", 36]!!) } } - throw RedirectException(soneRequest.parameters["returnPage", 256]!!) + redirectTo(soneRequest.parameters["returnPage", 256]!!) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt index 2a62a7d..9f6f30e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt @@ -19,7 +19,7 @@ class LockSonePage @Inject constructor(webInterface: WebInterface, loaders: Load soneRequest.parameters["sone", 44]!! .let { soneRequest.core.getLocalSone(it) } ?.let { soneRequest.core.lockSone(it) } - throw RedirectException(returnPage) + redirectTo(returnPage) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt index 9e47049..5be34ac 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt @@ -23,7 +23,7 @@ class LoginPage @Inject constructor(webInterface: WebInterface, loaders: Loaders soneRequest.core.getLocalSone(soneId)?.let { sone -> setCurrentSone(soneRequest.toadletContext, sone) val target = soneRequest.httpRequest.getParam("target").emptyToNull ?: "index.html" - throw RedirectException(target) + redirectTo(target) } } templateContext["sones"] = soneRequest.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt index 325d876..a7722d4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt @@ -17,7 +17,7 @@ class LogoutPage @Inject constructor(webInterface: WebInterface, loaders: Loader override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { setCurrentSone(soneRequest.toadletContext, null) - throw RedirectException("index.html") + redirectTo("index.html") } override fun isEnabled(soneRequest: SoneRequest): Boolean = diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt index 652881d..f919318 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt @@ -22,9 +22,9 @@ class MarkAsKnownPage @Inject constructor(webInterface: WebInterface, loaders: L "sone" -> ids.mapNotNull(soneRequest.core::getSone).forEach(soneRequest.core::markSoneKnown) "post" -> ids.mapNotNull(soneRequest.core::getPost).forEach(soneRequest.core::markPostKnown) "reply" -> ids.mapNotNull(soneRequest.core::getPostReply).forEach(soneRequest.core::markReplyKnown) - else -> throw RedirectException("invalid.html") + else -> redirectTo("invalid.html") } - throw RedirectException(soneRequest.parameters["returnPage", 256]!!) + redirectTo(soneRequest.parameters["returnPage", 256]!!) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt index 8829030..2c454e8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt @@ -66,7 +66,7 @@ class OptionsPage @Inject constructor(webInterface: WebInterface, loaders: Loade if (fieldsWithErrors.isEmpty()) { soneRequest.core.touchConfiguration() - throw RedirectException("options.html") + redirectTo("options.html") } templateContext["fieldErrors"] = fieldsWithErrors } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt index 2ed4940..be0e4c1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt @@ -29,7 +29,7 @@ class RescuePage @Inject constructor(webInterface: WebInterface, loaders: Loader if (soneRequest.parameters["fetch", 8] == "true") { soneRescuer.startNextFetch() } - throw RedirectException("rescue.html") + redirectTo("rescue.html") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt index 3c14604..19eba1c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt @@ -125,7 +125,7 @@ class SearchPage(webInterface: WebInterface, loaders: Loaders, templateRenderer: } } - private fun redirect(target: String): Nothing = throw RedirectException(target) + private fun redirect(target: String): Nothing = redirectTo(target) enum class Optionality { OPTIONAL, diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt index 9a4c02f..54edc5d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt @@ -21,7 +21,7 @@ class TrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders soneRequest.core.getSone(soneRequest.parameters["sone"]!!)?.let { sone -> soneRequest.core.trustSone(currentSone, sone) } - throw RedirectException(soneRequest.parameters["returnPage", 256]) + redirectTo(soneRequest.parameters["returnPage", 256]) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt index 9c226d4..aa7bbf6 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt @@ -21,13 +21,13 @@ class UnbookmarkPage @Inject constructor(webInterface: WebInterface, loaders: Lo soneRequest.core.bookmarkedPosts .filterNot(Post::isLoaded) .forEach(soneRequest.core::unbookmarkPost) - throw RedirectException("bookmarks.html") + redirectTo("bookmarks.html") } soneRequest.isPOST -> { soneRequest.parameters["post", 36] ?.let(soneRequest.core::getPost) ?.also(soneRequest.core::unbookmarkPost) - throw RedirectException(soneRequest.parameters["returnPage", 256]) + redirectTo(soneRequest.parameters["returnPage", 256]) } } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt index 79fdef5..9dbe9f1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt @@ -19,7 +19,7 @@ class UnfollowSonePage @Inject constructor(webInterface: WebInterface, loaders: if (soneRequest.isPOST) { soneRequest.parameters["sone"]!!.split(Regex("[ ,]+")) .forEach { soneRequest.core.unfollowSone(currentSone, it) } - throw RedirectException(soneRequest.parameters["returnPage", 256]) + redirectTo(soneRequest.parameters["returnPage", 256]) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt index 82147a9..46bd3ab 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt @@ -21,7 +21,7 @@ class UnlikePage @Inject constructor(webInterface: WebInterface, loaders: Loader "post" -> currentSone.removeLikedPostId(soneRequest.parameters["post"]!!) "reply" -> currentSone.removeLikedReplyId(soneRequest.parameters["reply"]!!) } - throw RedirectException(soneRequest.parameters["returnPage", 256]) + redirectTo(soneRequest.parameters["returnPage", 256]) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt index 2c5735b..450a466 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt @@ -19,7 +19,7 @@ class UnlockSonePage @Inject constructor(webInterface: WebInterface, loaders: Lo soneRequest.parameters["sone", 44] .let(soneRequest.core::getLocalSone) ?.also(soneRequest.core::unlockSone) - throw RedirectException(soneRequest.parameters["returnPage", 256]) + redirectTo(soneRequest.parameters["returnPage", 256]) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt index 7dd342e..dd445c8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt @@ -21,7 +21,7 @@ class UntrustPage @Inject constructor(webInterface: WebInterface, loaders: Loade soneRequest.parameters["sone", 44]!! .let(soneRequest.core::getSone) ?.also { soneRequest.core.untrustSone(currentSone, it) } - throw RedirectException(soneRequest.parameters["returnPage", 256]) + redirectTo(soneRequest.parameters["returnPage", 256]) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt index de61835..392b272 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt @@ -23,11 +23,11 @@ class UploadImagePage @Inject constructor(webInterface: WebInterface, loaders: L override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { - val parentAlbum = soneRequest.parameters["parent"]!!.let(soneRequest.core::getAlbum) ?: throw RedirectException("noPermission.html") + val parentAlbum = soneRequest.parameters["parent"]!!.let(soneRequest.core::getAlbum) ?: redirectTo("noPermission.html") if (parentAlbum.sone != currentSone) { - throw RedirectException("noPermission.html") + redirectTo("noPermission.html") } - val title = soneRequest.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html") + val title = soneRequest.parameters["title", 200].emptyToNull ?: redirectTo("emptyImageTitle.html") val uploadedFile = soneRequest.httpRequest.getUploadedFile("image") val bytes = uploadedFile.data.use { it.toByteArray() } @@ -44,7 +44,7 @@ class UploadImagePage @Inject constructor(webInterface: WebInterface, loaders: L setTitle(title) setDescription(TextFilter.filter(soneRequest.headers["Host"], soneRequest.parameters["description", 4000])) }.update() - throw RedirectException("imageBrowser.html?album=${parentAlbum.id}") + redirectTo("imageBrowser.html?album=${parentAlbum.id}") } }