btcpayserver/BTCPayServer/Services/UriResolver.cs
d11n 4c303d358b
Branding updates for 2.0 (#5947)
* Remove deprecated CSS options

Closes #5945.

* Greenfield: Add brandColor to store APIs

Closes #5946.

* Migrate file IDs to URLs

Closes #5953.

* Greenfield: Add CSS and logo URL to store settings API

Closes #5945.

* Add migration test

* Store and Server branding can reference file's via fileid:ID

* Add PaymentSoundUrl to Store API

---------

Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
2024-05-09 09:18:02 +09:00

38 lines
1.2 KiB
C#

#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.AccessControl;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
namespace BTCPayServer.Services
{
public class UriResolver
{
private readonly IFileService _fileService;
public UriResolver(IFileService fileService)
{
_fileService = fileService;
}
/// <summary>
/// If <paramref name="url"/> is an absolute URL, returns it as is.
/// If <paramref name="url"/> starts with "fileid:ID", returns the URL of the file with the ID.
/// </summary>
/// <param name="baseUri"><see cref="BTCPayServer.Abstractions.Extensions.HttpRequestExtensions.GetAbsoluteRootUri"/></param>
/// <param name="uri"></param>
/// <returns></returns>
public async Task<string?> Resolve(Uri baseUri, UnresolvedUri? uri)
{
return uri switch
{
null => null,
UnresolvedUri.FileIdUri fileId => await _fileService.GetFileUrl(baseUri, fileId.FileId),
UnresolvedUri.Raw raw => raw.Uri,
_ => throw new NotSupportedException(uri.GetType().Name)
};
}
}
}