mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-13 16:40:01 +00:00
Implement file-system PoC
Implement proxy functionality for external APIs
This commit is contained in:
@@ -42,6 +42,13 @@
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- File handling -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -5,9 +5,11 @@ import de.grimsi.gameyfin.igdb.dto.IgdbGame;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.net.URI;
|
||||
@@ -28,7 +30,9 @@ public class IgdbWrapper {
|
||||
@Value("${gameyfin.igdb.config.preferred-platform}")
|
||||
private int preferredPlatform;
|
||||
|
||||
private final WebClient twitchApiClient = WebClient.create();
|
||||
private final WebClient twitchApiClient = WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(HttpClient.create().proxyWithSystemProperties()))
|
||||
.build();
|
||||
|
||||
private WebClient igdbApiClient;
|
||||
|
||||
@@ -80,6 +84,7 @@ public class IgdbWrapper {
|
||||
}
|
||||
|
||||
igdbApiClient = WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(HttpClient.create().proxyWithSystemProperties()))
|
||||
.baseUrl("https://api.igdb.com/v4/")
|
||||
.defaultHeader("Client-ID", clientId)
|
||||
.defaultHeader("Authorization", "Bearer %s".formatted(accessToken.getAccessToken()))
|
||||
|
||||
@@ -3,6 +3,8 @@ package de.grimsi.gameyfin.rest;
|
||||
import de.grimsi.gameyfin.dto.GameDto;
|
||||
import de.grimsi.gameyfin.igdb.IgdbWrapper;
|
||||
import de.grimsi.gameyfin.igdb.dto.IgdbGame;
|
||||
import de.grimsi.gameyfin.service.FilesystemService;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -11,11 +13,18 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
public class GameyfinDevController {
|
||||
|
||||
@Autowired
|
||||
IgdbWrapper igdbWrapper;
|
||||
private IgdbWrapper igdbWrapper;
|
||||
|
||||
@Autowired
|
||||
private FilesystemService filesystemService;
|
||||
|
||||
@GetMapping(value = "/dev/findGameByTitle/{title}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public GameDto findGameByTitle(@PathVariable("title") String title) {
|
||||
@@ -29,4 +38,17 @@ public class GameyfinDevController {
|
||||
|
||||
return GameDto.builder().name(game.getName()).releaseDate(game.getFirstReleaseDate()).build();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/dev/gameFiles", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public List<String> getAllGameFiles() {
|
||||
return filesystemService.getGameFiles().stream().map(Path::toString).toList();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/dev/games", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public List<GameDto> getAllGames() {
|
||||
return filesystemService.getGameFileNames().stream()
|
||||
.map(t -> igdbWrapper.findGameByTitle(t))
|
||||
.map(g -> GameDto.builder().name(g.getName()).releaseDate(g.getFirstReleaseDate()).build())
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,36 @@
|
||||
package de.grimsi.gameyfin.service;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
public class FilesystemService {
|
||||
@Value("${gameyfin.root}")
|
||||
private String rootFolderPath;
|
||||
|
||||
@Value("${gameyfin.file-extensions}")
|
||||
private List<String> possibleGameFileExtensions;
|
||||
|
||||
public List<Path> getGameFiles() {
|
||||
Path rootFolder = Path.of(rootFolderPath);
|
||||
|
||||
try(Stream<Path> stream = Files.list(rootFolder)) {
|
||||
// return all sub-folders (non-recursive) and files that have an extension that indicates that they are a downloadable file
|
||||
return stream.filter(p -> Files.isDirectory(p) || possibleGameFileExtensions.contains(FilenameUtils.getExtension(p.getFileName().toString()))).toList();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error while opening root folder", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getGameFileNames() {
|
||||
return this.getGameFiles().stream().map(p -> FilenameUtils.getBaseName(p.toString())).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
gameyfin:
|
||||
root: D:\Games
|
||||
root: C:\Projects\privat\gameyfin-library
|
||||
igdb:
|
||||
api:
|
||||
client-id: 23l3l5qshx4dwjuao6yb8jyf1qrd08
|
||||
|
||||
@@ -3,6 +3,7 @@ spring.jackson.default-property-inclusion: non_null
|
||||
|
||||
gameyfin:
|
||||
root: ""
|
||||
file-extensions: iso, zip, rar, 7z, exe
|
||||
igdb:
|
||||
config:
|
||||
preferred-platform: 6
|
||||
|
||||
Reference in New Issue
Block a user