aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Controllers/DlnaController.cs
blob: 68cd144f4ea7305ddafd48b9dc51d631ce50614f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#nullable enable

using System.Collections.Generic;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dlna;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Jellyfin.Api.Controllers
{
    /// <summary>
    /// Dlna Controller.
    /// </summary>
    [Authenticated(Roles = "Admin")]
    public class DlnaController : BaseJellyfinApiController
    {
        private readonly IDlnaManager _dlnaManager;

        /// <summary>
        /// Initializes a new instance of the <see cref="DlnaController"/> class.
        /// </summary>
        /// <param name="dlnaManager">Instance of the <see cref="IDlnaManager"/> interface.</param>
        public DlnaController(IDlnaManager dlnaManager)
        {
            _dlnaManager = dlnaManager;
        }

        /// <summary>
        /// Get profile infos.
        /// </summary>
        /// <returns>Profile infos.</returns>
        [HttpGet("ProfileInfos")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public IEnumerable<DeviceProfileInfo> GetProfileInfos()
        {
            return _dlnaManager.GetProfileInfos();
        }

        /// <summary>
        /// Gets the default profile.
        /// </summary>
        /// <returns>Default profile.</returns>
        [HttpGet("Profiles/Default")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public ActionResult<DeviceProfileInfo> GetDefaultProfile()
        {
            return Ok(_dlnaManager.GetDefaultProfile());
        }

        /// <summary>
        /// Gets a single profile.
        /// </summary>
        /// <param name="id">Profile Id.</param>
        /// <returns>Profile.</returns>
        [HttpGet("Profiles/{Id}")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult<DeviceProfileInfo> GetProfile([FromRoute] string id)
        {
            var profile = _dlnaManager.GetProfile(id);
            if (profile == null)
            {
                return NotFound();
            }

            return Ok(profile);
        }

        /// <summary>
        /// Deletes a profile.
        /// </summary>
        /// <param name="id">Profile id.</param>
        /// <returns>Status.</returns>
        [HttpDelete("Profiles/{Id}")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult DeleteProfile([FromRoute] string id)
        {
            var existingDeviceProfile = _dlnaManager.GetProfile(id);
            if (existingDeviceProfile == null)
            {
                return NotFound();
            }

            _dlnaManager.DeleteProfile(id);
            return Ok();
        }

        /// <summary>
        /// Creates a profile.
        /// </summary>
        /// <param name="deviceProfile">Device profile.</param>
        /// <returns>Status.</returns>
        [HttpPost("Profiles")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        public ActionResult CreateProfile([FromBody] DeviceProfile deviceProfile)
        {
            _dlnaManager.CreateProfile(deviceProfile);
            return Ok();
        }

        /// <summary>
        /// Updates a profile.
        /// </summary>
        /// <param name="id">Profile id.</param>
        /// <param name="deviceProfile">Device profile.</param>
        /// <returns>Status.</returns>
        [HttpPost("Profiles/{Id}")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status404NotFound)]
        public ActionResult UpdateProfile([FromRoute] string id, [FromBody] DeviceProfile deviceProfile)
        {
            var existingDeviceProfile = _dlnaManager.GetProfile(id);
            if (existingDeviceProfile == null)
            {
                return NotFound();
            }

            _dlnaManager.UpdateProfile(deviceProfile);
            return Ok();
        }
    }
}