1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.data.Image.Modifier.*
5 import net.pterodactylus.sone.main.*
6 import net.pterodactylus.sone.text.*
7 import net.pterodactylus.sone.utils.*
8 import net.pterodactylus.sone.web.*
9 import net.pterodactylus.sone.web.page.*
10 import net.pterodactylus.util.template.*
14 * Page that lets the user edit title and description of an {@link Image}.
16 @ToadletPath("editImage.html")
17 class EditImagePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
18 LoggedInPage("Page.EditImage.Title", webInterface, loaders, templateRenderer) {
20 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
21 if (soneRequest.isPOST) {
22 val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: redirectTo("invalid.html")
23 if (!image.sone.isLocal) {
24 redirectTo("noPermission.html")
26 soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
27 if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
28 image.album.moveImageUp(image)
29 soneRequest.core.touchConfiguration()
30 } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
31 image.album.moveImageDown(image)
32 soneRequest.core.touchConfiguration()
36 .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
37 .setDescription(TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), soneRequest.httpRequest.getPartAsStringFailsafe("description", 1024)))
39 soneRequest.core.touchConfiguration()
40 } catch (e: ImageTitleMustNotBeEmpty) {
41 redirectTo("emptyImageTitle.html")
44 redirectTo(returnPage)