aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Library/LibraryService.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-02-11 22:54:31 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-02-11 22:54:31 -0500
commitea92065df0321039b4a6433e9f5d2a7269d720a6 (patch)
treef757d6ee2154e31e3ce10c286d175189146235af /MediaBrowser.Api/Library/LibraryService.cs
parent306c5041f032a539612522d9acdd59596b075719 (diff)
sync updates
Diffstat (limited to 'MediaBrowser.Api/Library/LibraryService.cs')
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs57
1 files changed, 49 insertions, 8 deletions
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index 9027685b1..85cc879f4 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -1,15 +1,19 @@
-using MediaBrowser.Controller.Channels;
+using MediaBrowser.Controller.Activity;
+using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Session;
+using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Querying;
using ServiceStack;
using System;
@@ -251,24 +255,24 @@ namespace MediaBrowser.Api.Library
private readonly IUserDataManager _userDataManager;
private readonly IDtoService _dtoService;
- private readonly IChannelManager _channelManager;
- private readonly ISessionManager _sessionManager;
private readonly IAuthorizationContext _authContext;
+ private readonly IActivityManager _activityManager;
+ private readonly ILocalizationManager _localization;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager,
- IDtoService dtoService, IUserDataManager userDataManager, IChannelManager channelManager, ISessionManager sessionManager, IAuthorizationContext authContext)
+ IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization)
{
_itemRepo = itemRepo;
_libraryManager = libraryManager;
_userManager = userManager;
_dtoService = dtoService;
_userDataManager = userDataManager;
- _channelManager = channelManager;
- _sessionManager = sessionManager;
_authContext = authContext;
+ _activityManager = activityManager;
+ _localization = localization;
}
public object Get(GetMediaFolders request)
@@ -302,10 +306,23 @@ namespace MediaBrowser.Api.Library
public object Get(GetDownload request)
{
var item = _libraryManager.GetItemById(request.Id);
+ var auth = _authContext.GetAuthorizationInfo(Request);
+
+ var user = _userManager.GetUserById(auth.UserId);
- if (!item.CanDelete())
+ if (user != null)
{
- throw new ArgumentException("Item does not support downloading");
+ if (!item.CanDownload(user))
+ {
+ throw new ArgumentException("Item does not support downloading");
+ }
+ }
+ else
+ {
+ if (!item.CanDownload())
+ {
+ throw new ArgumentException("Item does not support downloading");
+ }
}
var headers = new Dictionary<string, string>();
@@ -314,6 +331,11 @@ namespace MediaBrowser.Api.Library
var filename = Path.GetFileName(item.Path).Replace("\"", string.Empty);
headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename);
+ if (user != null)
+ {
+ LogDownload(item, user, auth);
+ }
+
return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
{
Path = item.Path,
@@ -321,6 +343,25 @@ namespace MediaBrowser.Api.Library
});
}
+ private async void LogDownload(BaseItem item, User user, AuthorizationInfo auth)
+ {
+ try
+ {
+ await _activityManager.Create(new ActivityLogEntry
+ {
+ Name = string.Format(_localization.GetLocalizedString("UserDownloadingItemWithValues"), user.Name, item.Name),
+ Type = "UserDownloadingContent",
+ ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), auth.Client, auth.Device),
+ UserId = auth.UserId
+
+ }).ConfigureAwait(false);
+ }
+ catch
+ {
+ // Logged at lower levels
+ }
+ }
+
public object Get(GetFile request)
{
var item = _libraryManager.GetItemById(request.Id);