2019-07-27 09:18:49 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2019-07-27 09:18:49 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-09-09 18:40:04 -04:00
|
|
|
|
using System.IO;
|
2019-07-27 09:18:49 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("dynamic")]
|
|
|
|
|
public class DynamicFileController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private static readonly IDictionary<string, string> _fileCache = new Dictionary<string, string>();
|
|
|
|
|
|
2019-12-02 16:52:36 -05:00
|
|
|
|
public DynamicFileController(IManager manager) : base(manager)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-27 09:18:49 -04:00
|
|
|
|
[Route("css/{fileName}")]
|
|
|
|
|
public async Task<IActionResult> Css(string fileName)
|
|
|
|
|
{
|
|
|
|
|
if (fileName.EndsWith(".css"))
|
|
|
|
|
{
|
2020-08-26 10:54:56 -04:00
|
|
|
|
if (Utilities.IsDevelopment)
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Join(Utilities.OperatingDirectory, "..", "..", "..", "..", "WebfrontCore", "wwwroot", "css", fileName);
|
|
|
|
|
string cssData = await System.IO.File.ReadAllTextAsync(path);
|
|
|
|
|
cssData = await Manager.MiddlewareActionHandler.Execute(cssData, "custom_css_accent");
|
|
|
|
|
return Content(cssData, "text/css");
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-27 09:18:49 -04:00
|
|
|
|
if (!_fileCache.ContainsKey(fileName))
|
|
|
|
|
{
|
2019-08-02 19:04:34 -04:00
|
|
|
|
|
2019-09-09 18:40:04 -04:00
|
|
|
|
string path = $"wwwroot{Path.DirectorySeparatorChar}css{Path.DirectorySeparatorChar}{fileName}";
|
2019-08-02 19:04:34 -04:00
|
|
|
|
string data = await System.IO.File.ReadAllTextAsync(path);
|
|
|
|
|
data = await Manager.MiddlewareActionHandler.Execute(data, "custom_css_accent");
|
|
|
|
|
_fileCache.Add(fileName, data);
|
2019-07-27 09:18:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Content(_fileCache[fileName], "text/css");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return StatusCode(400);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|