Avoid changing intro dictionary in HTTP controller

This commit is contained in:
ConfusedPolarBear 2022-09-04 03:16:33 -05:00
parent 85f21ae51c
commit b1cf0aa2fc
2 changed files with 13 additions and 1 deletions

View File

@ -54,7 +54,8 @@ public class SkipIntroController : ControllerBase
/// <returns>Intro object if the provided item has an intro, null otherwise.</returns> /// <returns>Intro object if the provided item has an intro, null otherwise.</returns>
private Intro? GetIntro(Guid id) private Intro? GetIntro(Guid id)
{ {
return Plugin.Instance!.Intros.TryGetValue(id, out var intro) ? intro : null; // Returns a copy to avoid mutating the original Intro object stored in the dictionary.
return Plugin.Instance!.Intros.TryGetValue(id, out var intro) ? new Intro(intro) : null;
} }
/// <summary> /// <summary>

View File

@ -32,6 +32,17 @@ public class Intro
IntroEnd = 0; IntroEnd = 0;
} }
/// <summary>
/// Initializes a new instance of the <see cref="Intro"/> class.
/// </summary>
/// <param name="intro">intro.</param>
public Intro(Intro intro)
{
EpisodeId = intro.EpisodeId;
IntroStart = intro.IntroStart;
IntroEnd = intro.IntroEnd;
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Intro"/> class. /// Initializes a new instance of the <see cref="Intro"/> class.
/// </summary> /// </summary>