mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 08:15:48 +00:00
Restructured API
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package de.grimsi.gameyfin.rest;
|
||||||
|
|
||||||
|
import de.grimsi.gameyfin.entities.DetectedGame;
|
||||||
|
import de.grimsi.gameyfin.service.GameService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This controller handles logic related to detected games.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/games")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GamesController {
|
||||||
|
|
||||||
|
private final GameService gameService;
|
||||||
|
|
||||||
|
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public List<DetectedGame> getAllGames() {
|
||||||
|
return gameService.getAllDetectedGames();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/game-mappings", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public Map<String, String> getGameMappings() {
|
||||||
|
return gameService.getAllMappings();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package de.grimsi.gameyfin.rest;
|
|
||||||
|
|
||||||
import de.grimsi.gameyfin.entities.DetectedGame;
|
|
||||||
import de.grimsi.gameyfin.entities.UnmappableFile;
|
|
||||||
import de.grimsi.gameyfin.service.FilesystemService;
|
|
||||||
import de.grimsi.gameyfin.service.GameService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class GameyfinDevController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FilesystemService filesystemService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GameService gameService;
|
|
||||||
|
|
||||||
@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<DetectedGame> getAllGames() {
|
|
||||||
return gameService.getAllDetectedGames();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(value = "/dev/images/{imageId}", produces = MediaType.IMAGE_PNG_VALUE)
|
|
||||||
public Resource getCoverImageForGame(@PathVariable String imageId) {
|
|
||||||
return filesystemService.getImage(imageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(value = "/dev/scan", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public void scanLibrary() {
|
|
||||||
filesystemService.scanGameLibrary();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(value = "/dev/cache/download")
|
|
||||||
public void downloadCovers() {
|
|
||||||
filesystemService.downloadGameCovers();
|
|
||||||
filesystemService.downloadGameScreenshots();
|
|
||||||
filesystemService.downloadCompanyLogos();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping(value = "/dev/unmappedFiles", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public List<UnmappableFile> getUnmappedFiles() {
|
|
||||||
return gameService.getAllUnmappedFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping(value = "/dev/gameMappings", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public Map<String, String> getGameMappings() {
|
|
||||||
return gameService.getAllMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(value = "/dev/unmappedFiles/{unmappedGameId}/mapTo/{igdbSlug}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public DetectedGame mapGameManually(@PathVariable Long unmappedGameId, @PathVariable String igdbSlug) {
|
|
||||||
return gameService.mapUnmappedFile(unmappedGameId, igdbSlug);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.grimsi.gameyfin.rest;
|
||||||
|
|
||||||
|
import de.grimsi.gameyfin.service.FilesystemService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This controller handles functionality for images.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/images")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ImageController {
|
||||||
|
|
||||||
|
private final FilesystemService filesystemService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/{imageId}", produces = MediaType.IMAGE_PNG_VALUE)
|
||||||
|
public Resource getCoverImageForGame(@PathVariable String imageId) {
|
||||||
|
return filesystemService.getImage(imageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
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;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This controller handles functionality of the library.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/library")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class LibraryController {
|
||||||
|
|
||||||
|
private final FilesystemService filesystemService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/scan", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public void scanLibrary(@RequestParam("download_images") boolean downloadImages) {
|
||||||
|
filesystemService.scanGameLibrary();
|
||||||
|
|
||||||
|
if(downloadImages) populateCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/populate-cache")
|
||||||
|
public void populateCache() {
|
||||||
|
filesystemService.downloadGameCovers();
|
||||||
|
filesystemService.downloadGameScreenshots();
|
||||||
|
filesystemService.downloadCompanyLogos();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/files", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public List<String> getAllFiles() {
|
||||||
|
return filesystemService.getGameFiles().stream().map(Path::toString).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package de.grimsi.gameyfin.rest;
|
||||||
|
|
||||||
|
import de.grimsi.gameyfin.entities.DetectedGame;
|
||||||
|
import de.grimsi.gameyfin.entities.UnmappableFile;
|
||||||
|
import de.grimsi.gameyfin.service.GameService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/unmapped-files")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UnmappedFileController {
|
||||||
|
|
||||||
|
private final GameService gameService;
|
||||||
|
|
||||||
|
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public List<UnmappableFile> getUnmappedFiles() {
|
||||||
|
return gameService.getAllUnmappedFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/{unmappedFileId}/map-to/{igdbSlug}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public DetectedGame mapGameManually(@PathVariable Long unmappedFileId, @PathVariable String igdbSlug) {
|
||||||
|
return gameService.mapUnmappedFile(unmappedFileId, igdbSlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user