2014-10-11 20:38:13 +00:00
|
|
|
|
using MediaBrowser.Controller.Devices;
|
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
|
using MediaBrowser.Model.Devices;
|
2014-10-13 20:14:53 +00:00
|
|
|
|
using MediaBrowser.Model.Session;
|
2014-10-11 20:38:13 +00:00
|
|
|
|
using ServiceStack;
|
|
|
|
|
using ServiceStack.Web;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Devices
|
|
|
|
|
{
|
|
|
|
|
[Route("/Devices", "GET", Summary = "Gets all devices")]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2014-10-11 20:38:13 +00:00
|
|
|
|
public class GetDevices : IReturn<List<DeviceInfo>>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "SupportsContentUploading", Description = "SupportsContentUploading", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public bool? SupportsContentUploading { get; set; }
|
2014-12-11 06:20:28 +00:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "SupportsDeviceId", Description = "SupportsDeviceId", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public bool? SupportsDeviceId { get; set; }
|
2014-10-11 20:38:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Devices", "DELETE", Summary = "Deletes a device")]
|
|
|
|
|
public class DeleteDevice
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Device Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Devices/CameraUploads", "GET", Summary = "Gets camera upload history for a device")]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
[Authenticated]
|
2014-10-11 20:38:13 +00:00
|
|
|
|
public class GetCameraUploads : IReturn<ContentUploadHistory>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Device Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string DeviceId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Devices/CameraUploads", "POST", Summary = "Uploads content")]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
[Authenticated]
|
2014-10-11 20:38:13 +00:00
|
|
|
|
public class PostCameraUpload : IRequiresRequestStream, IReturnVoid
|
|
|
|
|
{
|
2014-10-12 01:46:02 +00:00
|
|
|
|
[ApiMember(Name = "DeviceId", Description = "Device Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2014-10-11 20:38:13 +00:00
|
|
|
|
public string DeviceId { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "Album", Description = "Album", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string Album { get; set; }
|
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "Name", Description = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
2014-10-24 04:54:35 +00:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string Id { get; set; }
|
2014-10-11 20:38:13 +00:00
|
|
|
|
|
|
|
|
|
public Stream RequestStream { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 20:14:53 +00:00
|
|
|
|
[Route("/Devices/Info", "GET", Summary = "Gets device info")]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
[Authenticated]
|
2014-10-13 20:14:53 +00:00
|
|
|
|
public class GetDeviceInfo : IReturn<DeviceInfo>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Device Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Devices/Capabilities", "GET", Summary = "Gets device capabilities")]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
[Authenticated]
|
2014-10-13 20:14:53 +00:00
|
|
|
|
public class GetDeviceCapabilities : IReturn<ClientCapabilities>
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Device Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Devices/Options", "POST", Summary = "Updates device options")]
|
2014-11-15 02:31:03 +00:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2014-10-13 20:14:53 +00:00
|
|
|
|
public class PostDeviceOptions : DeviceOptions, IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "Device Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
2014-11-15 02:31:03 +00:00
|
|
|
|
|
2014-10-11 20:38:13 +00:00
|
|
|
|
public class DeviceService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly IDeviceManager _deviceManager;
|
|
|
|
|
|
|
|
|
|
public DeviceService(IDeviceManager deviceManager)
|
|
|
|
|
{
|
|
|
|
|
_deviceManager = deviceManager;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 20:14:53 +00:00
|
|
|
|
public void Post(PostDeviceOptions request)
|
|
|
|
|
{
|
|
|
|
|
var task = _deviceManager.UpdateDeviceInfo(request.Id, new DeviceOptions
|
|
|
|
|
{
|
|
|
|
|
CustomName = request.CustomName,
|
|
|
|
|
CameraUploadPath = request.CameraUploadPath
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetDeviceInfo request)
|
|
|
|
|
{
|
|
|
|
|
return ToOptimizedResult(_deviceManager.GetDevice(request.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetDeviceCapabilities request)
|
|
|
|
|
{
|
|
|
|
|
return ToOptimizedResult(_deviceManager.GetCapabilities(request.Id));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-11 20:38:13 +00:00
|
|
|
|
public object Get(GetDevices request)
|
|
|
|
|
{
|
|
|
|
|
var devices = _deviceManager.GetDevices();
|
|
|
|
|
|
|
|
|
|
if (request.SupportsContentUploading.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = request.SupportsContentUploading.Value;
|
|
|
|
|
|
2014-10-13 20:14:53 +00:00
|
|
|
|
devices = devices.Where(i => _deviceManager.GetCapabilities(i.Id).SupportsContentUploading == val);
|
2014-12-11 06:20:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.SupportsDeviceId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var val = request.SupportsDeviceId.Value;
|
|
|
|
|
|
|
|
|
|
devices = devices.Where(i => _deviceManager.GetCapabilities(i.Id).SupportsDeviceId == val);
|
2014-10-11 20:38:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(devices.ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Get(GetCameraUploads request)
|
|
|
|
|
{
|
|
|
|
|
return ToOptimizedResult(_deviceManager.GetCameraUploadHistory(request.DeviceId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(DeleteDevice request)
|
|
|
|
|
{
|
|
|
|
|
var task = _deviceManager.DeleteDevice(request.Id);
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Post(PostCameraUpload request)
|
|
|
|
|
{
|
2014-10-12 01:46:02 +00:00
|
|
|
|
var deviceId = Request.QueryString["DeviceId"];
|
2014-10-11 20:38:13 +00:00
|
|
|
|
var album = Request.QueryString["Album"];
|
2014-10-24 04:54:35 +00:00
|
|
|
|
var id = Request.QueryString["Id"];
|
2014-10-11 20:38:13 +00:00
|
|
|
|
var name = Request.QueryString["Name"];
|
|
|
|
|
|
|
|
|
|
var task = _deviceManager.AcceptCameraUpload(deviceId, request.RequestStream, new LocalFileInfo
|
|
|
|
|
{
|
|
|
|
|
MimeType = Request.ContentType,
|
|
|
|
|
Album = album,
|
|
|
|
|
Name = name,
|
2014-10-24 04:54:35 +00:00
|
|
|
|
Id = id
|
2014-10-11 20:38:13 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|