mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Set db and cache path from first library root
This commit is contained in:
@@ -0,0 +1,66 @@
|
|||||||
|
package de.grimsi.gameyfin.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.core.env.*;
|
||||||
|
import org.springframework.util.PropertyPlaceholderHelper;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class FilesystemConfig {
|
||||||
|
|
||||||
|
@Value("#{'${gameyfin.root}'.split(',')[0]}")
|
||||||
|
private String firstLibraryPath;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Environment env;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setConfigurableEnvironment(ConfigurableEnvironment env) {
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("gameyfin.db", "%s/.gameyfin/db".formatted(firstLibraryPath));
|
||||||
|
props.setProperty("gameyfin.cache", "%s/.gameyfin/cache".formatted(firstLibraryPath));
|
||||||
|
env.getPropertySources().addFirst(new PropertiesPropertySource("gameyfinFilesystemProperties", props));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This bean is needed so Spring initializes the data source after we are done messing with the configuration environment
|
||||||
|
* @return DataSource
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(prefix = "spring.datasource")
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public DataSource getDataSource() {
|
||||||
|
|
||||||
|
Properties properties = loadAllProperties();
|
||||||
|
|
||||||
|
return DataSourceBuilder
|
||||||
|
.create()
|
||||||
|
.url(properties.getProperty("spring.datasource.url"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties loadAllProperties() {
|
||||||
|
Properties props = new Properties();
|
||||||
|
|
||||||
|
MutablePropertySources propSrcs = ((AbstractEnvironment) env).getPropertySources();
|
||||||
|
|
||||||
|
StreamSupport.stream(propSrcs.spliterator(), false)
|
||||||
|
.filter(ps -> ps instanceof EnumerablePropertySource)
|
||||||
|
.map(ps -> ((EnumerablePropertySource<?>) ps).getPropertyNames())
|
||||||
|
.flatMap(Arrays::stream)
|
||||||
|
.forEach(propName -> props.setProperty(propName, env.getProperty(propName)));
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-8
@@ -9,20 +9,13 @@ import org.springframework.core.io.Resource;
|
|||||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class CustomConfiguratioLoader {
|
public class SecureProperties {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setConfigurableEnvironment(ConfigurableEnvironment env) {
|
public void setConfigurableEnvironment(ConfigurableEnvironment env) {
|
||||||
try {
|
try {
|
||||||
String firstLibraryPath = env.resolvePlaceholders("gameyfin.root").split(",")[0];
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.setProperty("gameyfin.db", "%s/.gameyfin/db".formatted(firstLibraryPath));
|
|
||||||
props.setProperty("gameyfin.cache", "%s/.gameyfin/cache".formatted(firstLibraryPath));
|
|
||||||
env.getPropertySources().addFirst(new PropertiesPropertySource("dynamicallyLoadedGameyfinProperties", props));
|
|
||||||
|
|
||||||
Resource resource = new ClassPathResource("/config/secure.yml");
|
Resource resource = new ClassPathResource("/config/secure.yml");
|
||||||
env.getPropertySources().addFirst(new PropertiesPropertySource(Objects.requireNonNull(resource.getFilename()), PropertiesLoaderUtils.loadProperties(resource)));
|
env.getPropertySources().addFirst(new PropertiesPropertySource(Objects.requireNonNull(resource.getFilename()), PropertiesLoaderUtils.loadProperties(resource)));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -39,7 +39,7 @@ public class LibraryService {
|
|||||||
public List<Path> getGameFiles() {
|
public List<Path> getGameFiles() {
|
||||||
List<Path> gamefiles = new ArrayList<>();
|
List<Path> gamefiles = new ArrayList<>();
|
||||||
|
|
||||||
libraryFolders.parallelStream().map(Path::of).forEach(
|
libraryFolders.stream().map(Path::of).forEach(
|
||||||
folder -> {
|
folder -> {
|
||||||
try (Stream<Path> stream = Files.list(folder)) {
|
try (Stream<Path> stream = Files.list(folder)) {
|
||||||
// return all sub-folders (non-recursive) and files that have an extension that indicates that they are a downloadable file
|
// return all sub-folders (non-recursive) and files that have an extension that indicates that they are a downloadable file
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
spring:
|
spring:
|
||||||
jpa:
|
jpa:
|
||||||
open-in-view: 'true'
|
open-in-view: true
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
enable_lazy_load_no_trans: 'true'
|
enable_lazy_load_no_trans: true
|
||||||
event:
|
event:
|
||||||
merge:
|
merge:
|
||||||
entity_copy_observer: allow
|
entity_copy_observer: allow
|
||||||
@@ -12,7 +12,7 @@ spring:
|
|||||||
ddl-auto: update
|
ddl-auto: update
|
||||||
datasource:
|
datasource:
|
||||||
username: gfadmin
|
username: gfadmin
|
||||||
url: jdbc:h2:file:${gameyfin.db}/${spring.datasource.db-name}
|
password: gameyfin
|
||||||
driverClassName: org.h2.Driver
|
|
||||||
db-name: gameyfin_db
|
db-name: gameyfin_db
|
||||||
password: gameyfin
|
url: jdbc:h2:file:${gameyfin.db}/${spring.datasource.db-name}
|
||||||
|
driverClassName: org.h2.Driver
|
||||||
@@ -1,14 +1,5 @@
|
|||||||
gameyfin:
|
gameyfin:
|
||||||
user:
|
|
||||||
password:
|
|
||||||
|
|
||||||
root:
|
|
||||||
|
|
||||||
db: ./.gameyfin/db
|
|
||||||
cache: ./.gameyfin/cache
|
|
||||||
|
|
||||||
file-extensions: iso, zip, rar, 7z, exe
|
file-extensions: iso, zip, rar, 7z, exe
|
||||||
|
|
||||||
igdb:
|
igdb:
|
||||||
api:
|
api:
|
||||||
client-id:
|
client-id:
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ services:
|
|||||||
- gameyfin.password=<your password here>
|
- gameyfin.password=<your password here>
|
||||||
- gameyfin.igdb.api.client-id=<your twitch client-id here>
|
- gameyfin.igdb.api.client-id=<your twitch client-id here>
|
||||||
- gameyfin.igdb.api.client-secret=<your twitch client-secret here>
|
- gameyfin.igdb.api.client-secret=<your twitch client-secret here>
|
||||||
# The following two environment variables only need to be set if you have more than one library folder.
|
|
||||||
# If you have just one you can safely delete them.
|
|
||||||
- gameyfin.cache=<path to your game library>/.gameyfin/cache
|
|
||||||
- gameyfin.db=<path to your game library>/.gameyfin/db
|
|
||||||
volumes:
|
volumes:
|
||||||
- <path to your game library>:/opt/gameyfin-library
|
- <path to your game library>:/opt/gameyfin-library
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
Reference in New Issue
Block a user