2019-03-23 15:24:29 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-03-24 01:10:16 +01:00
|
|
|
|
using BundlerMinifier.TagHelpers;
|
2019-10-03 10:06:49 +02:00
|
|
|
|
using Newtonsoft.Json.Serialization;
|
2019-03-23 15:24:29 +01:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Hosting
|
|
|
|
|
{
|
|
|
|
|
public class ResourceBundleProvider : IBundleProvider
|
|
|
|
|
{
|
|
|
|
|
BundleProvider _InnerProvider;
|
|
|
|
|
Lazy<Dictionary<string, Bundle>> _BundlesByName;
|
2019-10-03 10:06:49 +02:00
|
|
|
|
public ResourceBundleProvider(IWebHostEnvironment hosting, BundleOptions options)
|
2019-03-23 15:24:29 +01:00
|
|
|
|
{
|
|
|
|
|
if (options.UseBundles)
|
|
|
|
|
{
|
|
|
|
|
_BundlesByName = new Lazy<Dictionary<string, Bundle>>(() =>
|
|
|
|
|
{
|
|
|
|
|
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BTCPayServer.bundleconfig.json"))
|
|
|
|
|
using (var reader = new StreamReader(stream, Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
var content = reader.ReadToEnd();
|
|
|
|
|
return JArray.Parse(content).OfType<JObject>()
|
|
|
|
|
.Select(jobj => new Bundle()
|
|
|
|
|
{
|
2019-05-02 14:38:39 +02:00
|
|
|
|
Name = jobj.Property("name", StringComparison.OrdinalIgnoreCase)?.Value.Value<string>() ?? jobj.Property("outputFileName", StringComparison.OrdinalIgnoreCase).Value.Value<string>(),
|
|
|
|
|
OutputFileUrl = Path.Combine(hosting.ContentRootPath, jobj.Property("outputFileName", StringComparison.OrdinalIgnoreCase).Value.Value<string>())
|
2019-03-23 15:24:29 +01:00
|
|
|
|
}).ToDictionary(o => o.Name, o => o);
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_InnerProvider = new BundleProvider();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Bundle GetBundle(string name)
|
|
|
|
|
{
|
|
|
|
|
if (_InnerProvider != null)
|
|
|
|
|
return _InnerProvider.GetBundle(name);
|
|
|
|
|
_BundlesByName.Value.TryGetValue(name, out var bundle);
|
|
|
|
|
return bundle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|