X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateAlbumPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateAlbumPage.kt;h=3a628ddb90a0c417dd49940bff2a25e38f46ae1d;hp=0000000000000000000000000000000000000000;hb=de7568a82eb4150bf6d2b0553841b7b69f84c968;hpb=9acbc5bdec4ccb752e0856a501568b0bb6161579 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt new file mode 100644 index 0000000..3a628dd --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt @@ -0,0 +1,43 @@ +package net.pterodactylus.sone.web.pages + +import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty +import net.pterodactylus.sone.text.TextFilter +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 + +/** + * Page that lets the user create a new album. + */ +class CreateAlbumPage(template: Template, webInterface: WebInterface): + SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) { + + override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { + if (request.isPOST) { + val name = request.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) + try { + album.modify().apply { + setTitle(name) + setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), description)) + }.update() + } catch (e: AlbumTitleMustNotBeEmpty) { + throw RedirectException("emptyAlbumTitle.html") + } + webInterface.core.touchConfiguration() + throw RedirectException("imageBrowser.html?album=${album.id}") + } + } + +}