diff options
-rw-r--r-- | pom.xml | 6 | ||||
-rw-r--r-- | src/main/java/uk/co/blatech/blaears/controllers/BlauploadController.java | 41 |
2 files changed, 47 insertions, 0 deletions
@@ -66,6 +66,12 @@ <version>${jackson.version}</version> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.4</version> + </dependency> + </dependencies> <build> diff --git a/src/main/java/uk/co/blatech/blaears/controllers/BlauploadController.java b/src/main/java/uk/co/blatech/blaears/controllers/BlauploadController.java new file mode 100644 index 0000000..c58f654 --- /dev/null +++ b/src/main/java/uk/co/blatech/blaears/controllers/BlauploadController.java @@ -0,0 +1,41 @@ +package uk.co.blatech.blaears.controllers; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +import java.io.IOException; + +/** + * Takes notifications of uploads from Blaupload and sends them to IRC + */ +public class BlauploadController { + + private static final Logger log = Logger.getLogger(GitPushController.class); + + @RequestMapping(value = "/blaupload", method = RequestMethod.POST) + String notify(@RequestParam("url") String url, @RequestParam("channel") String channel, Model model) { + + if (StringUtils.isBlank(url) || StringUtils.isBlank(channel)) { + log.error("Invalid notification from blaupload: url=" + url + ", channel=" + channel); + model.addAttribute("result", "failed"); + return "blaupload"; + } + + try { + Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "echo " + channel + " New file uploaded: " + url + " | bash /home/smsd/msgrelay.bash "}); + } catch (IOException e) { + log.error("Failed to send message to " + channel + " for " + url); + e.printStackTrace(); + model.addAttribute("result", "failed"); + return "blaupload"; + } + + log.info("blaupload notification for " + url); + model.addAttribute("result", "OK"); + return "blaupload"; + } +} |