From 78358a5e23252b92c562b277561af6354d1d1bab Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 4 Jun 2024 12:51:18 +0200 Subject: [PATCH 1/2] Refactor StacStoreService to improve asset URI handling in collection --- src/Stars.Services/Store/StacStoreService.cs | 51 +++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Stars.Services/Store/StacStoreService.cs b/src/Stars.Services/Store/StacStoreService.cs index 52ae6e81..c376de0b 100644 --- a/src/Stars.Services/Store/StacStoreService.cs +++ b/src/Stars.Services/Store/StacStoreService.cs @@ -152,7 +152,7 @@ public async Task StoreItemNodeAtDestinationAsync(StacItemNode sta public async Task StoreCollectionNodeAtDestinationAsync(StacCollectionNode stacCollectionNode, IDestination destination, CancellationToken ct) { - PrepareStacCatalogueForDestination(stacCollectionNode, destination); + PrepareStacCollectionForDestination(stacCollectionNode, destination); return await _stacRouter.RouteAsync(await StoreResourceAtDestinationAsync(stacCollectionNode, destination, ct), ct) as StacCollectionNode; } @@ -305,6 +305,16 @@ private void PrepareStacCatalogueForDestination(StacCatalogNode stacCatalogNode, PrepareStacNodeForDestination(stacCatalogNode, destination); } + private void PrepareStacCollectionForDestination(StacCollectionNode stacCollectionNode, IDestination destination) + { + PrepareStacNodeForDestination(stacCollectionNode, destination); + if (storeOptions.AbsoluteAssetsUrl) + MakeAssetUriAbsolute(stacCollectionNode, destination); + else + MakeAssetUriRelative(stacCollectionNode, destination); + } + + public void PrepareStacItemForDestination(StacItemNode stacItemNode, IDestination destination) { PrepareStacNodeForDestination(stacItemNode, destination); @@ -327,6 +337,16 @@ private void MakeAssetUriAbsolute(StacItemNode stacItemNode, IDestination destin } } + private void MakeAssetUriAbsolute(StacCollectionNode stacCollectionNode, IDestination destination) + { + MakeAssetUriRelative(stacCollectionNode, destination); + foreach (var asset in stacCollectionNode.StacCollection.Assets) + { + if (asset.Value.Uri.IsAbsoluteUri) continue; + asset.Value.Uri = new Uri(MapToFrontUri(destination.Uri), asset.Value.Uri); + } + } + private void MakeAssetUriRelative(StacItemNode stacItemNode, IDestination destination) { foreach (var asset in stacItemNode.StacItem.Assets) @@ -356,6 +376,35 @@ private void MakeAssetUriRelative(StacItemNode stacItemNode, IDestination destin } } + private void MakeAssetUriRelative(StacCollectionNode stacCollectionNode, IDestination destination) + { + foreach (var asset in stacCollectionNode.StacCollection.Assets) + { + if (!asset.Value.Uri.IsAbsoluteUri) continue; + // 0. make sure the uri is not outside of the root catalog + var relativeUri = RootCatalogDestination.Uri.MakeRelativeUri(asset.Value.Uri); + if (relativeUri.IsAbsoluteUri || relativeUri.ToString().StartsWith("../")) + continue; + // 1. Check the asset uri can be relative to destination itself + relativeUri = destination.Uri.MakeRelativeUri(asset.Value.Uri); + if (!relativeUri.IsAbsoluteUri) + { + asset.Value.Uri = relativeUri; + continue; + } + // 1. Check the asset uri can be relative to root catalog + relativeUri = RootCatalogDestination.Uri.MakeRelativeUri(asset.Value.Uri); + if (relativeUri.IsAbsoluteUri) continue; + Uri absoluteUri = new Uri(RootCatalogNode.Uri, relativeUri); + relativeUri = stacCollectionNode.Uri.MakeRelativeUri(asset.Value.Uri); + if (!relativeUri.IsAbsoluteUri) + { + asset.Value.Uri = relativeUri; + continue; + } + } + } + public async Task GetAssetsInFolderAsync(string relPath, CancellationToken ct) { return await resourceServiceProvider.GetAssetsInFolderAsync(new GenericResource(new Uri(RootCatalogDestination.Uri, relPath)), ct); From e7f17f3dc89514f726e543786870851a4c518dd1 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 4 Jun 2024 12:53:10 +0200 Subject: [PATCH 2/2] ready to release 2.24.1 --- CHANGELOG.md | 8 +++++++- src/Stars.Console/Terradue.Stars.Console.csproj | 2 +- src/Stars.Data/Terradue.Stars.Data.csproj | 2 +- src/Stars.Services/Terradue.Stars.Services.csproj | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b6c5f8..dc0d6bf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -## [2.24.0](https://github.com/Terradue/Stars/compare/2.23.0...2.24.0) +## [2.24.1](https://github.com/Terradue/Stars/compare/2.24.0...2.24.1) + +### Commits + +- Refactor StacStoreService to improve asset URI handling in collection [`78358a5`](https://github.com/Terradue/Stars/commit/78358a5e23252b92c562b277561af6354d1d1bab) + +## [2.24.0](https://github.com/Terradue/Stars/compare/2.23.0...2.24.0) - 2024-06-04 ### Commits diff --git a/src/Stars.Console/Terradue.Stars.Console.csproj b/src/Stars.Console/Terradue.Stars.Console.csproj index 1c9f622c..5c6b4df2 100644 --- a/src/Stars.Console/Terradue.Stars.Console.csproj +++ b/src/Stars.Console/Terradue.Stars.Console.csproj @@ -2,7 +2,7 @@ Exe net6.0 - 2.24.0 + 2.24.1 Stars is a CLI for working with Spatio Temporal Catalog such as STAC but not only $(Version)-$(VersionSuffix) diff --git a/src/Stars.Data/Terradue.Stars.Data.csproj b/src/Stars.Data/Terradue.Stars.Data.csproj index 6652590d..e4a6610b 100644 --- a/src/Stars.Data/Terradue.Stars.Data.csproj +++ b/src/Stars.Data/Terradue.Stars.Data.csproj @@ -4,7 +4,7 @@ Terradue.Stars.Data Terradue.Stars.Data Collection of data Plugins for Terradue.Stars - 2.24.0 + 2.24.1 $(Version)-$(VersionSuffix) NU1603 diff --git a/src/Stars.Services/Terradue.Stars.Services.csproj b/src/Stars.Services/Terradue.Stars.Services.csproj index 1e0938ca..50ab8dc0 100644 --- a/src/Stars.Services/Terradue.Stars.Services.csproj +++ b/src/Stars.Services/Terradue.Stars.Services.csproj @@ -3,7 +3,7 @@ netstandard2.0 Terradue.Stars Stars is a set of services for working with Spatio Temporal Catalog such as STAC but not only - 2.24.0 + 2.24.1 $(Version)-$(VersionSuffix) Terradue.Stars.Services