mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
API: Documenting the track's api
This commit is contained in:
parent
e4d703223c
commit
38ec742db6
@ -52,7 +52,7 @@ namespace Kyoo.Abstractions.Models
|
|||||||
Subtitle = 3,
|
Subtitle = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The stream is an attachement (a font, an image or something else).
|
/// The stream is an attachment (a font, an image or something else).
|
||||||
/// Only fonts are handled by kyoo but they are not saved to the database.
|
/// Only fonts are handled by kyoo but they are not saved to the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Attachment = 4
|
Attachment = 4
|
||||||
|
@ -16,58 +16,69 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
using Kyoo.Abstractions.Models.Exceptions;
|
using Kyoo.Abstractions.Models.Attributes;
|
||||||
using Kyoo.Abstractions.Models.Permissions;
|
using Kyoo.Abstractions.Models.Permissions;
|
||||||
|
using Kyoo.Abstractions.Models.Utils;
|
||||||
using Kyoo.Core.Models.Options;
|
using Kyoo.Core.Models.Options;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using static Kyoo.Abstractions.Models.Utils.Constants;
|
||||||
|
|
||||||
namespace Kyoo.Core.Api
|
namespace Kyoo.Core.Api
|
||||||
{
|
{
|
||||||
[Route("api/track")]
|
/// <summary>
|
||||||
|
/// Information about one or multiple <see cref="Track"/>.
|
||||||
|
/// </summary>
|
||||||
[Route("api/tracks")]
|
[Route("api/tracks")]
|
||||||
|
[Route("api/track", Order = AlternativeRoute)]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[PartialPermission(nameof(Track))]
|
[PartialPermission(nameof(Track))]
|
||||||
|
[ApiDefinition("Tracks", Group = ResourcesGroup)]
|
||||||
public class TrackApi : CrudApi<Track>
|
public class TrackApi : CrudApi<Track>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The library manager used to modify or retrieve information in the data store.
|
||||||
|
/// </summary>
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new <see cref="TrackApi"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryManager">
|
||||||
|
/// The library manager used to modify or retrieve information in the data store.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="options">
|
||||||
|
/// Options used to retrieve the base URL of Kyoo.
|
||||||
|
/// </param>
|
||||||
public TrackApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
public TrackApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.TrackRepository, options.Value.PublicUrl)
|
: base(libraryManager.TrackRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id:int}/episode")]
|
/// <summary>
|
||||||
|
/// Get track's episode
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Get the episode that uses this track.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="identifier">The ID or slug of the <see cref="Track"/>.</param>
|
||||||
|
/// <returns>The episode that uses this track.</returns>
|
||||||
|
/// <response code="404">No track with the given ID or slug could be found.</response>
|
||||||
|
[HttpGet("{identifier:id}/episode")]
|
||||||
[PartialPermission(Kind.Read)]
|
[PartialPermission(Kind.Read)]
|
||||||
public async Task<ActionResult<Episode>> GetEpisode(int id)
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
{
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
try
|
public async Task<ActionResult<Episode>> GetEpisode(Identifier identifier)
|
||||||
{
|
|
||||||
return await _libraryManager.Get<Episode>(x => x.Tracks.Any(y => y.ID == id));
|
|
||||||
}
|
|
||||||
catch (ItemNotFoundException)
|
|
||||||
{
|
{
|
||||||
|
Episode ret = await _libraryManager.GetOrDefault(identifier.IsContainedIn<Episode, Track>(x => x.Tracks));
|
||||||
|
if (ret == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{slug}/episode")]
|
|
||||||
[PartialPermission(Kind.Read)]
|
|
||||||
public async Task<ActionResult<Episode>> GetEpisode(string slug)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await _libraryManager.Get<Episode>(x => x.Tracks.Any(y => y.Slug == slug));
|
|
||||||
}
|
|
||||||
catch (ItemNotFoundException)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,9 @@ namespace Kyoo.Tests
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
typeof(Track),
|
typeof(Track),
|
||||||
() => new Track
|
() =>
|
||||||
|
{
|
||||||
|
Track ret = new()
|
||||||
{
|
{
|
||||||
ID = 1,
|
ID = 1,
|
||||||
EpisodeID = 1,
|
EpisodeID = 1,
|
||||||
@ -249,12 +251,15 @@ namespace Kyoo.Tests
|
|||||||
Language = "eng",
|
Language = "eng",
|
||||||
Path = "/path",
|
Path = "/path",
|
||||||
Title = "Subtitle track",
|
Title = "Subtitle track",
|
||||||
|
Episode = Get<Episode>(),
|
||||||
Type = StreamType.Subtitle,
|
Type = StreamType.Subtitle,
|
||||||
EpisodeSlug = Get<Episode>().Slug,
|
|
||||||
IsDefault = true,
|
IsDefault = true,
|
||||||
IsExternal = false,
|
IsExternal = false,
|
||||||
IsForced = false,
|
IsForced = false,
|
||||||
TrackIndex = 1
|
TrackIndex = 1
|
||||||
|
};
|
||||||
|
ret.Episode = null;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user