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
11 import javax.inject.Inject
14 * Page that lets the user edit title and description of an {@link Image}.
16 class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface):
17 LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface) {
19 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
20 if (freenetRequest.isPOST) {
21 val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
22 if (!image.sone.isLocal) {
23 throw RedirectException("noPermission.html")
25 freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
26 if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
27 image.album.moveImageUp(image)
28 webInterface.core.touchConfiguration()
29 } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
30 image.album.moveImageDown(image)
31 webInterface.core.touchConfiguration()
35 .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100))
36 .setDescription(TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1024)))
38 webInterface.core.touchConfiguration()
39 } catch (e: ImageTitleMustNotBeEmpty) {
40 throw RedirectException("emptyImageTitle.html")
43 throw RedirectException(returnPage)