| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using MediaBrowser.Common.Api; |
| | | 5 | | using MediaBrowser.Model.Entities; |
| | | 6 | | using MediaBrowser.Model.Globalization; |
| | | 7 | | using Microsoft.AspNetCore.Authorization; |
| | | 8 | | using Microsoft.AspNetCore.Http; |
| | | 9 | | using Microsoft.AspNetCore.Mvc; |
| | | 10 | | |
| | | 11 | | namespace Jellyfin.Api.Controllers; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Localization controller. |
| | | 15 | | /// </summary> |
| | | 16 | | [Authorize(Policy = Policies.FirstTimeSetupOrDefault)] |
| | | 17 | | public class LocalizationController : BaseJellyfinApiController |
| | | 18 | | { |
| | | 19 | | private readonly ILocalizationManager _localization; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="LocalizationController"/> class. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param> |
| | 0 | 25 | | public LocalizationController(ILocalizationManager localization) |
| | | 26 | | { |
| | 0 | 27 | | _localization = localization; |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets known cultures. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <response code="200">Known cultures returned.</response> |
| | | 34 | | /// <returns>An <see cref="OkResult"/> containing the list of cultures.</returns> |
| | | 35 | | [HttpGet("Cultures")] |
| | | 36 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 37 | | public ActionResult<IEnumerable<CultureDto>> GetCultures() |
| | | 38 | | { |
| | 0 | 39 | | var allCultures = _localization.GetCultures(); |
| | | 40 | | |
| | 0 | 41 | | var distinctCultures = allCultures |
| | 0 | 42 | | .DistinctBy(c => c.DisplayName, StringComparer.OrdinalIgnoreCase) |
| | 0 | 43 | | .OrderBy(c => c.DisplayName) |
| | 0 | 44 | | .AsEnumerable(); |
| | | 45 | | |
| | 0 | 46 | | return Ok(distinctCultures); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets known countries. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <response code="200">Known countries returned.</response> |
| | | 53 | | /// <returns>An <see cref="OkResult"/> containing the list of countries.</returns> |
| | | 54 | | [HttpGet("Countries")] |
| | | 55 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 56 | | public ActionResult<IReadOnlyList<CountryInfo>> GetCountries() |
| | | 57 | | { |
| | 0 | 58 | | return Ok(_localization.GetCountries()); |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Gets known parental ratings. |
| | | 63 | | /// </summary> |
| | | 64 | | /// <response code="200">Known parental ratings returned.</response> |
| | | 65 | | /// <returns>An <see cref="OkResult"/> containing the list of parental ratings.</returns> |
| | | 66 | | [HttpGet("ParentalRatings")] |
| | | 67 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 68 | | public ActionResult<IReadOnlyList<ParentalRating>> GetParentalRatings() |
| | | 69 | | { |
| | 0 | 70 | | return Ok(_localization.GetParentalRatings()); |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Gets localization options. |
| | | 75 | | /// </summary> |
| | | 76 | | /// <response code="200">Localization options returned.</response> |
| | | 77 | | /// <returns>An <see cref="OkResult"/> containing the list of localization options.</returns> |
| | | 78 | | [HttpGet("Options")] |
| | | 79 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 80 | | public ActionResult<IEnumerable<LocalizationOption>> GetLocalizationOptions() |
| | | 81 | | { |
| | 0 | 82 | | return Ok(_localization.GetLocalizationOptions()); |
| | | 83 | | } |
| | | 84 | | } |