From 1ccb30ad26ae22275e405e187cafab267c28871d Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 13 Aug 2021 12:03:02 +0200 Subject: [PATCH 1/3] ShowAPI: Fixing fonts path --- Kyoo/Views/ShowApi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kyoo/Views/ShowApi.cs b/Kyoo/Views/ShowApi.cs index 0c8dde65..494c94a6 100644 --- a/Kyoo/Views/ShowApi.cs +++ b/Kyoo/Views/ShowApi.cs @@ -386,7 +386,7 @@ namespace Kyoo.Api string path = _files.Combine(await _files.GetExtraDirectory(show), "Attachments"); return (await _files.ListFiles(path)) .ToDictionary(Path.GetFileNameWithoutExtension, - x => $"{BaseURL}api/shows/{slug}/fonts/{Path.GetFileName(x)}"); + x => $"{BaseURL}/api/shows/{slug}/fonts/{Path.GetFileName(x)}"); } catch (ItemNotFoundException) { From 53a9085727496a99ba34b78eb136008066bf1d19 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 13 Aug 2021 12:21:49 +0200 Subject: [PATCH 2/3] PublicUrl: Using an Uri instead of a string to fix / handling --- Kyoo.Common/Models/Page.cs | 17 +++++++++-------- Kyoo.CommonAPI/CrudApi.cs | 8 ++++---- Kyoo/Models/Options/BasicOptions.cs | 8 +++++--- Kyoo/Views/LibraryItemApi.cs | 4 ++-- Kyoo/Views/ShowApi.cs | 2 +- Kyoo/settings.json | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) 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..06c21041 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"; + public string Url { get; set; } = new("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); } diff --git a/Kyoo/Views/ShowApi.cs b/Kyoo/Views/ShowApi.cs index 494c94a6..0c8dde65 100644 --- a/Kyoo/Views/ShowApi.cs +++ b/Kyoo/Views/ShowApi.cs @@ -386,7 +386,7 @@ namespace Kyoo.Api string path = _files.Combine(await _files.GetExtraDirectory(show), "Attachments"); return (await _files.ListFiles(path)) .ToDictionary(Path.GetFileNameWithoutExtension, - x => $"{BaseURL}/api/shows/{slug}/fonts/{Path.GetFileName(x)}"); + x => $"{BaseURL}api/shows/{slug}/fonts/{Path.GetFileName(x)}"); } catch (ItemNotFoundException) { diff --git a/Kyoo/settings.json b/Kyoo/settings.json index 1ddc8cf1..f196dba9 100644 --- a/Kyoo/settings.json +++ b/Kyoo/settings.json @@ -1,7 +1,7 @@ { "basics": { "url": "http://*:5000", - "publicUrl": "http://localhost:5000/", + "publicUrl": "http://localhost:5000", "pluginsPath": "plugins/", "transmuxPath": "cached/transmux", "transcodePath": "cached/transcode", From a0213d95f3e676a1b7fa60a1e7fd955f28800a29 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 13 Aug 2021 12:43:07 +0200 Subject: [PATCH 3/3] Cleaning up --- Kyoo/Models/Options/BasicOptions.cs | 2 +- Kyoo/settings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Kyoo/Models/Options/BasicOptions.cs b/Kyoo/Models/Options/BasicOptions.cs index 06c21041..2754e0d9 100644 --- a/Kyoo/Models/Options/BasicOptions.cs +++ b/Kyoo/Models/Options/BasicOptions.cs @@ -15,7 +15,7 @@ namespace Kyoo.Models.Options /// /// The internal url where the server will listen. It supports globing. /// - public string Url { get; set; } = new("http://*:5000"); + public string Url { get; set; } = "http://*:5000"; /// /// The public url that will be used in items response and in authentication server host. diff --git a/Kyoo/settings.json b/Kyoo/settings.json index f196dba9..1ddc8cf1 100644 --- a/Kyoo/settings.json +++ b/Kyoo/settings.json @@ -1,7 +1,7 @@ { "basics": { "url": "http://*:5000", - "publicUrl": "http://localhost:5000", + "publicUrl": "http://localhost:5000/", "pluginsPath": "plugins/", "transmuxPath": "cached/transmux", "transcodePath": "cached/transcode",