Added detailed library scan result

Small layout fixes in game detail view
This commit is contained in:
grimsi
2022-08-23 13:17:56 +02:00
parent 3325f066bd
commit 3877b5defd
16 changed files with 159 additions and 33 deletions
@@ -0,0 +1,10 @@
package de.grimsi.gameyfin.dto;
import lombok.Data;
@Data
public class ImageDownloadResultDto {
private int coverDownloads;
private int screenshotDownloads;
private int companyLogoDownloads;
}
@@ -0,0 +1,13 @@
package de.grimsi.gameyfin.dto;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class LibraryScanResult {
private int newGames;
private int deletedGames;
private int newUnmappableFiles;
private int totalGames;
}
@@ -0,0 +1,21 @@
package de.grimsi.gameyfin.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LibraryScanResultDto {
private int newGames;
private int deletedGames;
private int newUnmappableFiles;
private int totalGames;
private int coverDownloads;
private int screenshotDownloads;
private int companyLogoDownloads;
private int scanDuration;
}
@@ -1,5 +1,8 @@
package de.grimsi.gameyfin.rest;
import de.grimsi.gameyfin.dto.ImageDownloadResultDto;
import de.grimsi.gameyfin.dto.LibraryScanResult;
import de.grimsi.gameyfin.dto.LibraryScanResultDto;
import de.grimsi.gameyfin.service.DownloadService;
import de.grimsi.gameyfin.service.ImageService;
import de.grimsi.gameyfin.service.LibraryService;
@@ -7,6 +10,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -29,19 +33,45 @@ public class LibraryController {
private final ImageService imageService;
@GetMapping(value = "/scan", produces = MediaType.APPLICATION_JSON_VALUE)
public void scanLibrary(@RequestParam(value = "download_images", defaultValue = "true") boolean downloadImages) {
libraryService.scanGameLibrary();
public LibraryScanResultDto scanLibrary(@RequestParam(value = "download_images", defaultValue = "true") boolean downloadImages) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
if(downloadImages) downloadImages();
LibraryScanResultDto lscDto = new LibraryScanResultDto();
LibraryScanResult lsc = libraryService.scanGameLibrary();
lscDto.setNewGames(lsc.getNewGames());
lscDto.setDeletedGames(lsc.getDeletedGames());
lscDto.setNewUnmappableFiles(lsc.getNewUnmappableFiles());
lscDto.setTotalGames(lsc.getTotalGames());
if(downloadImages) {
ImageDownloadResultDto idrDto = downloadImages();
lscDto.setCoverDownloads(idrDto.getCoverDownloads());
lscDto.setScreenshotDownloads(idrDto.getScreenshotDownloads());
lscDto.setCompanyLogoDownloads(idrDto.getCompanyLogoDownloads());
}
stopWatch.stop();
lscDto.setScanDuration((int) stopWatch.getTotalTimeSeconds());
log.info("Library scan completed in {} seconds.", (int) stopWatch.getTotalTimeSeconds());
return lscDto;
}
@GetMapping(value = "/download-images")
public void downloadImages() {
imageService.downloadGameCoversFromIgdb();
imageService.downloadGameScreenshotsFromIgdb();
imageService.downloadCompanyLogosFromIgdb();
public ImageDownloadResultDto downloadImages() {
ImageDownloadResultDto idrDto = new ImageDownloadResultDto();
idrDto.setCoverDownloads(imageService.downloadGameCoversFromIgdb());
idrDto.setScreenshotDownloads(imageService.downloadGameScreenshotsFromIgdb());
idrDto.setCompanyLogoDownloads(imageService.downloadCompanyLogosFromIgdb());
log.info("Downloading images completed.");
return idrDto;
}
@GetMapping(value = "/files", produces = MediaType.APPLICATION_JSON_VALUE)
@@ -42,7 +42,7 @@ public class ImageService {
igdbImageClient = webclientBuilder.baseUrl(IgdbApiProperties.IMAGES_BASE_URL).build();
}
public void downloadGameCoversFromIgdb() {
public int downloadGameCoversFromIgdb() {
StopWatch stopWatch = new StopWatch();
log.info("Starting game cover download...");
@@ -57,9 +57,10 @@ public class ImageService {
stopWatch.stop();
log.info("Downloaded {} covers in {} seconds.", downloadCount, (int) stopWatch.getTotalTimeSeconds());
return downloadCount;
}
public void downloadGameScreenshotsFromIgdb() {
public int downloadGameScreenshotsFromIgdb() {
StopWatch stopWatch = new StopWatch();
log.info("Starting game screenshot download...");
@@ -74,9 +75,10 @@ public class ImageService {
stopWatch.stop();
log.info("Downloaded {} screenshots in {} seconds.", downloadCount, (int) stopWatch.getTotalTimeSeconds());
return downloadCount;
}
public void downloadCompanyLogosFromIgdb() {
public int downloadCompanyLogosFromIgdb() {
StopWatch stopWatch = new StopWatch();
log.info("Starting company logo download...");
@@ -93,6 +95,7 @@ public class ImageService {
stopWatch.stop();
log.info("Downloaded {} company logos in {} seconds.", downloadCount, (int) stopWatch.getTotalTimeSeconds());
return downloadCount;
}
private int saveImagesIntoCache(MultiValueMap<String, String> entityToImageIds, String imageSize, String imageType, String entityType) {
@@ -2,6 +2,7 @@ package de.grimsi.gameyfin.service;
import com.igdb.proto.Igdb;
import de.grimsi.gameyfin.dto.AutocompleteSuggestionDto;
import de.grimsi.gameyfin.dto.LibraryScanResult;
import de.grimsi.gameyfin.entities.DetectedGame;
import de.grimsi.gameyfin.entities.UnmappableFile;
import de.grimsi.gameyfin.igdb.IgdbWrapper;
@@ -57,7 +58,7 @@ public class LibraryService {
return gamefiles;
}
public void scanGameLibrary() {
public LibraryScanResult scanGameLibrary() {
StopWatch stopWatch = new StopWatch();
log.info("Starting scan...");
@@ -120,6 +121,13 @@ public class LibraryService {
log.info("Scan finished in {} seconds: Found {} new games, deleted {} games, could not map {} files/folders, {} games total.",
(int) stopWatch.getTotalTimeSeconds(), newDetectedGames.size(), deletedGames.size() + deletedUnmappableFiles.size(), newUnmappedFilesCounter.get(), detectedGameRepository.count());
return LibraryScanResult.builder()
.newGames(newDetectedGames.size())
.deletedGames(deletedGames.size() + deletedUnmappableFiles.size())
.newUnmappableFiles(newUnmappedFilesCounter.get())
.totalGames((int) detectedGameRepository.count())
.build();
}
public List<AutocompleteSuggestionDto> getAutocompleteSuggestions(String searchTerm, int limit) {