Skip to content

Commit

Permalink
feat: expose plex usernames in APIv3 User DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Sep 10, 2024
1 parent 9bae1ff commit b8add59
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Shoko.Server/API/v3/Models/Shoko/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class User
/// </summary>
public string Avatar { get; set; }

/// <summary>
/// The user's Plex usernames.
/// </summary>
public List<string> PlexUsernames { get; set; }

public User(SVR_JMMUser user)
{
ID = user.JMMUserID;
Expand Down Expand Up @@ -78,6 +83,8 @@ public User(SVR_JMMUser user)
.ToList();

Avatar = user.HasAvatarImage ? ModelHelper.ToDataURL(user.AvatarImageBlob, user.AvatarImageMetadata.ContentType) ?? string.Empty : string.Empty;

PlexUsernames = user.PlexUsers.Split(',', System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries).ToList();
}

public class Input
Expand Down Expand Up @@ -139,6 +146,11 @@ public class CreateOrUpdateUserBody
/// </summary>
public string? Avatar { get; set; } = null;

/// <summary>
/// The new user's Plex usernames.
/// </summary>
public List<string>? PlexUsernames { get; set; }

public CreateOrUpdateUserBody() { }

private const long MaxFileSize = 8 * 1024 * 1024; // 8MiB in bytes
Expand Down Expand Up @@ -230,6 +242,11 @@ public CreateOrUpdateUserBody() { }
user.IsAniDBUser = CommunitySites.Contains(global::Shoko.Models.Enums.CommunitySites.AniDB) ? 1 : 0;
}

if (PlexUsernames != null)
{
user.PlexUsers = string.Join(',', PlexUsernames.Select(username => username.Trim()).Where(username => !string.IsNullOrEmpty(username)));
}

// Save the model now.
RepoFactory.JMMUser.Save(user);

Expand Down

0 comments on commit b8add59

Please sign in to comment.