Skip to content

Commit

Permalink
Merge pull request #1083 from ShokoAnime/Filters
Browse files Browse the repository at this point in the history
Filters
  • Loading branch information
da3dsoul authored Sep 28, 2023
2 parents 6c57ba0 + a1ffefa commit e6b7526
Show file tree
Hide file tree
Showing 214 changed files with 11,674 additions and 8,817 deletions.
10 changes: 8 additions & 2 deletions Shoko.CLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#region
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Shoko.Server.Commands;
using Shoko.Server.Filters;
using Shoko.Server.Repositories;
using Shoko.Server.Server;
using Shoko.Server.Settings;
using Shoko.Server.Utilities;
Expand All @@ -13,6 +18,7 @@ namespace Shoko.CLI;

public static class Program
{
private static ILogger _logger;
public static void Main()
{
try
Expand All @@ -26,7 +32,7 @@ public static void Main()
Utils.SetInstance();
Utils.InitLogger();
var logFactory = new LoggerFactory().AddNLog();
var logger = logFactory.CreateLogger("Main");
_logger = logFactory.CreateLogger("Main");

try
{
Expand All @@ -40,7 +46,7 @@ public static void Main()
}
catch (Exception e)
{
logger.LogCritical(e, "The server failed to start");
_logger.LogCritical(e, "The server failed to start");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Shoko.Commons
4 changes: 4 additions & 0 deletions Shoko.Server/API/APIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Shoko.Server.API.SignalR.Aggregate;
using Shoko.Server.API.SignalR.Legacy;
using Shoko.Server.API.Swagger;
using Shoko.Server.API.v3.Helpers;
using Shoko.Server.API.v3.Models.Shoko;
using Shoko.Server.API.WebUI;
using Shoko.Server.Plugin;
Expand Down Expand Up @@ -50,6 +51,9 @@ public static IServiceCollection AddAPI(this IServiceCollection services)
services.AddSingleton<AVDumpEmitter>();
services.AddSingleton<NetworkEmitter>();
services.AddSingleton<QueueEmitter>();
services.AddScoped<FilterFactory>();
services.AddScoped<SeriesFactory>();
services.AddScoped<WebUIFactory>();

services.AddAuthentication(options =>
{
Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/API/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AuthenticationController : BaseController
[ProducesResponseType(400)]
[ProducesResponseType(401)]
[ProducesResponseType(200)]
public ActionResult<dynamic> Login(AuthUser auth)
public ActionResult<object> Login(AuthUser auth)
{
if (!ModelState.IsValid || string.IsNullOrEmpty(auth.user?.Trim()))
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public ActionResult ChangePassword([FromBody] string newPassword)
try
{
User.Password = Digest.Hash(newPassword.Trim());
RepoFactory.JMMUser.Save(User, false);
RepoFactory.JMMUser.Save(User);
RepoFactory.AuthTokens.DeleteAllWithUserID(User.JMMUserID);
return Ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Shoko.Server.Commands;
using Shoko.Server.Commands.AniDB;
using Shoko.Server.Extensions;
using Shoko.Server.Filters;
using Shoko.Server.Filters.Legacy;
using Shoko.Server.Models;
using Shoko.Server.Plex;
using Shoko.Server.Providers.AniDB.Interfaces;
Expand Down Expand Up @@ -175,16 +177,17 @@ public CL_MainChanges GetAllChanges(DateTime date, int userID)
var changes = ChangeTracker<int>.GetChainedChanges(
new List<ChangeTracker<int>>
{
RepoFactory.GroupFilter.GetChangeTracker(),
RepoFactory.FilterPreset.GetChangeTracker(),
RepoFactory.AnimeGroup.GetChangeTracker(),
RepoFactory.AnimeGroup_User.GetChangeTracker(userID),
RepoFactory.AnimeSeries.GetChangeTracker(),
RepoFactory.AnimeSeries_User.GetChangeTracker(userID)
}, date);
var legacyConverter = HttpContext.RequestServices.GetRequiredService<LegacyFilterConverter>();
c.Filters = new CL_Changes<CL_GroupFilter>
{
ChangedItems = changes[0]
.ChangedItems.Select(a => RepoFactory.GroupFilter.GetByID(a)?.ToClient())
ChangedItems = legacyConverter.ToClient(changes[0].ChangedItems.Select(a => RepoFactory.FilterPreset.GetByID(a)).ToList())
.Select(a => a.Value)
.Where(a => a != null)
.ToList(),
RemovedItems = changes[0].RemovedItems.ToList(),
Expand All @@ -203,8 +206,7 @@ public CL_MainChanges GetAllChanges(DateTime date, int userID)
if (!c.Filters.ChangedItems.Any(a => a.GroupFilterID == ag.ParentGroupFilterID.Value))
{
end = false;
var cag = RepoFactory.GroupFilter.GetByID(ag.ParentGroupFilterID.Value)?
.ToClient();
var cag = legacyConverter.ToClient(RepoFactory.FilterPreset.GetByID(ag.ParentGroupFilterID.Value));
if (cag != null)
{
c.Filters.ChangedItems.Add(cag);
Expand Down Expand Up @@ -270,8 +272,10 @@ public CL_Changes<CL_GroupFilter> GetGroupFilterChanges(DateTime date)
var c = new CL_Changes<CL_GroupFilter>();
try
{
var changes = RepoFactory.GroupFilter.GetChangeTracker().GetChanges(date);
c.ChangedItems = changes.ChangedItems.Select(a => RepoFactory.GroupFilter.GetByID(a).ToClient())
var legacyConverter = HttpContext.RequestServices.GetRequiredService<LegacyFilterConverter>();
var changes = RepoFactory.FilterPreset.GetChangeTracker().GetChanges(date);
c.ChangedItems = legacyConverter.ToClient(changes.ChangedItems.Select(a => RepoFactory.FilterPreset.GetByID(a)).ToList())
.Select(a => a.Value)
.Where(a => a != null)
.ToList();
c.RemovedItems = changes.RemovedItems.ToList();
Expand Down
Loading

0 comments on commit e6b7526

Please sign in to comment.