X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateAlbumPage.kt;h=3ffd62202c6ea29cb836215fc00d03c3450557ad;hp=d14ba3ad71464bdcc55a29078b8e45ae4ca9c092;hb=e3da46d8947ab8a542a156069b3b24c13fd011df;hpb=5ba707d40f9d2a20094aaabc21647aeec1feed46 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 d14ba3a..3ffd622 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt @@ -1,40 +1,42 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.main.* import net.pterodactylus.sone.text.TextFilter import net.pterodactylus.sone.utils.isPOST 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 net.pterodactylus.util.template.TemplateContext +import javax.inject.Inject /** * Page that lets the user create a new album. */ -class CreateAlbumPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) { +class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, loaders, templateRenderer) { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.isPOST) { - val name = request.httpRequest.getPartAsStringFailsafe("name", 64).trim() + override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { + if (soneRequest.isPOST) { + val name = soneRequest.httpRequest.getPartAsStringFailsafe("name", 64).trim() if (name.isEmpty()) { templateContext["nameMissing"] = true return } - val description = request.httpRequest.getPartAsStringFailsafe("description", 256).trim() - val currentSone = webInterface.getCurrentSoneCreatingSession(request.toadletContext) - val parentId = request.httpRequest.getPartAsStringFailsafe("parent", 36) - val parent = if (parentId == "") currentSone.rootAlbum else webInterface.core.getAlbum(parentId) - val album = webInterface.core.createAlbum(currentSone, parent) + val description = soneRequest.httpRequest.getPartAsStringFailsafe("description", 256).trim() + val parentId = soneRequest.httpRequest.getPartAsStringFailsafe("parent", 36) + val parent = if (parentId == "") currentSone.rootAlbum else soneRequest.core.getAlbum(parentId) + val album = soneRequest.core.createAlbum(currentSone, parent) try { album.modify().apply { setTitle(name) - setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), description)) + setDescription(TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), description)) }.update() } catch (e: AlbumTitleMustNotBeEmpty) { throw RedirectException("emptyAlbumTitle.html") } - webInterface.core.touchConfiguration() + soneRequest.core.touchConfiguration() throw RedirectException("imageBrowser.html?album=${album.id}") } }