mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Merge branch 'release-1.2.4' into gh33_ImproveTestCoverage
This commit is contained in:
@@ -18,7 +18,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
|
|
||||||
- name: Set up JDK
|
- name: Set up JDK
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
@@ -47,7 +47,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
|
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=grimsi_gameyfin
|
||||||
|
|
||||||
- name: Upload build artifact
|
- name: Upload build artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
|
|||||||
@@ -254,6 +254,21 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<!-- JaCoCo coverage report -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<goals>
|
||||||
|
<goal>report-aggregate</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>verify</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,16 @@ import de.grimsi.gameyfin.entities.DetectedGame;
|
|||||||
import de.grimsi.gameyfin.service.DownloadService;
|
import de.grimsi.gameyfin.service.DownloadService;
|
||||||
import de.grimsi.gameyfin.service.GameService;
|
import de.grimsi.gameyfin.service.GameService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -44,17 +49,33 @@ public class GamesController {
|
|||||||
return gameService.getAllMappings();
|
return gameService.getAllMappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value="/game/{slug}/download")
|
@GetMapping(value = "/game/{slug}/download")
|
||||||
public ResponseEntity<StreamingResponseBody> downloadGameFiles(@PathVariable String slug) {
|
public ResponseEntity<StreamingResponseBody> downloadGameFiles(@PathVariable String slug) {
|
||||||
|
|
||||||
DetectedGame game = gameService.getDetectedGame(slug);
|
DetectedGame game = gameService.getDetectedGame(slug);
|
||||||
|
|
||||||
String downloadFileName = downloadService.getDownloadFileName(game);
|
String downloadFileName = downloadService.getDownloadFileName(game);
|
||||||
|
long downloadFileSize = downloadService.getDownloadFileSize(game);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"%s\"".formatted(downloadFileName));
|
||||||
|
headers.add(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate");
|
||||||
|
headers.add(HttpHeaders.PRAGMA, "no-cache");
|
||||||
|
headers.add(HttpHeaders.EXPIRES, "0");
|
||||||
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
if (downloadFileSize > 0) {
|
||||||
|
headers.setContentLength(downloadFileSize);
|
||||||
|
}
|
||||||
|
|
||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
.ok()
|
.ok()
|
||||||
.header("Content-Disposition", "attachment; filename=\"%s\"".formatted(downloadFileName))
|
.headers(headers)
|
||||||
.body(out -> downloadService.sendGamefilesToClient(game, out));
|
.body(out -> downloadService.sendGamefilesToClient(game, out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/game/{slug}/refresh", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public DetectedGame refreshGame(@PathVariable String slug) {
|
||||||
|
return gameService.refreshGame(slug);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.catalina.connector.ClientAbortException;
|
import org.apache.catalina.connector.ClientAbortException;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
@@ -34,6 +35,23 @@ public class DownloadService {
|
|||||||
return getFilenameWithExtension(path) + ".zip";
|
return getFilenameWithExtension(path) + ".zip";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getDownloadFileSize(DetectedGame game) {
|
||||||
|
Path path = Path.of(game.getPath());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!path.toFile().isDirectory()) {
|
||||||
|
long fileSize = filesystemService.getSizeOnDisk(path);
|
||||||
|
log.info("Calculated file size for {} ({} MB).", path, Math.divideExact(fileSize, 1000000L));
|
||||||
|
return fileSize;
|
||||||
|
} else {
|
||||||
|
// return zero since we cannot set content length for ZipOutputStreams that are used to archive directories
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DownloadAbortedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Resource sendImageToClient(String imageId) {
|
public Resource sendImageToClient(String imageId) {
|
||||||
String filename = "%s.png".formatted(imageId);
|
String filename = "%s.png".formatted(imageId);
|
||||||
return filesystemService.getFileFromCache(filename);
|
return filesystemService.getFileFromCache(filename);
|
||||||
@@ -78,6 +96,7 @@ public class DownloadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendGamefilesAsZipToClient(Path path, OutputStream outputStream) {
|
private void sendGamefilesAsZipToClient(Path path, OutputStream outputStream) {
|
||||||
|
log.info("Archiving game path {} for download...", path);
|
||||||
ZipOutputStream zos = new ZipOutputStream(outputStream) {{
|
ZipOutputStream zos = new ZipOutputStream(outputStream) {{
|
||||||
def.setLevel(Deflater.NO_COMPRESSION);
|
def.setLevel(Deflater.NO_COMPRESSION);
|
||||||
}};
|
}};
|
||||||
@@ -87,6 +106,7 @@ public class DownloadService {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||||
zos.putNextEntry(new ZipEntry(path.relativize(file).toString()));
|
zos.putNextEntry(new ZipEntry(path.relativize(file).toString()));
|
||||||
|
log.debug("Adding file {} to archive...", file);
|
||||||
Files.copy(file, zos);
|
Files.copy(file, zos);
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import de.grimsi.gameyfin.mapper.GameMapper;
|
|||||||
import de.grimsi.gameyfin.repositories.DetectedGameRepository;
|
import de.grimsi.gameyfin.repositories.DetectedGameRepository;
|
||||||
import de.grimsi.gameyfin.repositories.UnmappableFileRepository;
|
import de.grimsi.gameyfin.repositories.UnmappableFileRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
@@ -20,6 +21,7 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class GameService {
|
public class GameService {
|
||||||
|
|
||||||
@@ -87,6 +89,17 @@ public class GameService {
|
|||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Path '%s' not in database".formatted(path));
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Path '%s' not in database".formatted(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DetectedGame refreshGame(String slug) {
|
||||||
|
Optional<DetectedGame> optionalDetectedGame = detectedGameRepository.findById(slug);
|
||||||
|
|
||||||
|
if (optionalDetectedGame.isPresent()) {
|
||||||
|
log.info("Refreshing game with slug '{}'", slug);
|
||||||
|
return mapDetectedGame(optionalDetectedGame.get(), slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Game with slug '%s' not found in database".formatted(slug));
|
||||||
|
}
|
||||||
|
|
||||||
private DetectedGame mapUnmappableFile(UnmappableFile unmappableFile, String slug) {
|
private DetectedGame mapUnmappableFile(UnmappableFile unmappableFile, String slug) {
|
||||||
Igdb.Game igdbGame = igdbWrapper.getGameBySlug(slug)
|
Igdb.Game igdbGame = igdbWrapper.getGameBySlug(slug)
|
||||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Game with slug '%s' does not exist on IGDB.".formatted(slug)));
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Game with slug '%s' does not exist on IGDB.".formatted(slug)));
|
||||||
@@ -106,8 +119,6 @@ public class GameService {
|
|||||||
DetectedGame game = gameMapper.toDetectedGame(igdbGame, Path.of(existingGame.getPath()));
|
DetectedGame game = gameMapper.toDetectedGame(igdbGame, Path.of(existingGame.getPath()));
|
||||||
game = detectedGameRepository.save(game);
|
game = detectedGameRepository.save(game);
|
||||||
|
|
||||||
detectedGameRepository.deleteById(existingGame.getSlug());
|
|
||||||
|
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ export interface GamesApi {
|
|||||||
getGame(slug: String): Observable<DetectedGameDto>;
|
getGame(slug: String): Observable<DetectedGameDto>;
|
||||||
getGameOverviews(): Observable<GameOverviewDto[]>;
|
getGameOverviews(): Observable<GameOverviewDto[]>;
|
||||||
getAllGameMappings(): Observable<Map<string, string>>;
|
getAllGameMappings(): Observable<Map<string, string>>;
|
||||||
|
refreshGame(slug: String): Observable<DetectedGameDto>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<div fxLayout="column" fxFlex="0 1 75" fxLayoutGap="16px" fxFlex.lt-lg="95">
|
<div fxLayout="column" fxFlex="0 1 75" fxLayoutGap="16px" fxFlex.lt-lg="95">
|
||||||
<div fxLayout="row" fxLayout.lt-lg="column" fxLayoutGap="16px">
|
<div fxLayout="row" fxLayout.lt-lg="column" fxLayoutGap="16px">
|
||||||
|
|
||||||
<mat-card fxFlex="60" fxLayout="row" fxLayout.lt-lg="column" fxLayoutGap="16px">
|
<mat-card fxFlex="100" fxLayout="row" fxLayout.lt-lg="column" fxLayoutGap="16px">
|
||||||
<div fxLayoutAlign="start" fxLayoutAlign.lt-lg="center">
|
<div fxLayoutAlign="start" fxLayoutAlign.lt-lg="center">
|
||||||
<img src="v1/images/{{game.coverId}}" style="max-height: 352px" alt="Game cover">
|
<img src="v1/images/{{game.coverId}}" style="max-height: 352px" alt="Game cover">
|
||||||
</div>
|
</div>
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
<div *ngIf="companiesWithLogo.length > 0">
|
<div *ngIf="companiesWithLogo.length > 0">
|
||||||
<h2>Developed by</h2>
|
<h2>Developed by</h2>
|
||||||
<div fxLayout="row wrap" fxLayoutGap="8px grid">
|
<div fxLayout="row wrap" fxLayoutGap="8px grid">
|
||||||
<div *ngFor="let company of companiesWithLogo">
|
<div *ngFor="let company of companiesWithLogo" class="company-logos">
|
||||||
<img style="height: 52px;" src="v1/images/{{company.logoId}}" alt="{{company.name}}" [matTooltip]="company.name">
|
<img src="v1/images/{{company.logoId}}" alt="{{company.name}}" [matTooltip]="company.name">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,6 +33,9 @@
|
|||||||
<div fxLayout="column" fxFlex="40" fxLayoutGap="16px">
|
<div fxLayout="column" fxFlex="40" fxLayoutGap="16px">
|
||||||
|
|
||||||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px">
|
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px">
|
||||||
|
<button mat-raised-button color="secondary" (click)="refreshGame()" title="Refresh metadata">
|
||||||
|
<mat-icon>refresh</mat-icon>
|
||||||
|
</button>
|
||||||
<button mat-raised-button color="primary" (click)="downloadGame()">
|
<button mat-raised-button color="primary" (click)="downloadGame()">
|
||||||
<mat-icon>download</mat-icon>
|
<mat-icon>download</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
.mat-card {
|
||||||
|
// min-height: max-content;
|
||||||
|
|
||||||
|
.company-logos img {
|
||||||
|
max-height: 52px;
|
||||||
|
max-width: 260px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,24 @@ export class GameDetailViewComponent {
|
|||||||
this.gamesService.downloadGame(this.game.slug);
|
this.gamesService.downloadGame(this.game.slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public refreshGame(): void {
|
||||||
|
this.gamesService.refreshGame(this.game.slug).subscribe({
|
||||||
|
next: game => {
|
||||||
|
this.game = game;
|
||||||
|
if(game.companies !== undefined) {
|
||||||
|
this.companiesWithLogo = game.companies.filter(c => c.logoId !== undefined && c.logoId.length > 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: error => {
|
||||||
|
if (error.status === 404) {
|
||||||
|
this.router.navigate(['/library']);
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public bytesAsHumanReadableString(bytes: number): string {
|
public bytesAsHumanReadableString(bytes: number): string {
|
||||||
const thresh = 1024;
|
const thresh = 1024;
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ export class GamesService implements GamesApi {
|
|||||||
window.open(`v1${this.apiPath}/game/${slug}/download`, '_top');
|
window.open(`v1${this.apiPath}/game/${slug}/download`, '_top');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshGame(slug: String): Observable<DetectedGameDto> {
|
||||||
|
return this.http.get<DetectedGameDto>(`${this.apiPath}/game/${slug}/refresh`);
|
||||||
|
}
|
||||||
|
|
||||||
getGameOverviews(): Observable<GameOverviewDto[]> {
|
getGameOverviews(): Observable<GameOverviewDto[]> {
|
||||||
return this.http.get<GameOverviewDto[]>(`${this.apiPath}/game-overviews`);
|
return this.http.get<GameOverviewDto[]>(`${this.apiPath}/game-overviews`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>de.grimsi</groupId>
|
<groupId>de.grimsi</groupId>
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.7.4</version>
|
<version>2.7.4</version>
|
||||||
<relativePath /> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
<url>scm:git:https://github.com/grimsi/gameyfin.git</url>
|
<url>scm:git:https://github.com/grimsi/gameyfin.git</url>
|
||||||
<developerConnection>scm:git:https://github.com/grimsi/gameyfin.git</developerConnection>
|
<developerConnection>scm:git:https://github.com/grimsi/gameyfin.git</developerConnection>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<sonar.organization>grimsi-github</sonar.organization>
|
<sonar.organization>grimsi-github</sonar.organization>
|
||||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
sonar.projectKey=grimsi_gameyfin
|
|
||||||
|
|
||||||
# Point SONAR to the compiled Java classes
|
# Point SONAR to the compiled Java classes
|
||||||
sonar.java.binaries=./backend/target
|
sonar.java.binaries=./backend/target
|
||||||
|
|||||||
Reference in New Issue
Block a user