Skip to content

Commit

Permalink
Merge pull request #1043 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
3.0.5557.0
  • Loading branch information
LukePulverenti committed Mar 19, 2015
2 parents d589e23 + aae750d commit d6d4124
Show file tree
Hide file tree
Showing 597 changed files with 14,206 additions and 6,002 deletions.
27 changes: 22 additions & 5 deletions MediaBrowser.Api/ApiEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected virtual void Dispose(bool dispose)
/// Called when [transcode beginning].
/// </summary>
/// <param name="path">The path.</param>
/// <param name="streamId">The stream identifier.</param>
/// <param name="transcodingJobId">The transcoding job identifier.</param>
/// <param name="type">The type.</param>
/// <param name="process">The process.</param>
Expand All @@ -140,6 +141,7 @@ protected virtual void Dispose(bool dispose)
/// <param name="cancellationTokenSource">The cancellation token source.</param>
/// <returns>TranscodingJob.</returns>
public TranscodingJob OnTranscodeBeginning(string path,
string streamId,
string transcodingJobId,
TranscodingJobType type,
Process process,
Expand All @@ -157,7 +159,8 @@ public TranscodingJob OnTranscodeBeginning(string path,
ActiveRequestCount = 1,
DeviceId = deviceId,
CancellationTokenSource = cancellationTokenSource,
Id = transcodingJobId
Id = transcodingJobId,
StreamId = streamId
};

_activeTranscodingJobs.Add(job);
Expand Down Expand Up @@ -316,17 +319,26 @@ private void OnTranscodeKillTimerStopped(object state)
/// Kills the single transcoding job.
/// </summary>
/// <param name="deviceId">The device id.</param>
/// <param name="streamId">The stream identifier.</param>
/// <param name="deleteFiles">The delete files.</param>
/// <returns>Task.</returns>
/// <exception cref="ArgumentNullException">deviceId</exception>
internal void KillTranscodingJobs(string deviceId, Func<string, bool> deleteFiles)
internal void KillTranscodingJobs(string deviceId, string streamId, Func<string, bool> deleteFiles)
{
if (string.IsNullOrEmpty(deviceId))
{
throw new ArgumentNullException("deviceId");
}

KillTranscodingJobs(j => string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase), deleteFiles);
KillTranscodingJobs(j =>
{
if (string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase))
{
return string.IsNullOrWhiteSpace(streamId) || string.Equals(streamId, j.StreamId, StringComparison.OrdinalIgnoreCase);
}

return false;

}, deleteFiles);
}

