First Commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace JobTrackerApi.Services
|
||||
{
|
||||
public sealed class AppPaths
|
||||
{
|
||||
public string DataRoot { get; }
|
||||
public string AttachmentsRoot { get; }
|
||||
|
||||
public AppPaths(IConfiguration cfg, IHostEnvironment env)
|
||||
{
|
||||
var dataRoot = (cfg["Data:Root"] ?? "").Trim();
|
||||
if (string.IsNullOrWhiteSpace(dataRoot)) dataRoot = env.ContentRootPath;
|
||||
if (!Path.IsPathRooted(dataRoot)) dataRoot = Path.Combine(env.ContentRootPath, dataRoot);
|
||||
|
||||
Directory.CreateDirectory(dataRoot);
|
||||
DataRoot = dataRoot;
|
||||
|
||||
var attachmentsRoot = (cfg["Data:AttachmentsRoot"] ?? "").Trim();
|
||||
if (string.IsNullOrWhiteSpace(attachmentsRoot)) attachmentsRoot = Path.Combine(DataRoot, "Attachments");
|
||||
if (!Path.IsPathRooted(attachmentsRoot)) attachmentsRoot = Path.Combine(env.ContentRootPath, attachmentsRoot);
|
||||
|
||||
Directory.CreateDirectory(attachmentsRoot);
|
||||
AttachmentsRoot = attachmentsRoot;
|
||||
}
|
||||
|
||||
public string GetDbPath(string fileName = "jobtracker.db") => Path.Combine(DataRoot, fileName);
|
||||
|
||||
public string GetExportsRoot(string? configuredFolder)
|
||||
{
|
||||
var folder = (configuredFolder ?? "").Trim();
|
||||
if (string.IsNullOrWhiteSpace(folder)) return Path.Combine(DataRoot, "exports");
|
||||
return Path.IsPathRooted(folder) ? folder : Path.Combine(DataRoot, folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user