1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
4 import net.pterodactylus.sone.text.TextFilter
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8 import net.pterodactylus.util.web.Method.POST
11 * Page that lets the user create a new album.
13 class CreateAlbumPage(template: Template, webInterface: WebInterface):
14 SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) {
16 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
17 if (request.method == POST) {
18 val name = request.httpRequest.getPartAsStringFailsafe("name", 64).trim()
20 templateContext["nameMissing"] = true
23 val description = request.httpRequest.getPartAsStringFailsafe("description", 256).trim()
24 val currentSone = webInterface.getCurrentSoneCreatingSession(request.toadletContext)
25 val parentId = request.httpRequest.getPartAsStringFailsafe("parent", 36)
26 val parent = if (parentId == "") currentSone.rootAlbum else webInterface.core.getAlbum(parentId)
27 val album = webInterface.core.createAlbum(currentSone, parent)
29 album.modify().apply {
31 setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), description))
33 } catch (e: AlbumTitleMustNotBeEmpty) {
34 throw RedirectException("emptyAlbumTitle.html")
36 webInterface.core.touchConfiguration()
37 throw RedirectException("imageBrowser.html?album=${album.id}")