/// <summary>
Expand All @@ -335,7 +347,7 @@ internal void KillTranscodingJobs(string deviceId, Func<string, bool> deleteFile
/// <param name="killJob">The kill job.</param>
/// <param name="deleteFiles">The delete files.</param>
/// <returns>Task.</returns>
internal void KillTranscodingJobs(Func<TranscodingJob, bool> killJob, Func<string, bool> deleteFiles)
private void KillTranscodingJobs(Func<TranscodingJob, bool> killJob, Func<string, bool> deleteFiles)
{
var jobs = new List<TranscodingJob>();

Expand Down Expand Up @@ -516,6 +528,11 @@ private void DeleteHlsPartialStreamFiles(string outputFilePath)
/// </summary>
public class TranscodingJob
{
/// <summary>
/// Gets or sets the stream identifier.
/// </summary>
/// <value>The stream identifier.</value>
public string StreamId { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
Expand Down
30 changes: 27 additions & 3 deletions MediaBrowser.Api/BaseApiService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediaBrowser.Controller.Dto;
using System.Threading.Tasks;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
Expand Down Expand Up @@ -72,6 +73,29 @@ protected object ToOptimizedResultUsingCache<T>(Guid cacheKey, DateTime? lastDat
return ResultFactory.GetOptimizedResultUsingCache(Request, cacheKey, lastDateModified, cacheDuration, factoryFn);
}

protected void AssertCanUpdateUser(IUserManager userManager, string userId)
{
var auth = AuthorizationContext.GetAuthorizationInfo(Request);

var authenticatedUser = userManager.GetUserById(auth.UserId);

// If they're going to update the record of another user, they must be an administrator
if (!string.Equals(userId, auth.UserId, StringComparison.OrdinalIgnoreCase))
{
if (!authenticatedUser.Policy.IsAdministrator)
{
throw new SecurityException("Unauthorized access.");
}
}
else
{
if (!authenticatedUser.Policy.EnableUserPreferenceAccess)
{
throw new SecurityException("Unauthorized access.");
}
}
}

/// <summary>
/// To the optimized serialized result using cache.
/// </summary>
Expand All @@ -88,9 +112,9 @@ protected object ToOptimizedSerializedResultUsingCache<T>(T result)
/// Gets the session.
/// </summary>
/// <returns>SessionInfo.</returns>
protected SessionInfo GetSession()
protected async Task<SessionInfo> GetSession()
{
var session = SessionContext.GetSession(Request);
var session = await SessionContext.GetSession(Request).ConfigureAwait(false);

if (session == null)
{
Expand Down
55 changes: 54 additions & 1 deletion MediaBrowser.Api/ConnectService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using MediaBrowser.Common.Extensions;
using System;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Connect;
using MediaBrowser.Model.Dto;
using ServiceStack;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -73,6 +75,28 @@ public class GetLocalUser : IReturn<ConnectAuthenticationExchangeResult>
public string ConnectUserId { get; set; }
}

[Route("/Connect/Supporters", "GET")]
[Authenticated(Roles = "Admin")]
public class GetConnectSupporterSummary : IReturn<ConnectSupporterSummary>
{
}

[Route("/Connect/Supporters", "DELETE")]
[Authenticated(Roles = "Admin")]
public class RemoveConnectSupporter : IReturnVoid
{
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
public string Id { get; set; }
}

[Route("/Connect/Supporters", "POST")]
[Authenticated(Roles = "Admin")]
public class AddConnectSupporter : IReturnVoid
{
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Id { get; set; }
}

public class ConnectService : BaseApiService
{
private readonly IConnectManager _connectManager;
Expand All @@ -84,6 +108,35 @@ public ConnectService(IConnectManager connectManager, IUserManager userManager)
_userManager = userManager;
}

public async Task<object> Get(GetConnectSupporterSummary request)
{
var result = await _connectManager.GetConnectSupporterSummary().ConfigureAwait(false);
var existingConnectUserIds = result.Users.Select(i => i.Id).ToList();

result.EligibleUsers = _userManager.Users
.Where(i => !string.IsNullOrWhiteSpace(i.ConnectUserId))
.Where(i => !existingConnectUserIds.Contains(i.ConnectUserId, StringComparer.OrdinalIgnoreCase))
.OrderBy(i => i.Name)
.Select(i => _userManager.GetUserDto(i))
.ToList();

return ToOptimizedResult(result);
}

public void Delete(RemoveConnectSupporter request)
{
var task = _connectManager.RemoveConnectSupporter(request.Id);

Task.WaitAll(task);
}

public void Post(AddConnectSupporter request)
{
var task = _connectManager.AddConnectSupporter(request.Id);

Task.WaitAll(task);
}

public object Post(CreateConnectLink request)
{
return _connectManager.LinkUser(request.Id, request.ConnectUsername);
Expand Down
31 changes: 17 additions & 14 deletions MediaBrowser.Api/Images/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public class GetItemImage : ImageRequest
/// Class UpdateItemImageIndex
/// </summary>
[Route("/Items/{Id}/Images/{Type}/{Index}/Index", "POST", Summary = "Updates the index for an item image")]
[Authenticated]
[Authenticated(Roles = "admin")]
public class UpdateItemImageIndex : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
public string Id { get; set; }

/// <summary>
/// Gets or sets the type of the image.
Expand Down Expand Up @@ -143,23 +143,23 @@ public class GetUserImage : ImageRequest
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
public string Id { get; set; }
}

/// <summary>
/// Class DeleteItemImage
/// </summary>
[Route("/Items/{Id}/Images/{Type}", "DELETE")]
[Route("/Items/{Id}/Images/{Type}/{Index}", "DELETE")]
[Authenticated]
[Authenticated(Roles = "admin")]
public class DeleteItemImage : DeleteImageRequest, IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public Guid Id { get; set; }
public string Id { get; set; }
}

/// <summary>
Expand All @@ -175,7 +175,7 @@ public class DeleteUserImage : DeleteImageRequest, IReturnVoid
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public Guid Id { get; set; }
public string Id { get; set; }
}

/// <summary>
Expand All @@ -191,7 +191,7 @@ public class PostUserImage : DeleteImageRequest, IRequiresRequestStream, IReturn
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public Guid Id { get; set; }
public string Id { get; set; }

/// <summary>
/// The raw Http Request Input Stream
Expand All @@ -206,7 +206,7 @@ public class PostUserImage : DeleteImageRequest, IRequiresRequestStream, IReturn
[Route("/Items/{Id}/Images/{Type}", "POST")]
[Route("/Items/{Id}/Images/{Type}/{Index}", "POST")]
[Api(Description = "Posts an item image")]
[Authenticated]
[Authenticated(Roles = "admin")]
public class PostItemImage : DeleteImageRequest, IRequiresRequestStream, IReturnVoid
{
/// <summary>
Expand Down Expand Up @@ -318,7 +318,7 @@ private ImageInfo GetImageInfo(IHasImages item, ItemImageInfo info, int? imageIn

try
{
var size = _imageProcessor.GetImageSize(info.Path, info.DateModified);
var size = _imageProcessor.GetImageSize(info);

width = Convert.ToInt32(size.Width);
height = Convert.ToInt32(size.Height);
Expand Down Expand Up @@ -417,11 +417,12 @@ public object Head(GetItemByNameImage request)
/// <param name="request">The request.</param>
public void Post(PostUserImage request)
{
var id = new Guid(GetPathValue(1));
var userId = GetPathValue(1);
AssertCanUpdateUser(_userManager, userId);

request.Type = (ImageType)Enum.Parse(typeof(ImageType), GetPathValue(3), true);

var item = _userManager.GetUserById(id);
var item = _userManager.GetUserById(userId);

var task = PostImage(item, request.RequestStream, request.Type, Request.ContentType);

Expand All @@ -434,7 +435,7 @@ public void Post(PostUserImage request)
/// <param name="request">The request.</param>
public void Post(PostItemImage request)
{
var id = new Guid(GetPathValue(1));
var id = GetPathValue(1);

request.Type = (ImageType)Enum.Parse(typeof(ImageType), GetPathValue(3), true);

Expand All @@ -451,7 +452,10 @@ public void Post(PostItemImage request)
/// <param name="request">The request.</param>
public void Delete(DeleteUserImage request)
{
var item = _userManager.GetUserById(request.Id);
var userId = request.Id;
AssertCanUpdateUser(_userManager, userId);

var item = _userManager.GetUserById(userId);

var task = item.DeleteImage(request.Type, request.Index ?? 0);

Expand Down Expand Up @@ -492,7 +496,6 @@ public void Post(UpdateItemImageIndex request)
/// <param name="currentIndex">Index of the current.</param>
/// <param name="newIndex">The new index.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentException">The change index operation is only applicable to backdrops and screenshots</exception>
private Task UpdateItemIndex(IHasImages item, ImageType type, int currentIndex, int newIndex)
{
return item.SwapImages(type, currentIndex, newIndex);
Expand Down
19 changes: 5 additions & 14 deletions MediaBrowser.Api/ItemLookupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,15 @@ public void Post(ApplySearchCriteria request)
//}
item.ProviderIds = request.ProviderIds;

var service = new ItemRefreshService(_libraryManager)
var task = _providerManager.RefreshFullItem(item, new MetadataRefreshOptions
{
Logger = Logger,
Request = Request,
ResultFactory = ResultFactory,
SessionContext = SessionContext,
AuthorizationContext = AuthorizationContext
};

service.Post(new RefreshItem
{
Id = request.Id,
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = ImageRefreshMode.FullRefresh,
ReplaceAllMetadata = true,
ReplaceAllImages = request.ReplaceAllImages,
Recursive = true
});
ReplaceAllImages = request.ReplaceAllImages

}, CancellationToken.None);
Task.WaitAll(task);
}

/// <summary>
Expand Down
Loading

0 comments on commit d6d4124

Please sign in to comment.