Skip to content

Commit

Permalink
Merge pull request #1809 from mregni/develop
Browse files Browse the repository at this point in the history
Fixing path
  • Loading branch information
mregni authored Jun 7, 2022
2 parents b490e02 + fa5dd7b commit 69bc8b7
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 66 deletions.
4 changes: 2 additions & 2 deletions EmbyStat.Common/EmbyStat.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.5" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.18.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.19.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Rollbar.NetCore.AspNet" Version="5.2.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.18.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.19.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
Expand Down
23 changes: 22 additions & 1 deletion EmbyStat.Common/Models/OptionSerializerAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using CommandLine;

namespace EmbyStat.Common.Models;

[AttributeUsage(AttributeTargets.Property)]
public class OptionSerializerAttribute : Attribute
{
private string Key { get; }
private bool NeedsCurrentDirPrefix { get; }

public OptionSerializerAttribute(string key)
{
Key = key;
}

public OptionSerializerAttribute(string key, bool needsCurrentDirPrefix)
{
Key = key;
NeedsCurrentDirPrefix = needsCurrentDirPrefix;
}

public KeyValuePair<string, string> ToKeyValuePair<T>(T value)
{
return new KeyValuePair<string, string>(Key, value.ToString());
if (NeedsCurrentDirPrefix && value != null)
{
var path = value.Cast<string>();
if (path.StartsWith('/'))
{
path = path.Remove(0, 1);
}

path = Path.Combine(Directory.GetCurrentDirectory(), path);
return new KeyValuePair<string, string>(Key, path);
}

return new KeyValuePair<string, string>(Key, value?.ToString());
}
}
17 changes: 9 additions & 8 deletions EmbyStat.Common/Models/StartupOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CommandLine;

Expand All @@ -11,20 +12,20 @@ public class StartupOptions
[OptionSerializer("Hosting:Port")]
public int? Port { get; set; }

[Option('n', "disable-updates", Required = false, Default = null, HelpText = "Disable all update flow and pages on the server.")]
[OptionSerializer("UpdatesDisabled")]
[Option('n', "enable-updates", Required = false, Default = null, HelpText = "Disable all update flow and pages on the server.")]
[OptionSerializer("SystemConfig:CanUpdate")]
public bool? NoUpdates { get; set; }

[Option('d', "data-dir", Required = false, Default = "", HelpText = "Folder where database is stored, default is <current-directory>")]
[OptionSerializer("Dirs:Data")]
[Option('d', "data-dir", Required = false, Default = "data", HelpText = "Folder where database is stored, default is /data")]
[OptionSerializer("SystemConfig:Dirs:Data", true)]
public string DataDir { get; set; }

[Option('l', "log-dir", Required = false, Default = "", HelpText = "Folder where log files are stored, default is <current-directory>/logs")]
[OptionSerializer("Dirs:Logs")]
[Option('l', "log-dir", Required = false, Default = "logs", HelpText = "Folder where log files are stored, default is /logs")]
[OptionSerializer("SystemConfig:Dirs:Logs", true)]
public string LogDir { get; set; }

[Option('c', "config-dir", Required = false, Default = "", HelpText = "Folder where config files are stored, default is <current-directory>")]
[OptionSerializer("Dirs:Config")]
[Option('c', "config-dir", Required = false, Default = "config", HelpText = "Folder where config files are stored, default is /config")]
[OptionSerializer("SystemConfig:Dirs:Config", true)]
public string ConfigDir { get; set; }

[Option('g', "log-level", Required = false, Default = null, HelpText = "Set the proper log level\n1: Debug\n2: Information")]
Expand Down
3 changes: 2 additions & 1 deletion EmbyStat.Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SystemConfig()
public string AppName { get; set; }
public Guid? Id { get; set; }
public bool UpdateInProgress { get; set; }
public bool UpdatesDisabled { get; set; }
public bool CanUpdate { get; set; }
public long Migration { get; set; }
public UpdateTrain UpdateTrain { get; set; }
public Updater Updater { get; set; }
Expand Down Expand Up @@ -98,6 +98,7 @@ public class Dirs
public string Updater { get; set; }
public string Logs { get; set; }
public string Data { get; set; }
public string Config { get; set; }
}

public class Jwt
Expand Down
2 changes: 1 addition & 1 deletion EmbyStat.Configuration/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Config Get()

