1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Image.Modifier.ImageTitleMustNotBeEmpty
4 import net.pterodactylus.sone.text.TextFilter
5 import net.pterodactylus.sone.utils.isPOST
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
12 * Page that lets the user edit title and description of an {@link Image}.
14 class EditImagePage(template: Template, webInterface: WebInterface):
15 SoneTemplatePage("editImage.html", template, "Page.EditImage.Title", webInterface, true) {
17 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
19 val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
20 if (!image.sone.isLocal) {
21 throw RedirectException("noPermission.html")
23 request.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
24 if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
25 image.album.moveImageUp(image)
26 webInterface.core.touchConfiguration()
27 } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
28 image.album.moveImageDown(image)
29 webInterface.core.touchConfiguration()
33 .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100))
34 .setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), request.httpRequest.getPartAsStringFailsafe("description", 1024)))
36 webInterface.core.touchConfiguration()
37 } catch (e: ImageTitleMustNotBeEmpty) {
38 throw RedirectException("emptyImageTitle.html")
41 throw RedirectException(returnPage)