You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Api/ConnectService.cs

152 lines
5.9 KiB

using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
10 years ago
using MediaBrowser.Model.Connect;
using ServiceStack;
10 years ago
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MediaBrowser.Api
{
[Route("/Users/{Id}/Connect/Link", "POST", Summary = "Creates a Connect link for a user")]
[Authenticated(Roles = "Admin")]
public class CreateConnectLink : IReturn<UserLinkResult>
{
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Id { get; set; }
[ApiMember(Name = "ConnectUsername", Description = "Connect username", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string ConnectUsername { get; set; }
}
[Route("/Users/{Id}/Connect/Link", "DELETE", Summary = "Removes a Connect link for a user")]
[Authenticated(Roles = "Admin")]
public class DeleteConnectLink : IReturnVoid
{
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
public string Id { get; set; }
}
10 years ago
[Route("/Connect/Invite", "POST", Summary = "Creates a Connect link for a user")]
[Authenticated(Roles = "Admin")]
10 years ago
public class CreateConnectInvite : IReturn<UserLinkResult>
{
10 years ago
[ApiMember(Name = "ConnectUsername", Description = "Connect username", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
10 years ago
public string ConnectUsername { get; set; }
10 years ago
[ApiMember(Name = "SendingUserId", Description = "Sending User Id", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
10 years ago
public string SendingUserId { get; set; }
10 years ago
[ApiMember(Name = "ExcludeLibraries", Description = "ExcludeLibraries", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
public string ExcludedLibraries { get; set; }
[ApiMember(Name = "ExcludedChannels", Description = "ExcludedChannels", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
public string ExcludedChannels { get; set; }
[ApiMember(Name = "EnableLiveTv", Description = "EnableLiveTv", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
public bool EnableLiveTv { get; set; }
10 years ago
}
[Route("/Connect/Pending", "GET", Summary = "Creates a Connect link for a user")]
[Authenticated(Roles = "Admin")]
10 years ago
public class GetPendingGuests : IReturn<List<ConnectAuthorization>>
{
}
[Route("/Connect/Pending", "DELETE", Summary = "Deletes a Connect link for a user")]
[Authenticated(Roles = "Admin")]
10 years ago
public class DeleteAuthorization : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Authorization Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
public string Id { get; set; }
}
[Route("/Connect/Exchange", "GET", Summary = "Gets the corresponding local user from a connect user id")]
[Authenticated]
public class GetLocalUser : IReturn<ConnectAuthenticationExchangeResult>
{
[ApiMember(Name = "ConnectUserId", Description = "ConnectUserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string ConnectUserId { get; set; }
}
public class ConnectService : BaseApiService
{
private readonly IConnectManager _connectManager;
private readonly IUserManager _userManager;
public ConnectService(IConnectManager connectManager, IUserManager userManager)
{
_connectManager = connectManager;
_userManager = userManager;
}
public object Post(CreateConnectLink request)
{
return _connectManager.LinkUser(request.Id, request.ConnectUsername);
}
10 years ago
public object Post(CreateConnectInvite request)
{
10 years ago
var excludeLibraries = (request.ExcludedLibraries ?? string.Empty)
.Split(',')
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToArray();
var excludedChannels = (request.ExcludedChannels ?? string.Empty)
.Split(',')
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToArray();
return _connectManager.InviteUser(new ConnectAuthorizationRequest
{
ConnectUserName = request.ConnectUsername,
SendingUserId = request.SendingUserId,
ExcludedLibraries = excludeLibraries,
ExcludedChannels = excludedChannels,
EnableLiveTv = request.EnableLiveTv
});
10 years ago
}
public void Delete(DeleteConnectLink request)
{
10 years ago
var task = _connectManager.RemoveConnect(request.Id);
Task.WaitAll(task);
}
10 years ago
public async Task<object> Get(GetPendingGuests request)
{
var result = await _connectManager.GetPendingGuests().ConfigureAwait(false);
return ToOptimizedResult(result);
}
public void Delete(DeleteAuthorization request)
{
var task = _connectManager.CancelAuthorization(request.Id);
Task.WaitAll(task);
}
public async Task<object> Get(GetLocalUser request)
{
var user = await _connectManager.GetLocalUser(request.ConnectUserId).ConfigureAwait(false);
if (user == null)
{
throw new ResourceNotFoundException();
}
return ToOptimizedResult(new ConnectAuthenticationExchangeResult
{
AccessToken = user.ConnectAccessKey,
LocalUserId = user.Id.ToString("N")
});
}
}
}