Skip to content

Commit

Permalink
refactor: more changes to signalr models
Browse files Browse the repository at this point in the history
- Another overhaul of the SingalR models, this time removing
  an (now) unneeded event model, and also (hopefully) correcting the
  relative paths to use the correct directory separators for the local
  os environment and not the environment Shoko Server is running in.
  • Loading branch information
revam committed Apr 14, 2024
1 parent cb06fbd commit 2764cdb
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public interface IFileEventArgs
int ImportFolderId { get; }

/// <summary>
/// The relative path of the new file from the import folder base location.
/// The relative path from the base of the <see cref="ImportFolder"/> to
/// where the <see cref="File"/> lies, with a leading slash applied at
/// the start and normalised for the local system.
/// </summary>
string RelativePath { get; }

Expand Down
21 changes: 4 additions & 17 deletions Shokofin/SignalR/Interfaces/IFileRelocationEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@

namespace Shokofin.SignalR.Interfaces;

public interface IFileRelocationEventArgs
public interface IFileRelocationEventArgs : 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 ID of the old import folder the event was detected in.
Expand All @@ -21,12 +11,9 @@ public interface IFileRelocationEventArgs
int PreviousImportFolderId { get; }

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

/// <summary>
/// The relative path of the old file from the import folder base location.
/// The relative path from the previous base of the
/// <see cref="ImportFolder"/> to where the <see cref="File"/> previously
/// lied, with a leading slash applied at the start.
/// </summary>
string PreviousRelativePath { get; }
}
14 changes: 8 additions & 6 deletions Shokofin/SignalR/Models/EpisodeInfoUpdatedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,42 @@ public class EpisodeInfoUpdatedEventArgs
/// <summary>
/// The update reason.
/// </summary>
[JsonInclude, JsonPropertyName("Reason")]
public UpdateReason Reason { get; set; }

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

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

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

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

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

/// <summary>
/// Shoko group ids affected by this update.
/// </summary>
[JsonPropertyName("ShokoGroupIDs")]
[JsonInclude, JsonPropertyName("ShokoGroupIDs")]
public List<int> GroupIds { get; set; } = new();
}
43 changes: 30 additions & 13 deletions Shokofin/SignalR/Models/FileEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,44 @@ namespace Shokofin.SignalR.Models;

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

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

/// <summary>
/// The relative path of the file from the import folder base location.
/// The relative path with no leading slash and directory seperators used on
/// the Shoko side.
/// </summary>
[JsonPropertyName("RelativePath")]
public string RelativePath { get; set; } = string.Empty;
[JsonInclude, JsonPropertyName("RelativePath")]
private string InternalPath { get; set; } = string.Empty;

/// <summary>
/// Cross references of episodes linked to this file.
/// Cached path for later re-use.
/// </summary>
[JsonIgnore]
private string? CachedPath { get; set; }

/// <inheritdoc/>
[JsonIgnore]
public string RelativePath =>
CachedPath ??= System.IO.Path.DirectorySeparatorChar + InternalPath
.Replace('/', System.IO.Path.DirectorySeparatorChar)
.Replace('\\', System.IO.Path.DirectorySeparatorChar);

/// <inheritdoc/>
[JsonInclude, JsonPropertyName("CrossReferences")]
public List<IFileEventArgs.FileCrossReference> CrossReferences { get; set; } = new();

#pragma warning disable IDE0051
/// <summary>
/// Legacy cross-references of episodes lined to this file. Only present
/// for setting the cross-references when deserializing JSON.
/// </summary>
[JsonInclude, JsonPropertyName("CrossRefs")]
private List<IFileEventArgs.FileCrossReference> LegacyCrossReferences { set { CrossReferences = value; } }
#pragma warning restore IDE0051
}
33 changes: 0 additions & 33 deletions Shokofin/SignalR/Models/FileMatchedEventArgs.cs

This file was deleted.

