mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-13 16:40:01 +00:00
feat(refresh): added refresh button on game detail view to refresh metadata
Resolves grimsi/gameyfin#45
This commit is contained in:
@@ -44,7 +44,7 @@ public class GamesController {
|
||||
return gameService.getAllMappings();
|
||||
}
|
||||
|
||||
@GetMapping(value="/game/{slug}/download")
|
||||
@GetMapping(value = "/game/{slug}/download")
|
||||
public ResponseEntity<StreamingResponseBody> downloadGameFiles(@PathVariable String slug) {
|
||||
|
||||
DetectedGame game = gameService.getDetectedGame(slug);
|
||||
@@ -57,4 +57,9 @@ public class GamesController {
|
||||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.grimsi.gameyfin.mapper.GameMapper;
|
||||
import de.grimsi.gameyfin.repositories.DetectedGameRepository;
|
||||
import de.grimsi.gameyfin.repositories.UnmappableFileRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
@@ -20,6 +21,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Service
|
||||
public class GameService {
|
||||
|
||||
@@ -87,6 +89,17 @@ public class GameService {
|
||||
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) {
|
||||
Igdb.Game igdbGame = igdbWrapper.getGameBySlug(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()));
|
||||
game = detectedGameRepository.save(game);
|
||||
|
||||
detectedGameRepository.deleteById(existingGame.getSlug());
|
||||
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ export interface GamesApi {
|
||||
getGame(slug: String): Observable<DetectedGameDto>;
|
||||
getGameOverviews(): Observable<GameOverviewDto[]>;
|
||||
getAllGameMappings(): Observable<Map<string, string>>;
|
||||
refreshGame(slug: String): Observable<DetectedGameDto>;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
<div fxLayout="column" fxFlex="40" 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()">
|
||||
<mat-icon>download</mat-icon>
|
||||
</button>
|
||||
|
||||
@@ -48,6 +48,24 @@ export class GameDetailViewComponent {
|
||||
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 {
|
||||
const thresh = 1024;
|
||||
|
||||
|
||||
@@ -92,6 +92,10 @@ export class GamesService implements GamesApi {
|
||||
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[]> {
|
||||
return this.http.get<GameOverviewDto[]>(`${this.apiPath}/game-overviews`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user