diff --git a/Kyoo.Common/Models/Page.cs b/Kyoo.Common/Models/Page.cs index 023aac3e..1c8cff69 100644 --- a/Kyoo.Common/Models/Page.cs +++ b/Kyoo.Common/Models/Page.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; @@ -12,17 +13,17 @@ namespace Kyoo.Models /// /// The link of the current page. /// - public string This { get; } + public Uri This { get; } /// /// The link of the first page. /// - public string First { get; } + public Uri First { get; } /// /// The link of the next page. /// - public string Next { get; } + public Uri Next { get; } /// /// The number of items in the current page. @@ -42,7 +43,7 @@ namespace Kyoo.Models /// The link of the current page. /// The link of the next page. /// The link of the first page. - public Page(ICollection items, string @this, string next, string first) + public Page(ICollection items, Uri @this, Uri next, Uri first) { Items = items; This = @this; @@ -58,21 +59,21 @@ namespace Kyoo.Models /// The list of query strings of the current page /// The number of items requested for the current page. public Page(ICollection items, - string url, + Uri url, Dictionary query, int limit) { Items = items; - This = url + query.ToQueryString(); + This = new Uri(url + query.ToQueryString()); if (items.Count == limit && limit > 0) { query["afterID"] = items.Last().ID.ToString(); - Next = url + query.ToQueryString(); + Next = new Uri(url + query.ToQueryString()); } query.Remove("afterID"); - First = url + query.ToQueryString(); + First = new Uri(url + query.ToQueryString()); } } } \ No newline at end of file diff --git a/Kyoo.CommonAPI/CrudApi.cs b/Kyoo.CommonAPI/CrudApi.cs index a6834c31..9b7e7c39 100644 --- a/Kyoo.CommonAPI/CrudApi.cs +++ b/Kyoo.CommonAPI/CrudApi.cs @@ -15,9 +15,9 @@ namespace Kyoo.CommonApi public class CrudApi : ControllerBase where T : class, IResource { private readonly IRepository _repository; - protected readonly string BaseURL; + protected readonly Uri BaseURL; - public CrudApi(IRepository repository, string baseURL) + public CrudApi(IRepository repository, Uri baseURL) { _repository = repository; BaseURL = baseURL; @@ -82,8 +82,8 @@ namespace Kyoo.CommonApi protected Page Page(ICollection resources, int limit) where TResult : IResource { - return new(resources, - BaseURL + Request.Path, + return new Page(resources, + new Uri(BaseURL, Request.Path), Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString(), StringComparer.InvariantCultureIgnoreCase), limit); } diff --git a/Kyoo/Models/Options/BasicOptions.cs b/Kyoo/Models/Options/BasicOptions.cs index 60e95ee2..2754e0d9 100644 --- a/Kyoo/Models/Options/BasicOptions.cs +++ b/Kyoo/Models/Options/BasicOptions.cs @@ -1,3 +1,5 @@ +using System; + namespace Kyoo.Models.Options { /// @@ -11,14 +13,14 @@ namespace Kyoo.Models.Options public const string Path = "Basics"; /// - /// The internal url where the server will listen + /// The internal url where the server will listen. It supports globing. /// public string Url { get; set; } = "http://*:5000"; /// /// The public url that will be used in items response and in authentication server host. /// - public string PublicUrl { get; set; } = "http://localhost:5000/"; + public Uri PublicUrl { get; set; } = new("http://localhost:5000"); /// /// The path of the plugin directory. diff --git a/Kyoo/Views/LibraryItemApi.cs b/Kyoo/Views/LibraryItemApi.cs index 5fd6b7e3..c35ec412 100644 --- a/Kyoo/Views/LibraryItemApi.cs +++ b/Kyoo/Views/LibraryItemApi.cs @@ -20,7 +20,7 @@ namespace Kyoo.Api public class LibraryItemApi : ControllerBase { private readonly ILibraryItemRepository _libraryItems; - private readonly string _baseURL; + private readonly Uri _baseURL; public LibraryItemApi(ILibraryItemRepository libraryItems, IOptions options) @@ -44,7 +44,7 @@ namespace Kyoo.Api new Pagination(limit, afterID)); return new Page(resources, - _baseURL + Request.Path, + new Uri(_baseURL + Request.Path), Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString(), StringComparer.InvariantCultureIgnoreCase), limit); }