113 changes: 76 additions & 37 deletions Shokofin/SignalR/Models/FileMovedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,93 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Shokofin.SignalR.Interfaces;

namespace Shokofin.SignalR.Models;

public class FileMovedEventArgsV1 : IFileRelocationEventArgs

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

/// <summary>
/// The ID of the new import folder the event was detected in.
/// The previous relative path with no leading slash and directory
/// seperators used on the Shoko side.
/// </summary>
/// <value></value>
[JsonPropertyName("NewImportFolderID")]
public int ImportFolderId { get; set; }
[JsonInclude, JsonPropertyName("PreviousRelativePath")]
private string PreviousInternalPath { get; set; } = string.Empty;

/// <summary>
/// The ID of the old import folder the event was detected in.
/// Cached path for later re-use.
/// </summary>
/// <value></value>
[JsonPropertyName("OldImportFolderID")]
public int PreviousImportFolderId { get; set; }
[JsonIgnore]
private string? PreviousCachedPath { get; set; }

/// <summary>
/// The relative path of the new file from the import folder base location.
/// </summary>
[JsonPropertyName("NewRelativePath")]
public string RelativePath { get; set; } = string.Empty;
/// <inheritdoc/>
[JsonIgnore]
public string PreviousRelativePath =>
PreviousCachedPath ??= System.IO.Path.DirectorySeparatorChar + PreviousInternalPath
.Replace('/', System.IO.Path.DirectorySeparatorChar)
.Replace('\\', System.IO.Path.DirectorySeparatorChar);

/// <summary>
/// The relative path of the old file from the import folder base location.
/// </summary>
[JsonPropertyName("OldRelativePath")]
public string PreviousRelativePath { get; set; } = string.Empty;
}
public class V0 : IFileRelocationEventArgs
{
/// <inheritdoc/>
[JsonInclude, JsonPropertyName("FileID")]
public int FileId { get; set; }

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; }
/// <inheritdoc/>
[JsonInclude, JsonPropertyName("NewImportFolderID")]
public int ImportFolderId { get; set; }

/// <summary>
/// The relative path of the old file from the import folder base location.
/// </summary>
public string PreviousRelativePath { get; set; } = string.Empty;
/// <inheritdoc/>
[JsonInclude, JsonPropertyName("OldImportFolderID")]
public int PreviousImportFolderId { get; set; }

/// <summary>
/// The relative path with no leading slash and directory seperators used on
/// the Shoko side.
/// </summary>
[JsonInclude, JsonPropertyName("RelativePath")]
private string InternalPath { get; set; } = string.Empty;

/// <summary>
/// Cached path for later re-use.
/// </summary>
[JsonIgnore]
private string? CachedPath { get; set; }

/// <inheritdoc/>
[JsonIgnore]
public string RelativePath =>
CachedPath ??= System.IO.Path.DirectorySeparatorChar + InternalPath
.Replace('/', System.IO.Path.DirectorySeparatorChar)
.Replace('\\', System.IO.Path.DirectorySeparatorChar);


/// <summary>
/// The previous relative path with no leading slash and directory
/// seperators used on the Shoko side.
/// </summary>
[JsonInclude, JsonPropertyName("OldRelativePath")]
private string PreviousInternalPath { get; set; } = string.Empty;

/// <summary>
/// Cached path for later re-use.
/// </summary>
[JsonIgnore]
private string? PreviousCachedPath { get; set; }

/// <inheritdoc/>
[JsonIgnore]
public string PreviousRelativePath =>
PreviousCachedPath ??= System.IO.Path.DirectorySeparatorChar + PreviousInternalPath
.Replace('/', System.IO.Path.DirectorySeparatorChar)
.Replace('\\', System.IO.Path.DirectorySeparatorChar);

/// <inheritdoc/>
[JsonIgnore]
public List<IFileEventArgs.FileCrossReference> CrossReferences => new();
}
}
Loading

0 comments on commit 2764cdb

Please sign in to comment.