Created JSP Home and Scan pages; moved to use war

This commit is contained in:
itdominator 2023-09-22 16:39:07 -05:00
parent 366f1f7e69
commit 8487384eda
12 changed files with 122 additions and 24 deletions

View File

@ -13,6 +13,7 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>ITDominator Thumbnailer</name> <name>ITDominator Thumbnailer</name>
<description>A thumbnailer api for files.</description> <description>A thumbnailer api for files.</description>
<packaging>war</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -51,6 +52,10 @@
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId> <artifactId>spring-security-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency> <dependency>

View File

@ -2,6 +2,8 @@ package com.itdominator.api;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -9,7 +11,12 @@ import org.springframework.context.annotation.Configuration;
@SpringBootApplication @SpringBootApplication
@ComponentScan("com.itdominator.api") @ComponentScan("com.itdominator.api")
@Configuration @Configuration
public class ThumbnailApiApplication { public class ThumbnailApiApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ThumbnailApiApplication.class);
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ThumbnailApiApplication.class, args); SpringApplication.run(ThumbnailApiApplication.class, args);

View File

@ -1,30 +1,39 @@
package com.itdominator.api.controller; package com.itdominator.api.controller;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor; import com.itdominator.api.dto.ScanQuery;
import com.itdominator.api.dto.User;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@RestController
@EnableMethodSecurity(securedEnabled = true, prePostEnabled = true) @Controller
@RequiredArgsConstructor
@Slf4j @Slf4j
@Validated
public class BaseController { public class BaseController {
@GetMapping({"/", "home"})
@PreAuthorize("hasRole('User')") public String index() {
// @PreAuthorize("hashPermission('User')") return "index";
@GetMapping("/")
public String root() {
return "<h1>Hello, World!</h1>";
} }
@GetMapping("/register")
public String register(Model model) {
model.addAttribute("user", new User());
return "register";
}
@GetMapping("/submit-for-scan")
public String submitForScan(Model model) {
model.addAttribute("scan_query", new ScanQuery());
return "submit-for-scan";
}
} }

View File

@ -13,11 +13,13 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.itdominator.api.dto.ScanQuery;
import com.itdominator.api.dto.ThumbnailDto; import com.itdominator.api.dto.ThumbnailDto;
import com.itdominator.api.dto.ThumbnailSearchCriteria; import com.itdominator.api.dto.ThumbnailSearchCriteria;
import com.itdominator.api.entities.Thumbnails; import com.itdominator.api.entities.Thumbnails;
@ -72,6 +74,7 @@ public class ThumbnailerApiController {
return thumbnailerService.getThumbnailByIdOrHashQuery(criteria); return thumbnailerService.getThumbnailByIdOrHashQuery(criteria);
} }
// @PreAuthorize("hashPermission('User')")
@PreAuthorize("hasRole('Admin')") @PreAuthorize("hasRole('Admin')")
@GetMapping("/get-all-thumbnails") @GetMapping("/get-all-thumbnails")
public List<ThumbnailDto> getAllThumbnails() { public List<ThumbnailDto> getAllThumbnails() {
@ -79,9 +82,11 @@ public class ThumbnailerApiController {
} }
@PreAuthorize("hasRole('User')") @PreAuthorize("hasRole('User')")
@GetMapping("/temp-videos-list-test") @PostMapping("/scan-target")
public Set<String> getAllVideoFiles() throws IOException { public Set<String> scanTarget(
Set<Path> paths = thumbnailer.collectVideoFilePaths("/home/abaddon/Downloads"); @ModelAttribute("scan_query") ScanQuery query
) throws IOException {
Set<Path> paths = thumbnailer.collectVideoFilePaths(query.getPath());
Set<String> files = new HashSet<>(); Set<String> files = new HashSet<>();
thumbnailer.generateThumbnails(paths); thumbnailer.generateThumbnails(paths);

View File

@ -0,0 +1,10 @@
package com.itdominator.api.dto;
import lombok.Data;
@Data
public class ScanQuery {
private String path;
}

View File

@ -0,0 +1,11 @@
package com.itdominator.api.dto;
import lombok.Data;
@Data
public class User {
private String email;
private String password;
}

View File

@ -1,5 +1,8 @@
server.port=8999 server.port=8999
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp
spring.security.user.name=root spring.security.user.name=root
spring.security.user.password=toor spring.security.user.password=toor
spring.security.user.roles=User,Admin spring.security.user.roles=User,Admin

View File

@ -0,0 +1,15 @@
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>Thumbnailer</title>
</head>
<body>
<ul>
<li>
<a href="/submit-for-scan">Manual Scanner</a>
<a href="/register">Register</a>
</li>
</ul>
</body>
</html>

View File

@ -0,0 +1,17 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<title>User Registration</title>
</head>
<body>
<form:form method="POST" modelAttribute="user">
<form:label path="email">Email: </form:label>
<form:input path="email" type="text"/>
<form:label path="password">Password: </form:label>
<form:input path="password" type="password" />
<input type="submit" value="Submit" />
</form:form>
</body>
</html>

View File

@ -0,0 +1,15 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<title>Manual Scan</title>
</head>
<body>
<form:form method="POST" action="scan-target" modelAttribute="scan_query">
<form:label path="path">Scan Path: </form:label>
<form:input path="path" type="text"/>
<input type="submit" value="Scan" />
</form:form>
</body>
</html>

View File

@ -12,6 +12,7 @@ function main() {
echo "Working Dir: " $(pwd) echo "Working Dir: " $(pwd)
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk/" export JAVA_HOME="/usr/lib/jvm/java-17-openjdk/"
/usr/lib/jvm/java-17-openjdk/bin/java -jar ./target/thumbnailer-api-0.0.1-SNAPSHOT.jar # /usr/lib/jvm/java-17-openjdk/bin/java -jar ./target/thumbnailer-api-0.0.1-SNAPSHOT.jar
/usr/lib/jvm/java-17-openjdk/bin/java -jar ./target/thumbnailer-api-0.0.1-SNAPSHOT.war
} }
main "$@"; main "$@";