X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FDeleteAlbumPage.kt;h=bd86c954c28ecb62d0f4d53330158d82bdf980a7;hp=8009c72e2bbba1885996ca530273611c817e743a;hb=HEAD;hpb=05fb821e72072bde52f383bdc5a988da67f66d0c 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 8009c72..bd86c95 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt @@ -1,32 +1,35 @@ package net.pterodactylus.sone.web.pages -import net.pterodactylus.sone.utils.isPOST -import net.pterodactylus.sone.web.pages.SoneTemplatePage -import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest -import net.pterodactylus.util.template.Template -import net.pterodactylus.util.template.TemplateContext +import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.main.* +import net.pterodactylus.sone.utils.* +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* +import net.pterodactylus.util.template.* +import javax.inject.* /** * Page that lets the user delete an {@link Album}. */ -class DeleteAlbumPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true) { +@TemplatePath("/templates/deleteAlbum.html") +@ToadletPath("deleteAlbum.html") +class DeleteAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("Page.DeleteAlbum.Title", webInterface, loaders, templateRenderer) { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.isPOST) { - val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") + override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { + if (soneRequest.isPOST) { + 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 (request.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") { - throw RedirectException("imageBrowser.html?album=${album.id}") + if (soneRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") { + redirectTo("imageBrowser.html?album=${album.id}") } - webInterface.core.deleteAlbum(album) - throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}") + soneRequest.core.deleteAlbum(album) + redirectTo(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}") } - val album = webInterface.core.getAlbum(request.httpRequest.getParam("album")) - templateContext["album"] = album ?: throw RedirectException("invalid.html") + val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getParam("album")) + templateContext["album"] = album ?: redirectTo("invalid.html") } }