From 37bfba35c6c02d14942f853ca7e2d0bb90d7d1ed Mon Sep 17 00:00:00 2001 From: alterdekim Date: Thu, 23 Jan 2025 03:02:01 +0300 Subject: [PATCH] Making it portable --- .gitignore | 3 +- .../game/component/StartUpListener.java | 6 +- .../game/controller/FileServerController.java | 10 +- .../game/controller/StaticController.java | 9 - .../game/security/SpringSecurity.java | 8 +- .../alterdekim/game/service/MRTService.java | 5 +- .../game/storage/StorageProperties.java | 6 +- src/main/resources/templates/db.html | 4808 ----------------- src/main/resources/templates/index.html | 66 +- src/main/resources/templates/login.html | 4 +- src/main/resources/templates/main.html | 2 +- 11 files changed, 57 insertions(+), 4870 deletions(-) delete mode 100644 src/main/resources/templates/db.html diff --git a/.gitignore b/.gitignore index 6d091b7..b7ed972 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store +/cache/ diff --git a/src/main/java/com/alterdekim/game/component/StartUpListener.java b/src/main/java/com/alterdekim/game/component/StartUpListener.java index 3187a02..1a92316 100644 --- a/src/main/java/com/alterdekim/game/component/StartUpListener.java +++ b/src/main/java/com/alterdekim/game/component/StartUpListener.java @@ -141,6 +141,10 @@ public class StartUpListener { // todo: compile other swf's if( userService.findByUsername(ADMIN_USERNAME) != null ) { + + // todo: remove hardcoded cache folder + new File("cache/").mkdirs(); + Map root = new HashMap<>(); Map mr = new HashMap<>(); mr.put("MR", FlashMapper.objToMap(mrService.getAll())); @@ -149,7 +153,7 @@ public class StartUpListener { mr.put("MRT", FlashMapper.simpleToMap(mrtService.getAll())); root.put("resources", mr); - try { + try { // todo: and here too ( abolish hardcoded paths ) Files.write(Path.of("cache/resources.swf"), new FlashCompiler(new Java2Flash().convert(root)).compile(), StandardOpenOption.CREATE); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/alterdekim/game/controller/FileServerController.java b/src/main/java/com/alterdekim/game/controller/FileServerController.java index 3fc0c52..ca30420 100644 --- a/src/main/java/com/alterdekim/game/controller/FileServerController.java +++ b/src/main/java/com/alterdekim/game/controller/FileServerController.java @@ -21,14 +21,14 @@ public class FileServerController { @Autowired private FileSystemStorageService storageService; - @RequestMapping(value = "/static/{*resPath}", method = RequestMethod.GET) + @RequestMapping(value = {"/file/**"}, method = RequestMethod.GET) @ResponseBody - public ResponseEntity serveFile(@PathVariable("resPath") String resPath, HttpServletRequest request) { + public ResponseEntity serveFile(HttpServletRequest request) { try { - String filename = request.getRequestURL().substring(request.getRequestURL().indexOf("/static/")+8); + String filename = request.getRequestURI().substring(6); Path path = storageService.load(filename); - return ResponseEntity.ok().contentType(switch(resPath.substring(1, 4)) { - case "swf" -> MediaType.parseMediaType("application/x-shockwave-flash"); + return ResponseEntity.ok().contentType(switch(filename.substring(0, 3)) { + case "swf", "pub" -> MediaType.parseMediaType("application/x-shockwave-flash"); case "css" -> MediaType.parseMediaType("text/css"); case "_js" -> MediaType.parseMediaType("text/javascript"); case "img" -> MediaType.parseMediaType("image/jpeg"); diff --git a/src/main/java/com/alterdekim/game/controller/StaticController.java b/src/main/java/com/alterdekim/game/controller/StaticController.java index 2b58e7b..232f786 100644 --- a/src/main/java/com/alterdekim/game/controller/StaticController.java +++ b/src/main/java/com/alterdekim/game/controller/StaticController.java @@ -19,10 +19,6 @@ import java.nio.charset.StandardCharsets; @Controller public class StaticController { - @Autowired - private GoodsService goodsService; - - @GetMapping("/main") public String mainPage() { return "main"; @@ -33,11 +29,6 @@ public class StaticController { return "index"; } - @GetMapping("/push") - public String pushPage() { - return "db"; - } - @GetMapping("/crossdomain.xml") public ResponseEntity crossdomain() { return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body("\n" + diff --git a/src/main/java/com/alterdekim/game/security/SpringSecurity.java b/src/main/java/com/alterdekim/game/security/SpringSecurity.java index e098da1..866a1e4 100644 --- a/src/main/java/com/alterdekim/game/security/SpringSecurity.java +++ b/src/main/java/com/alterdekim/game/security/SpringSecurity.java @@ -34,13 +34,7 @@ public class SpringSecurity { .requestMatchers("/").permitAll() .requestMatchers("/login").permitAll() .requestMatchers("/main").hasAnyAuthority("ROLE_USER") - .requestMatchers("/_js/**").permitAll() - .requestMatchers("/img/**").permitAll() - .requestMatchers("/png/**").hasAnyAuthority("ROLE_USER") - .requestMatchers("/swf/**").hasAnyAuthority("ROLE_USER") - .requestMatchers("/avatar.swf").hasAnyAuthority("ROLE_USER") - .requestMatchers("/pub/**").permitAll() - .requestMatchers("/css/**").permitAll() + .requestMatchers("/file/**").permitAll() .requestMatchers("/ConstructorACHandler.ashx").permitAll() .requestMatchers("/crossdomain.xml").permitAll() .requestMatchers("/async/**").hasAnyAuthority("ROLE_USER") diff --git a/src/main/java/com/alterdekim/game/service/MRTService.java b/src/main/java/com/alterdekim/game/service/MRTService.java index ae40ca1..f2037bf 100644 --- a/src/main/java/com/alterdekim/game/service/MRTService.java +++ b/src/main/java/com/alterdekim/game/service/MRTService.java @@ -17,9 +17,12 @@ public class MRTService implements OutputObjectCallback { @Autowired private MRTRepository repository; + // todo: abolish hardcoded file path somehow @Override public void onOutputObjectReady(Object o) { - this.repository.save((MediaResourcePath) o); + var pathObj = (MediaResourcePath) o; + pathObj.setVal("file/"+pathObj.getVal()); + this.repository.save(pathObj); } public List getAll() { diff --git a/src/main/java/com/alterdekim/game/storage/StorageProperties.java b/src/main/java/com/alterdekim/game/storage/StorageProperties.java index 3f6df00..f1eb86b 100644 --- a/src/main/java/com/alterdekim/game/storage/StorageProperties.java +++ b/src/main/java/com/alterdekim/game/storage/StorageProperties.java @@ -2,11 +2,13 @@ package com.alterdekim.game.storage; import lombok.Getter; import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @Setter @Getter -@ConfigurationProperties("storage") +@ConfigurationProperties(prefix = "storage") public class StorageProperties { - private String location = "static"; + @Value("location") private String location; } \ No newline at end of file diff --git a/src/main/resources/templates/db.html b/src/main/resources/templates/db.html deleted file mode 100644 index db9de19..0000000 --- a/src/main/resources/templates/db.html +++ /dev/null @@ -1,4808 +0,0 @@ - - - - - Title - - - - - - \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 70015ca..55d4952 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -3,14 +3,14 @@ PolyDarker - - - - + + + + - - - + + + @@ -19,7 +19,7 @@
- Закрыть + Закрыть
@@ -46,12 +46,12 @@ Забыл пароль?
- Загрузка... + Загрузка...
- Закрыть + Закрыть @@ -68,7 +68,7 @@