private async Task WriteConfiguration(Config config)
{
var path = Path.Combine("config", "config.json");
var path = Path.Combine(config.SystemConfig.Dirs.Config, "config.json");
if (!File.Exists(path))
{
throw new InvalidConfigFileException($"Config file cannot be found at {path}");
Expand Down
4 changes: 2 additions & 2 deletions EmbyStat.Controllers/Job/JobController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IActionResult GetAll()
{
var jobs = _jobService.GetAll();

if (_config.SystemConfig.UpdatesDisabled)
if (!_config.SystemConfig.CanUpdate)
{
jobs = jobs.Where(x => x.Id != Constants.JobIds.CheckUpdateId);
}
Expand All @@ -68,7 +68,7 @@ public async Task<IActionResult> UpdateTrigger(Guid id, string cron)
{
if (await _jobService.UpdateTrigger(id, cron))
{
_jobInitializer.UpdateTrigger(id, cron, _config.SystemConfig.UpdatesDisabled);
_jobInitializer.UpdateTrigger(id, cron, _config.SystemConfig.CanUpdate);
return NoContent();
}

Expand Down
2 changes: 1 addition & 1 deletion EmbyStat.Controllers/Settings/ConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SystemConfigViewModel
public string AppName { get; set; }
public Guid? Id { get; set; }
public bool UpdateInProgress { get; set; }
public bool UpdatesDisabled { get; set; }
public bool CanUpdate { get; set; }
public long Migration { get; set; }
public int UpdateTrain { get; set; }
public RollbarViewModel Rollbar { get; set; }
Expand Down
7 changes: 5 additions & 2 deletions EmbyStat.Core/MediaServers/MediaServerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,13 @@ public Task<List<Library>> GetAllLibraries(LibraryType type, bool synced)

public async Task SetLibraryAsSynced(string[] libraryIds, LibraryType type)
{
var libraries = await _context.Libraries.Where(x => x.Type == type).ToListAsync();
var libraries = await _context.Libraries
.Where(x => x.Type == type)
.ToListAsync();

foreach (var library in libraries)
{
library.Sync = library.Type == type;
library.Sync = libraryIds.Contains(library.Id);
}

await _context.SaveChangesAsync();
Expand Down
4 changes: 2 additions & 2 deletions EmbyStat.Jobs/IJobInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace EmbyStat.Jobs;

public interface IJobInitializer
{
void Setup(bool disableUpdates);
void UpdateTrigger(Guid id, string trigger, bool disableUpdates);
void Setup(bool canUpdate);
void UpdateTrigger(Guid id, string trigger, bool canUpdate);
}
8 changes: 4 additions & 4 deletions EmbyStat.Jobs/JobInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public JobInitializer(IDatabaseCleanupJob databaseCleanupJob, IPingEmbyJob pingE
_movieSyncJob = movieSyncJob;
}

public void Setup(bool disableUpdates)
public void Setup(bool canUpdate)
{
var jobs = _jobService.GetAll();
foreach (var job in jobs)
{
UpdateTrigger(job.Id, job.Trigger, disableUpdates);
UpdateTrigger(job.Id, job.Trigger, canUpdate);
}
}

public void UpdateTrigger(Guid id, string trigger, bool disableUpdates)
public void UpdateTrigger(Guid id, string trigger, bool canUpdate)
{
if (id == Constants.JobIds.ShowSyncId)
{
Expand All @@ -49,7 +49,7 @@ public void UpdateTrigger(Guid id, string trigger, bool disableUpdates)
{
_recurringJobManager.AddOrUpdate(id.ToString(), () => _movieSyncJob.Execute(), trigger);
}
else if (id == Constants.JobIds.CheckUpdateId && !disableUpdates)
else if (id == Constants.JobIds.CheckUpdateId && canUpdate)
{
_recurringJobManager.AddOrUpdate(id.ToString(), () => _checkUpdateJob.Execute(), trigger);
}
Expand Down
6 changes: 3 additions & 3 deletions EmbyStat.Web/ClientApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, {useEffect, useMemo, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {Cell, Label, Pie, PieChart, ResponsiveContainer, Sector} from 'recharts';

import {darken, Paper, Stack, Typography, useTheme} from '@mui/material';
import {darken, Paper, Stack, Typography} from '@mui/material';

import i18n from '../../../i18n';
import {theme} from '../../../styles/theme';
Expand All @@ -20,7 +19,7 @@ interface ActiveShapeProps {
startAngle: number;
endAngle: number;
fill: string;
payload: {name: string};
payload: {label: string};
percent: number;
value: number;
}
Expand Down Expand Up @@ -62,7 +61,9 @@ const renderActiveShape = (props: ActiveShapeProps) => {
/>
<path d={`M${sx},${sy}L${mx},${my}L${ex},${ey}`} stroke={fill} fill="none" />
<circle cx={ex} cy={ey} r={2} fill={fill} stroke="none" />
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey} textAnchor={textAnchor} fill={color}>{`${value}`}</text>
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey} textAnchor={textAnchor} fill={color}>
{`${value} ${payload.label}`}
</text>
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey} dy={15} fontSize={12} textAnchor={textAnchor} fill={colorDark}>
{`${(percent * 100).toFixed(2)}%`}
</text>
Expand All @@ -77,8 +78,6 @@ interface Props {

export function EsPieGraph(props: Props) {
const {chart, height = 250} = props;
const theme = useTheme();
const {t} = useTranslation();
const [data, setData] = useState<SimpleData[]>(null!);
const [activeIndex, setActiveIndex] = useState(0);
const generatePalette = usePalette();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SystemConfig {
appName: string;
id: string | null;
updateInProgress: boolean;
updatesDisabled: boolean;
canUpdate: boolean;
migration: number;
updateTrain: number;
rollbar: Rollbar;
Expand Down
4 changes: 1 addition & 3 deletions EmbyStat.Web/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public static class DefaultConfig
Dirs = new Dirs
{
TempUpdate = "updateFiles",
Data = "data",
Logs = "logs",
Updater = "updater"
},
Jwt = new Jwt
Expand All @@ -32,7 +30,7 @@ public static class DefaultConfig
Id = Guid.NewGuid(),
Migration = 0,
UpdateInProgress = false,
UpdatesDisabled = false,
CanUpdate = true,
Rollbar = new Configuration.Rollbar(),
Updater = new Updater
{
Expand Down
18 changes: 10 additions & 8 deletions EmbyStat.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,19 @@ private static ApplicationModes GetApplicationMode()

private static IHost BuildConsoleHost(StartupOptions options)
{
CreateFolder("config");
GenerateDefaultConfiguration();

var memoryConfig = options.ToKeyValuePairs();
var dicConfig = memoryConfig.ToDictionary(x => x.Key, x => x.Value);
GenerateDefaultConfiguration(dicConfig["SystemConfig:Dirs:Config"]);

var configurationRoot = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(Path.Combine("config", "config.json"), false, true)
.AddJsonFile(Path.Combine(dicConfig["SystemConfig:Dirs:Config"], "config.json"), false, true)
.AddInMemoryCollection(memoryConfig)
.Build();

var config = configurationRoot.Get<Config>();

//Dirs in options object worden hier genegeerd!

CreateFolder(config.SystemConfig.Dirs.Logs);
CreateFolder(config.SystemConfig.Dirs.Data);
Expand Down Expand Up @@ -224,9 +225,10 @@ private static void CreateFolder(string folder)
}
}

private static void GenerateDefaultConfiguration()
private static void GenerateDefaultConfiguration(string configDir)
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "config", "config.json");
CreateFolder(configDir);
var path = Path.Combine(configDir, "config.json");
if (!File.Exists(path))
{
using var writer = File.CreateText(path);
Expand Down Expand Up @@ -319,10 +321,10 @@ private static void LogStartupParameters(Config config, int logLevel, bool servi
Log.Information($"\tSSL Port:\t{config.UserConfig.Hosting.SslPort}");
Log.Information($"\tSSL Enabled:\t{config.UserConfig.Hosting.SslEnabled}");
Log.Information($"\tURLs:\t\t{config.UserConfig.Hosting.Url}");
Log.Information($"\tConfig dir:\tconfig");
Log.Information($"\tConfig dir:\t{config.SystemConfig.Dirs.Config}");
Log.Information($"\tLog dir:\t{config.SystemConfig.Dirs.Logs}");
Log.Information($"\tData dir:\t{config.SystemConfig.Dirs.Data}");
Log.Information($"\tCan update:\t{!config.SystemConfig.UpdatesDisabled}");
Log.Information($"\tCan update:\t{config.SystemConfig.CanUpdate}");
Log.Information($"\tAs service:\t{service}");
Log.Information("--------------------------------------------------------------------");
}
Expand Down
2 changes: 1 addition & 1 deletion EmbyStat.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private void PerformPostStartup()
SetupDirectories(config);
accountService?.CreateRoles();
SetMediaServerClientConfiguration(configurationService, clientStrategy);
jobInitializer?.Setup(config.SystemConfig.UpdatesDisabled);
jobInitializer?.Setup(config.SystemConfig.CanUpdate);
}

RemoveVersionFiles();
Expand Down
4 changes: 2 additions & 2 deletions Tests.Unit/Builders/ConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ConfigBuilder()
UpdateTrain = UpdateTrain.Beta,
Migration = 0,
ProcessName = "EmbyStat",
UpdatesDisabled = false,
CanUpdate = true,
Jwt = new Jwt
{
Audience = "jwt-audience",
Expand Down Expand Up @@ -136,7 +136,7 @@ public ConfigBuilder WithRollbarSettings(bool state)

public ConfigBuilder WithAutoUpdate(bool state)
{
_config.SystemConfig.UpdatesDisabled = state;
_config.SystemConfig.CanUpdate = state;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests.Unit/Builders/ViewModels/ConfigViewModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ConfigViewModelBuilder(Config config)
ProcessName = config.SystemConfig.ProcessName,
Id = config.SystemConfig.Id,
UpdateInProgress = config.SystemConfig.UpdateInProgress,
UpdatesDisabled = config.SystemConfig.UpdatesDisabled,
CanUpdate = config.SystemConfig.CanUpdate,
Migration = config.SystemConfig.Migration,
UpdateTrain = (int)config.SystemConfig.UpdateTrain,
Dirs = new DirsViewModel
Expand Down
Loading

0 comments on commit 69bc8b7

Please sign in to comment.