mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
Fix and Cache Shopify JS
This commit is contained in:
parent
0cf9b20328
commit
4516bbdadd
@ -10,37 +10,42 @@ using BTCPayServer.Services.Shopify;
|
||||
using BTCPayServer.Services.Shopify.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BTCPayServer.Controllers
|
||||
{
|
||||
public partial class StoresController
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[HttpGet("{storeId}/integrations/shopify/shopify.js")]
|
||||
public async Task<IActionResult> ShopifyJavascript(string storeId)
|
||||
{
|
||||
|
||||
string[] fileList = new[]
|
||||
private static string _cachedBasejavascript;
|
||||
|
||||
private async Task<string> GetJavascript()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_cachedBasejavascript))
|
||||
{
|
||||
"modal/btcpay.js",
|
||||
"shopify/btcpay-browser-client.js",
|
||||
"shopify/btcpay-shopify-checkout.js"
|
||||
};
|
||||
if (_BtcpayServerOptions.BundleJsCss)
|
||||
{
|
||||
fileList = new[] {_bundleProvider.GetBundle("shopify-bundle.min.js").OutputFileUrl};
|
||||
return _cachedBasejavascript;
|
||||
}
|
||||
|
||||
var jsFile = $"var BTCPAYSERVER_URL = \"{Request.GetAbsoluteRoot()}\"; var STORE_ID = \"{storeId}\";";
|
||||
string[] fileList = _BtcpayServerOptions.BundleJsCss
|
||||
? new[] { "bundles/shopify-bundle.min.js"}
|
||||
: new[] {"modal/btcpay.js", "shopify/btcpay-browser-client.js", "shopify/btcpay-shopify-checkout.js"};
|
||||
|
||||
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
await using var stream = _webHostEnvironment.WebRootFileProvider
|
||||
.GetFileInfo(file).CreateReadStream();
|
||||
using var reader = new StreamReader(stream);
|
||||
jsFile += Environment.NewLine + await reader.ReadToEndAsync();
|
||||
_cachedBasejavascript += Environment.NewLine + await reader.ReadToEndAsync();
|
||||
}
|
||||
|
||||
return _cachedBasejavascript;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("{storeId}/integrations/shopify/shopify.js")]
|
||||
public async Task<IActionResult> ShopifyJavascript(string storeId)
|
||||
{
|
||||
var jsFile = $"var BTCPAYSERVER_URL = \"{Request.GetAbsoluteRoot()}\"; var STORE_ID = \"{storeId}\"; { await GetJavascript()}";
|
||||
return Content(jsFile, "text/javascript");
|
||||
}
|
||||
|
||||
|
@ -58,15 +58,13 @@ namespace BTCPayServer.Controllers
|
||||
ExplorerClientProvider explorerProvider,
|
||||
IFeeProviderFactory feeRateProvider,
|
||||
LanguageService langService,
|
||||
IWebHostEnvironment env, IHttpClientFactory httpClientFactory,
|
||||
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
|
||||
SettingsRepository settingsRepository,
|
||||
IAuthorizationService authorizationService,
|
||||
EventAggregator eventAggregator,
|
||||
CssThemeManager cssThemeManager,
|
||||
AppService appService,
|
||||
IWebHostEnvironment webHostEnvironment,
|
||||
IBundleProvider bundleProvider)
|
||||
IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
_RateFactory = rateFactory;
|
||||
_Repo = repo;
|
||||
@ -75,15 +73,12 @@ namespace BTCPayServer.Controllers
|
||||
_LangService = langService;
|
||||
_TokenController = tokenController;
|
||||
_WalletProvider = walletProvider;
|
||||
_Env = env;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
||||
_settingsRepository = settingsRepository;
|
||||
_authorizationService = authorizationService;
|
||||
_CssThemeManager = cssThemeManager;
|
||||
_appService = appService;
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_bundleProvider = bundleProvider;
|
||||
_EventAggregator = eventAggregator;
|
||||
_NetworkProvider = networkProvider;
|
||||
_ExplorerProvider = explorerProvider;
|
||||
@ -105,15 +100,12 @@ namespace BTCPayServer.Controllers
|
||||
readonly TokenRepository _TokenRepository;
|
||||
readonly UserManager<ApplicationUser> _UserManager;
|
||||
private readonly LanguageService _LangService;
|
||||
readonly IWebHostEnvironment _Env;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
|
||||
private readonly SettingsRepository _settingsRepository;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly CssThemeManager _CssThemeManager;
|
||||
private readonly AppService _appService;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly IBundleProvider _bundleProvider;
|
||||
private readonly EventAggregator _EventAggregator;
|
||||
|
||||
[TempData]
|
||||
|
Loading…
Reference in New Issue
Block a user