Skip to content

Commit

Permalink
refactor: update signalr events
Browse files Browse the repository at this point in the history
- Updated the SignalR Connection Manager
  to support both the new and old signalr events.
  • Loading branch information
revam committed Apr 13, 2024
1 parent d7f4394 commit 2942660
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 59 deletions.
49 changes: 49 additions & 0 deletions Shokofin/SignalR/Interfaces/IFileMatchedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Shokofin.SignalR.Interfaces;

public interface IFileEventArgs
{
/// <summary>
/// Shoko file id.
/// </summary>
int FileId { get; }

/// <summary>
/// The ID of the new import folder the event was detected in.
/// </summary>
/// <value></value>
int ImportFolderId { get; }

/// <summary>
/// The relative path of the new file from the import folder base location.
/// </summary>
string RelativePath { get; }

/// <summary>
/// Cross references of episodes linked to this file.
/// </summary>
List<FileCrossReference> CrossReferences { get; }

public class FileCrossReference
{
/// <summary>
/// Shoko episode id.
/// </summary>
[JsonPropertyName("EpisodeID")]
public int EpisodeId { get; set; }

/// <summary>
/// Shoko series id.
/// </summary>
[JsonPropertyName("SeriesID")]
public int SeriesId { get; set; }

/// <summary>
/// Shoko group id.
/// </summary>
[JsonPropertyName("GroupID")]
public int GroupId { get; set; }
}
}
37 changes: 30 additions & 7 deletions Shokofin/SignalR/Models/EpisodeInfoUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Shokofin.SignalR.Models;

public class EpisodeInfoUpdatedEventArgs
{
/// <summary>
/// Shoko episode id.
/// The update reason.
/// </summary>
public UpdateReason Reason { get; set; }
/// <summary>
/// The provider metadata source.
/// </summary>
[JsonPropertyName("Source")]
public string ProviderName { get; set; } = string.Empty;

/// <summary>
/// The provided metadata episode id.
/// </summary>
[JsonPropertyName("EpisodeID")]
public int EpisodeId { get; set; }
public int ProviderId { get; set; }

/// <summary>
/// Shoko series id.
/// The provided metadata series id.
/// </summary>
[JsonPropertyName("SeriesID")]
public int SeriesId { get; set; }
public int ProviderSeriesId { get; set; }

/// <summary>
/// Shoko episode ids affected by this update.
/// </summary>
[JsonPropertyName("ShokoEpisodeIDs")]
public List<int> EpisodeIds { get; set; } = new();

/// <summary>
/// Shoko series ids affected by this update.
/// </summary>
[JsonPropertyName("ShokoSeriesIDs")]
public List<int> SeriesIds { get; set; } = new();

/// <summary>
/// Shoko group id.
/// Shoko group ids affected by this update.
/// </summary>
[JsonPropertyName("GroupID")]
public int GroupId { get; set; }
[JsonPropertyName("ShokoGroupIDs")]
public List<int> GroupIds { get; set; } = new();
}
9 changes: 8 additions & 1 deletion Shokofin/SignalR/Models/FileEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Shokofin.SignalR.Interfaces;

namespace Shokofin.SignalR.Models;

public class FileEventArgs
public class FileEventArgs : IFileEventArgs
{
/// <summary>
/// Shoko file id.
Expand All @@ -22,4 +24,9 @@ public class FileEventArgs
/// </summary>
[JsonPropertyName("RelativePath")]
public string RelativePath { get; set; } = string.Empty;

/// <summary>
/// Cross references of episodes linked to this file.
/// </summary>
public List<IFileEventArgs.FileCrossReference> CrossReferences { get; set; } = new();
}
43 changes: 21 additions & 22 deletions Shokofin/SignalR/Models/FileMatchedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Shokofin.SignalR.Interfaces;

namespace Shokofin.SignalR.Models;

public class FileMatchedEventArgs : FileEventArgs
public class FileMatchedEventArgsV1 : IFileEventArgs
{
/// <summary>
/// Cross references of episodes linked to this file.
/// Shoko file id.
/// </summary>
[JsonPropertyName("CrossRefs")]
public List<FileCrossReference> CrossReferences { get; set; } = new();
[JsonPropertyName("FileID")]
public int FileId { get; set; }

public class FileCrossReference
{
/// <summary>
/// Shoko episode id.
/// </summary>
[JsonPropertyName("EpisodeID")]
public int EpisodeId { get; set; }
/// <summary>
/// The ID of the import folder the event was detected in.
/// </summary>
/// <value></value>
[JsonPropertyName("ImportFolderID")]
public int ImportFolderId { get; set; }

/// <summary>
/// Shoko series id.
/// </summary>
[JsonPropertyName("SeriesID")]
public int SeriesId { get; set; }
/// <summary>
/// The relative path of the file from the import folder base location.
/// </summary>
[JsonPropertyName("RelativePath")]
public string RelativePath { get; set; } = string.Empty;

/// <summary>
/// Shoko group id.
/// </summary>
[JsonPropertyName("GroupID")]
public int GroupId { get; set; }
}
/// <summary>
/// Cross references of episodes linked to this file.
/// </summary>
[JsonPropertyName("CrossRefs")]
public List<IFileEventArgs.FileCrossReference> CrossReferences { get; set; } = new();
}
17 changes: 16 additions & 1 deletion Shokofin/SignalR/Models/FileMovedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Shokofin.SignalR.Models;

