Added OpenAPI UI

Refactored some REST Endpoints
This commit is contained in:
Simon Grimme
2022-07-19 12:30:24 +02:00
parent a3e5f59795
commit 6b89690180
4 changed files with 26 additions and 13 deletions
+7
View File
@@ -36,6 +36,13 @@
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<!-- OpenAPI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
<!-- Webclient Rate limiter -->
<dependency>
<groupId>io.github.resilience4j</groupId>
@@ -2,7 +2,6 @@ package de.grimsi.gameyfin.rest;
import de.grimsi.gameyfin.service.FilesystemService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.repository.query.Param;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -23,14 +22,14 @@ public class LibraryController {
private final FilesystemService filesystemService;
@GetMapping(value = "/scan", produces = MediaType.APPLICATION_JSON_VALUE)
public void scanLibrary(@RequestParam("download_images") boolean downloadImages) {
public void scanLibrary(@RequestParam(value = "download_images", defaultValue = "true") boolean downloadImages) {
filesystemService.scanGameLibrary();
if(downloadImages) populateCache();
if(downloadImages) downloadImages();
}
@GetMapping(value = "/populate-cache")
public void populateCache() {
@GetMapping(value = "/download_images")
public void downloadImages() {
filesystemService.downloadGameCovers();
filesystemService.downloadGameScreenshots();
filesystemService.downloadCompanyLogos();
@@ -7,7 +7,6 @@ import de.grimsi.gameyfin.entities.UnmappableFile;
import de.grimsi.gameyfin.igdb.IgdbApiProperties;
import de.grimsi.gameyfin.igdb.IgdbWrapper;
import de.grimsi.gameyfin.mapper.GameMapper;
import de.grimsi.gameyfin.repositories.CompanyRepository;
import de.grimsi.gameyfin.repositories.DetectedGameRepository;
import de.grimsi.gameyfin.repositories.UnmappableFileRepository;
import lombok.extern.slf4j.Slf4j;
@@ -29,6 +28,7 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
import org.springframework.web.server.ResponseStatusException;
import reactor.core.publisher.Flux;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -64,7 +64,14 @@ public class FilesystemService {
@Autowired
private UnmappableFileRepository unmappableFileRepository;
private WebClient igdbImageClient = WebClient.create(IgdbApiProperties.IMAGES_BASE_URL);
@Autowired
private WebClient.Builder webclientBuilder;
private WebClient igdbImageClient;
@PostConstruct
public void init() {
igdbImageClient = webclientBuilder.baseUrl(IgdbApiProperties.IMAGES_BASE_URL).build();
}
public List<Path> getGameFiles() {
@@ -141,11 +148,11 @@ public class FilesystemService {
log.info("Starting game cover download...");
stopWatch.start();
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>(
MultiValueMap<String, String> gameToImageIds = new LinkedMultiValueMap<>(
detectedGameRepository.findAll().stream()
.collect(Collectors.toMap(DetectedGame::getTitle, g -> Collections.singletonList(g.getCoverId()))));
int downloadCount = downloadImagesIntoCache(multiValueMap, IgdbApiProperties.COVER_IMAGE_SIZE, "cover", "game");
int downloadCount = downloadImagesIntoCache(gameToImageIds, IgdbApiProperties.COVER_IMAGE_SIZE, "cover", "game");
stopWatch.stop();
@@ -175,13 +182,13 @@ public class FilesystemService {
log.info("Starting company logo download...");
stopWatch.start();
Map<String, List<String>> test = detectedGameRepository.findAll().stream()
Map<String, List<String>> companyToLogoIdMap = detectedGameRepository.findAll().stream()
.flatMap(g -> g.getCompanies().stream())
.collect(Collectors.toMap(Company::getName, c -> Collections.singletonList(c.getLogoId()), (c1, c2) -> c1));
MultiValueMap<String, String> gamesToImageIds = new LinkedMultiValueMap<>(test);
MultiValueMap<String, String> companiesToLogoIds = new LinkedMultiValueMap<>(companyToLogoIdMap);
int downloadCount = downloadImagesIntoCache(gamesToImageIds, IgdbApiProperties.LOGO_IMAGE_SIZE, "logo", "company");
int downloadCount = downloadImagesIntoCache(companiesToLogoIds, IgdbApiProperties.LOGO_IMAGE_SIZE, "logo", "company");
stopWatch.stop();
+1 -1
View File
@@ -1,5 +1,5 @@
gameyfin:
root: \\NAS-Simon\Öffentlich\Spiele
root: C:\Projects\privat\gameyfin-library
cache: ${gameyfin.root}\.gameyfin\cache
db: ${gameyfin.root}\.gameyfin\db # Currently unused
igdb: