aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Library/LibraryService.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-02-06 00:39:07 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-02-06 00:39:07 -0500
commitb6d59c7688fc39d4689bc9070a7a99271d5b41ee (patch)
tree214166a434a1007cea7c7b4396a001ed9c1efddc /MediaBrowser.Api/Library/LibraryService.cs
parent4ae6b5f675ba922dadd532870ef97dfa28ff3db3 (diff)
fixes #1001 - Support downloading
Diffstat (limited to 'MediaBrowser.Api/Library/LibraryService.cs')
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs56
1 files changed, 38 insertions, 18 deletions
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index f147234fe..a97e2b52e 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -226,6 +226,18 @@ namespace MediaBrowser.Api.Library
public string TvdbId { get; set; }
}
+ [Route("/Items/{Id}/Download", "GET", Summary = "Downloads item media")]
+ [Authenticated(Roles = "download")]
+ public class GetDownload
+ {
+ /// <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 string Id { get; set; }
+ }
+
/// <summary>
/// Class LibraryService
/// </summary>
@@ -273,7 +285,7 @@ namespace MediaBrowser.Api.Library
}
var dtoOptions = GetDtoOptions(request);
-
+
var result = new ItemsResult
{
TotalRecordCount = items.Count,
@@ -289,6 +301,28 @@ namespace MediaBrowser.Api.Library
Task.Run(() => _libraryManager.ValidateMediaLibrary(new Progress<double>(), CancellationToken.None));
}
+ public object Get(GetDownload request)
+ {
+ var item = _libraryManager.GetItemById(request.Id);
+
+ if (!item.CanDelete())
+ {
+ throw new ArgumentException("Item does not support downloading");
+ }
+
+ var headers = new Dictionary<string, string>();
+
+ // Quotes are valid in linux. They'll possibly cause issues here
+ var filename = Path.GetFileName(item.Path).Replace("\"", string.Empty);
+ headers["Content-Disposition"] = string.Format("inline; filename=\"{0}\"", filename);
+
+ return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
+ {
+ Path = item.Path,
+ ResponseHeaders = headers
+ });
+ }
+
public object Get(GetFile request)
{
var item = _libraryManager.GetItemById(request.Id);
@@ -347,7 +381,7 @@ namespace MediaBrowser.Api.Library
var dtoOptions = GetDtoOptions(request);
BaseItem parent = item.Parent;
-
+
while (parent != null)
{
if (user != null)
@@ -458,23 +492,9 @@ namespace MediaBrowser.Api.Library
var auth = _authContext.GetAuthorizationInfo(Request);
var user = _userManager.GetUserById(auth.UserId);
- if (item is Playlist || item is BoxSet)
+ if (!item.CanDelete(user))
{
- // For now this is allowed if user can see the playlist
- }
- else if (item is ILiveTvRecording)
- {
- if (!user.Policy.EnableLiveTvManagement)
- {
- throw new UnauthorizedAccessException();
- }
- }
- else
- {
- if (!user.Policy.EnableContentDeletion)
- {
- throw new UnauthorizedAccessException();
- }
+ throw new UnauthorizedAccessException();
}
var task = _libraryManager.DeleteItem(item);