-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
paladins-webservice/src/main/java/dev/luzifer/spring/ApplicationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
package dev.luzifer.spring; | ||
|
||
import dev.luzifer.data.access.GameDao; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan({"dev.luzifer.data.access"}) | ||
public class ApplicationConfiguration { | ||
|
||
@Bean | ||
public GameDao gameDao() { | ||
return new GameDao(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
paladins-webservice/src/main/java/dev/luzifer/spring/controller/DebugController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dev.luzifer.spring.controller; | ||
|
||
import dev.luzifer.Webservice; | ||
import dev.luzifer.spring.ApplicationAccessPoint; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
|
||
@RestController | ||
@RequestMapping(ApplicationAccessPoint.DEBUG) | ||
public class DebugController { | ||
|
||
@GetMapping(ApplicationAccessPoint.LATEST_LOG_DOWNLOAD) | ||
@ResponseStatus(HttpStatus.OK) | ||
public ResponseEntity<byte[]> downloadLatestLog(@PathVariable String apiKey, HttpServletResponse response) { | ||
if(couldNotVerifyApiKey(apiKey)) { | ||
Webservice.REST_LOGGER.info("Received unauthorized request to download latest log."); | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); | ||
} | ||
|
||
File logFile = Webservice.getCURRENT_LOG_FILE(); | ||
|
||
if (logFile != null && logFile.exists()) { | ||
try { | ||
byte[] logBytes = Files.readAllBytes(logFile.toPath()); | ||
|
||
response.setHeader("Content-Disposition", "attachment; filename=logfile.txt"); | ||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); | ||
|
||
OutputStream outputStream = response.getOutputStream(); | ||
outputStream.write(logBytes); | ||
outputStream.flush(); | ||
outputStream.close(); | ||
|
||
return ResponseEntity.ok().build(); | ||
} catch (IOException e) { | ||
Webservice.REST_LOGGER.severe("Error while downloading latest log."); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); | ||
} | ||
} | ||
|
||
Webservice.REST_LOGGER.severe("Could not find latest log file."); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); | ||
} | ||
|
||
private boolean couldNotVerifyApiKey(String key) { | ||
return !Webservice.getApiKey().equals(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters