mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Make checkout CSS and logo paths relative (#4354)
* Make sure custom logo and CSS paths are relative * match request host and scheme before replacing * Fix the issue for greenfield as well Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ using BTCPayServer.Security;
|
|||||||
using BTCPayServer.Services.Stores;
|
using BTCPayServer.Services.Stores;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using StoreData = BTCPayServer.Data.StoreData;
|
using StoreData = BTCPayServer.Data.StoreData;
|
||||||
@@ -149,7 +150,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ToModel(StoreBaseData restModel, Data.StoreData model, PaymentMethodId defaultPaymentMethod)
|
private void ToModel(StoreBaseData restModel, Data.StoreData model, PaymentMethodId defaultPaymentMethod)
|
||||||
{
|
{
|
||||||
var blob = model.GetStoreBlob();
|
var blob = model.GetStoreBlob();
|
||||||
model.StoreName = restModel.Name;
|
model.StoreName = restModel.Name;
|
||||||
@@ -185,6 +186,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||||||
blob.LightningDescriptionTemplate = restModel.LightningDescriptionTemplate;
|
blob.LightningDescriptionTemplate = restModel.LightningDescriptionTemplate;
|
||||||
blob.PaymentTolerance = restModel.PaymentTolerance;
|
blob.PaymentTolerance = restModel.PaymentTolerance;
|
||||||
blob.PayJoinEnabled = restModel.PayJoinEnabled;
|
blob.PayJoinEnabled = restModel.PayJoinEnabled;
|
||||||
|
blob.NormalizeToRelativeLinks(Request);
|
||||||
model.SetStoreBlob(blob);
|
model.SetStoreBlob(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
blob.OnChainWithLnInvoiceFallback = model.OnChainWithLnInvoiceFallback;
|
blob.OnChainWithLnInvoiceFallback = model.OnChainWithLnInvoiceFallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
blob.RequiresRefundEmail = model.RequiresRefundEmail;
|
blob.RequiresRefundEmail = model.RequiresRefundEmail;
|
||||||
blob.LazyPaymentMethods = model.LazyPaymentMethods;
|
blob.LazyPaymentMethods = model.LazyPaymentMethods;
|
||||||
blob.RedirectAutomatically = model.RedirectAutomatically;
|
blob.RedirectAutomatically = model.RedirectAutomatically;
|
||||||
@@ -515,7 +515,7 @@ namespace BTCPayServer.Controllers
|
|||||||
blob.HtmlTitle = string.IsNullOrWhiteSpace(model.HtmlTitle) ? null : model.HtmlTitle;
|
blob.HtmlTitle = string.IsNullOrWhiteSpace(model.HtmlTitle) ? null : model.HtmlTitle;
|
||||||
blob.AutoDetectLanguage = model.AutoDetectLanguage;
|
blob.AutoDetectLanguage = model.AutoDetectLanguage;
|
||||||
blob.DefaultLang = model.DefaultLang;
|
blob.DefaultLang = model.DefaultLang;
|
||||||
|
blob.NormalizeToRelativeLinks(Request);
|
||||||
if (CurrentStore.SetStoreBlob(blob))
|
if (CurrentStore.SetStoreBlob(blob))
|
||||||
{
|
{
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using BTCPayServer.Payments;
|
|||||||
using BTCPayServer.Rating;
|
using BTCPayServer.Rating;
|
||||||
using BTCPayServer.Services.Mails;
|
using BTCPayServer.Services.Mails;
|
||||||
using BTCPayServer.Services.Rates;
|
using BTCPayServer.Services.Rates;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
@@ -239,6 +240,30 @@ namespace BTCPayServer.Data
|
|||||||
ExcludedPaymentMethods = methods.ToArray();
|
ExcludedPaymentMethods = methods.ToArray();
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace absolute URL with relative to avoid this issue: https://github.com/btcpayserver/btcpayserver/discussions/4195
|
||||||
|
public void NormalizeToRelativeLinks(HttpRequest request)
|
||||||
|
{
|
||||||
|
var schemeAndHost = $"{request.Scheme}://{request.Host.ToString()}/";
|
||||||
|
this.CustomLogo = EnsureRelativeLinks(this.CustomLogo, schemeAndHost);
|
||||||
|
this.CustomCSS = EnsureRelativeLinks(this.CustomCSS, schemeAndHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make a link relative if possible
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">Example: https://mystore.com/toto.png</param>
|
||||||
|
/// <param name="schemeAndHost">Example: https://mystore.com/</param>
|
||||||
|
/// <returns>/toto.png</returns>
|
||||||
|
private string EnsureRelativeLinks(string value, string schemeAndHost)
|
||||||
|
{
|
||||||
|
if (value is null)
|
||||||
|
return null;
|
||||||
|
value = value.Trim();
|
||||||
|
if (value.StartsWith(schemeAndHost, StringComparison.OrdinalIgnoreCase))
|
||||||
|
return value.Substring(schemeAndHost.Length - 1);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public class PaymentMethodCriteria
|
public class PaymentMethodCriteria
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user