Skip to content

Commit

Permalink
Merge branch 'master' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
GodCipher committed Sep 25, 2023
2 parents face034 + 1713e45 commit 5c7af00
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import dev.luzifer.data.access.shit.PlayerInfo;
import dev.luzifer.data.dto.ChampDto;
import dev.luzifer.data.dto.GameDto;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component("gameDao")
public class GameDao {

private final Map<String, Integer> mapCache = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;

@SpringBootApplication()
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
@PropertySource("classpath:application.properties")
public class Application {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class ApplicationAccessPoint {

public static final String API_KEY = "/{apiKey}"; // /{apiKey}

// debug
public static final String DEBUG = API_KEY + "/debug"; // /{apiKey}/debug
public static final String LATEST_LOG_DOWNLOAD = "/latestlog"; // /{apiKey}/debug/latestlog

// game
public static final String GAME = API_KEY + "/game"; // /{apiKey}/game
public static final String POST = "/post"; // /{apiKey}/game/post
Expand All @@ -21,4 +25,6 @@ public class ApplicationAccessPoint {
public static final String GET_COUNT_BANNED_CHAMPS = GET_COUNT + "/bannedchamps"; // /{apiKey}/game/get/count/bannedchamps
public static final String GET_COUNT_REGIONS = GET_COUNT + "/regions"; // /{apiKey}/game/get/count/regions
public static final String GET_COUNT_MAPS = GET_COUNT + "/maps"; // /{apiKey}/game/get/count/maps


}
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();
}
}
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);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.4</version>
<version>2.7.2</version>
<relativePath />
</parent>

Expand Down

0 comments on commit 5c7af00

Please sign in to comment.