#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; } /// /// If is an absolute URL, returns it as is. /// If starts with "fileid:ID", returns the URL of the file with the ID. /// /// /// /// public async Task 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) }; } } }