public class FileMovedEventArgs : IFileRelocationEventArgs
public class FileMovedEventArgsV1 : IFileRelocationEventArgs
{
/// <summary>
/// Shoko file id.
Expand Down Expand Up @@ -37,3 +37,18 @@ public class FileMovedEventArgs : IFileRelocationEventArgs
[JsonPropertyName("OldRelativePath")]
public string PreviousRelativePath { get; set; } = string.Empty;
}

public class FileMovedEventArgs: FileEventArgs, IFileRelocationEventArgs
{
/// <summary>
/// The ID of the old import folder the event was detected in.
/// </summary>
/// <value></value>
[JsonPropertyName("PreviousImportFolderID")]
public int PreviousImportFolderId { get; set; }

/// <summary>
/// The relative path of the old file from the import folder base location.
/// </summary>
public string PreviousRelativePath { get; set; } = string.Empty;
}
44 changes: 41 additions & 3 deletions Shokofin/SignalR/Models/FileRenamedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@

namespace Shokofin.SignalR.Models;

public class FileRenamedEventArgs : FileEventArgs, IFileRelocationEventArgs
public class FileRenamedEventArgsV1 : IFileRelocationEventArgs
{
/// <summary>
/// Shoko file id.
/// </summary>
[JsonPropertyName("FileID")]
public int FileId { get; set; }

/// <summary>
/// The ID of the import folder the event was detected in.
/// </summary>
/// <value></value>
[JsonPropertyName("ImportFolderID")]
public int ImportFolderId { get; set; }

/// <summary>
/// The relative path of the file from the import folder base location.
/// </summary>
[JsonPropertyName("RelativePath")]
public string RelativePath { get; set; } = string.Empty;

/// <summary>
/// The new File name.
/// </summary>
Expand All @@ -17,10 +36,29 @@ public class FileRenamedEventArgs : FileEventArgs, IFileRelocationEventArgs
[JsonPropertyName("OldFileName")]
public string PreviousFileName { get; set; } = string.Empty;

public int PreviousImportFolderId { get; set; }

/// <inheritdoc/>
public int PreviousImportFolderId => ImportFolderId;

/// <inheritdoc/>
public string PreviousRelativePath => RelativePath[^FileName.Length] + PreviousFileName;
}

public class FileRenamedEventArgs : FileEventArgs, IFileRelocationEventArgs
{
/// <summary>
/// The new File name.
/// </summary>
public string FileName { get; set; } = string.Empty;

/// <summary>
/// The relative path of the old file from the import folder base location.
/// The old file name.
/// </summary>
public string PreviousFileName { get; set; } = string.Empty;

/// <inheritdoc/>
public int PreviousImportFolderId => ImportFolderId;

/// <inheritdoc/>
public string PreviousRelativePath => RelativePath[^FileName.Length] + PreviousFileName;
}
28 changes: 23 additions & 5 deletions Shokofin/SignalR/Models/SeriesInfoUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Shokofin.SignalR.Models;

public class SeriesInfoUpdatedEventArgs
{
/// <summary>
/// Shoko series id.
/// The update reason.
/// </summary>
public UpdateReason Reason { get; set; }

/// <summary>
/// The provider metadata source.
/// </summary>
[JsonPropertyName("Source")]
public string ProviderName { get; set; } = string.Empty;

/// <summary>
/// The provided metadata series id.
/// </summary>
[JsonPropertyName("SeriesID")]
public int SeriesId { get; set; }
public int ProviderId { get; set; }

/// <summary>
/// Shoko series ids affected by this update.
/// </summary>
[JsonPropertyName("ShokoSeriesIDs")]
public List<int> SeriesIds { get; set; } = new();

/// <summary>
/// Shoko group id.
/// Shoko group ids affected by this update.
/// </summary>
[JsonPropertyName("GroupID")]
public int GroupId { get; set; }
[JsonPropertyName("ShokoGroupIDs")]
public List<int> GroupIds { get; set; } = new();
}
13 changes: 13 additions & 0 deletions Shokofin/SignalR/Models/UpdateReason.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

using System.Text.Json.Serialization;

namespace Shokofin.SignalR.Models;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum UpdateReason
{
None = 0,
Added = 1,
Updated = 2,
Removed = 3,
}
Loading

0 comments on commit 2942660

Please sign in to comment.