diff options
| author | Jake Mannens <jake@asger.xyz> | 2026-05-22 12:46:00 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-05-23 22:13:00 +1000 |
| commit | 4ea3ddb38d010c2f85c22b7f1c3f2d7e0c1355e3 (patch) | |
| tree | 90af9203059d645eb77216f1a091722ee9702438 /Services/ConfigService.cs | |
| parent | 6de5d7f5364fe1d54703da6d6b7cb08ea26e939f (diff) | |
Initial commitwasm-oldserver
Diffstat (limited to 'Services/ConfigService.cs')
| -rw-r--r-- | Services/ConfigService.cs | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/Services/ConfigService.cs b/Services/ConfigService.cs deleted file mode 100644 index ac1f155..0000000 --- a/Services/ConfigService.cs +++ /dev/null @@ -1,72 +0,0 @@ -using HyperBooru.ApiModels; - -namespace HyperBooru.Services; - -public interface IConfigService { - public string DataPath { get; } - public string KeyPath { get; } - public string DbConnectionString { get; } - public string MediaBasePath { get; } - public string ThumbnailBasePath { get; } - public string ConvertedMediaBasePath { get; } - public bool EnableOcr { get; } -} - -public class ConfigService : IConfigService { - private IConfiguration config; - - private const string AppName = "HyperBooru"; - - public string DataPath { - get { - #if DEBUG - return "Data"; - #else - string? path = config["DataPath"]; - if(path is not null) - return path; - - switch(Environment.OSVersion.Platform) { - case PlatformID.Win32NT: - return Path.Join( - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), - AppName); - case PlatformID.Unix: - return $"/var/lib/{AppName.ToLower()}"; - default: - throw new NotImplementedException( - $"Unknown Operating System: {Environment.OSVersion.Platform}"); - } - #endif - } - } - - public string KeyPath => - Path.Join(DataPath, "keys"); - - public string DbConnectionString => - config.GetConnectionString("DefaultConnection") ?? - throw new HBException("Unable to get default connection string"); - - public string MediaBasePath => - Path.Join(DataPath, "media"); - - public string ThumbnailBasePath => - Path.Join(DataPath, "thumb"); - - public string ConvertedMediaBasePath => - Path.Join(DataPath, "converted"); - - public bool EnableOcr => - bool.TryParse(config["DisableOcr"], out bool x) ? !x : true; - - public ConfigService(IConfiguration config) { - this.config = config; - InitDirectoryStructure(); - } - - private void InitDirectoryStructure() { - Directory.CreateDirectory(DataPath); - Directory.CreateDirectory(MediaBasePath); - } -}
\ No newline at end of file |
