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