1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.text.TextFilter
4 import net.pterodactylus.sone.utils.headers
5 import net.pterodactylus.sone.utils.ifTrue
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.*
9 import javax.inject.Inject
12 * Page that stores a user’s album modifications.
14 @ToadletPath("editAlbum.ajax")
15 class EditAlbumAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
17 override fun createJsonObject(request: FreenetRequest) =
18 request.parameters["album"]!!
21 album.sone.isLocal.ifTrue {
23 request.parameters["moveLeft"] == "true" -> createSuccessJsonObject().apply {
24 put("sourceAlbumId", album.id)
25 put("destinationAlbumId", album.parent.moveAlbumUp(album).id)
27 request.parameters["moveRight"] == "true" -> createSuccessJsonObject().apply {
28 put("sourceAlbumId", album.id)
29 put("destinationAlbumId", album.parent.moveAlbumDown(album).id)
33 .setTitle(request.parameters["title"])
34 .setDescription(TextFilter.filter(request.headers["Host"], request.parameters["description"]))
36 createSuccessJsonObject()
37 .put("albumId", album.id)
38 .put("title", album.title)
39 .put("description", album.description)
40 } catch (e: IllegalStateException) {
41 createErrorJsonObject("invalid-album-title")
44 } ?: createErrorJsonObject("not-authorized")
45 } ?: createErrorJsonObject("invalid-album-id")