Finished implementation of frontend functionality.

Styling and bugfixing next
This commit is contained in:
grimsi
2022-07-25 21:17:30 +02:00
parent 57377036c4
commit aa72161990
23 changed files with 146 additions and 152 deletions
@@ -32,22 +32,8 @@ public class SecurityConfiguration {
@Bean
protected SecurityFilterChain httpSecurity(HttpSecurity http) throws Exception {
// TODO: Try to enable CSRF
http.csrf().disable();
// Allow GET-Requests on *all* URLs (Frontend will handle 404 and permission)
// except paths under "/v1/library-management"
http.authorizeRequests()
.antMatchers("**").permitAll()
.antMatchers("/v1/library-management").authenticated()
.anyRequest().denyAll();
http.httpBasic(Customizer.withDefaults());
http.exceptionHandling()
.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));
return http.build();
}
@@ -4,6 +4,7 @@ import de.grimsi.gameyfin.service.DownloadService;
import de.grimsi.gameyfin.service.LibraryService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -17,6 +18,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/v1/library")
@PreAuthorize("hasAuthority('ADMIN_API_ACCESS')")
@RequiredArgsConstructor
public class LibraryController {
@@ -28,6 +28,11 @@ public class LibraryManagementController {
gameService.deleteGame(slug);
}
@DeleteMapping(value = "/delete-unmapped-file/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public void deleteUnmappedFile(@PathVariable Long id) {
gameService.deleteUnmappedFile(id);
}
@GetMapping(value = "/confirm-game/{slug}", produces = MediaType.APPLICATION_JSON_VALUE)
public DetectedGame confirmMatch(@PathVariable String slug, @RequestParam(required = false, defaultValue = "true") boolean confirm) {
return gameService.confirmGame(slug, confirm);
@@ -6,8 +6,8 @@ import de.grimsi.gameyfin.entities.DetectedGame;
import de.grimsi.gameyfin.entities.UnmappableFile;
import de.grimsi.gameyfin.igdb.IgdbWrapper;
import de.grimsi.gameyfin.mapper.GameMapper;
import de.grimsi.gameyfin.repositories.UnmappableFileRepository;
import de.grimsi.gameyfin.repositories.DetectedGameRepository;
import de.grimsi.gameyfin.repositories.UnmappableFileRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -50,11 +50,21 @@ public class GameService {
public List<GameOverviewDto> getGameOverviews() {
return detectedGameRepository.findAll().stream().map(GameMapper::toGameOverviewDto).toList();
}
public void deleteGame(String slug) {
DetectedGame gameToBeDeleted = getDetectedGame(slug);
// Add the path of the game to be deleted to the unmappable files
// so it doesn't get re-indexed on the next library scan
unmappableFileRepository.save(new UnmappableFile(gameToBeDeleted.getPath()));
detectedGameRepository.deleteById(slug);
}
public void deleteUnmappedFile(Long id) {
unmappableFileRepository.deleteById(id);
}
public DetectedGame confirmGame(String slug, boolean confirm) {
DetectedGame g = getDetectedGame(slug);
g.setConfirmedMatch(confirm);
@@ -63,17 +73,17 @@ public class GameService {
public DetectedGame mapPathToGame(String path, String slug) {
if(detectedGameRepository.existsBySlug(slug))
if (detectedGameRepository.existsBySlug(slug))
throw new ResponseStatusException(HttpStatus.CONFLICT, "Game with slug '%s' already exists in database.".formatted(slug));
Optional<UnmappableFile> optionalUnmappableFile = unmappableFileRepository.findByPath(path);
Optional<DetectedGame> optionalDetectedGame = detectedGameRepository.findByPath(path);
if(optionalUnmappableFile.isPresent()) {
if (optionalUnmappableFile.isPresent()) {
return mapUnmappableFile(optionalUnmappableFile.get(), slug);
}
if(optionalDetectedGame.isPresent()) {
if (optionalDetectedGame.isPresent()) {
return mapDetectedGame(optionalDetectedGame.get(), slug);
}
@@ -18,6 +18,11 @@ public class FilenameUtil {
}
public static String getFilenameWithoutExtension(Path p) {
// If the path points to a folder, return the folder name
// Folders like "Counter Strike 1.6" would otherwise be returned as "Counter Strike 1"
if(p.toFile().isDirectory()) return FilenameUtils.getName(p.toString());
return FilenameUtils.getBaseName(p.toString());
}
@@ -1,8 +1,8 @@
gameyfin:
user: admin
password: 112
root: C:\Projects\privat\gameyfin-library
#root: \\NAS-Simon\Öffentlich\Spiele
#root: C:\Projects\privat\gameyfin-library
root: \\NAS-Simon\Öffentlich\Spiele
cache: ${gameyfin.root}\.gameyfin\cache
db: ${gameyfin.root}\.gameyfin\db
#db: ./data
@@ -1,14 +0,0 @@
server:
error.include-stacktrace: never
spring:
mvc:
async.request-timeout: -1
jackson.default-property-inclusion: non_null
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate.ddl-auto: update
open-in-view: true
properties:
hibernate:
event.merge.entity_copy_observer: allow