using LJProxy.Services; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Primitives; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Web; namespace LJProxy.Providers { public class L1SvrFileProvider : IFileProvider { private string _contentRoot; private LJClientPoolService _ljClient; private string _token; IHttpContextAccessor _accessor; public L1SvrFileProvider(string contentRoot, LJClientPoolService ljClient,IHttpContextAccessor accessor) { _contentRoot = contentRoot; _ljClient = ljClient; _accessor = accessor; } public IDirectoryContents GetDirectoryContents(string subpath) { throw new NotImplementedException(); } public IFileInfo GetFileInfo(string subpath) { string physicSubpath = subpath.Replace("/","\\"); int suffixIndex = physicSubpath.IndexOf(DocumentSuffix); if (suffixIndex > 0) { string fileExtension = Path.GetExtension(physicSubpath); physicSubpath = physicSubpath.Substring(0, suffixIndex); physicSubpath = physicSubpath + fileExtension; } physicSubpath = HttpUtility.UrlDecode(physicSubpath); string directory = @$"{_contentRoot}\wwwroot"; var fullFilepath = @$"{directory}{physicSubpath}"; _token = _accessor.HttpContext.Request.Headers["Authorization"]; var result = new L1SvrFileInfo(fullFilepath, physicSubpath,_ljClient.Pool,_token); return result; } private readonly static string DocumentSuffix = "$27BAljSuffix!"; public IChangeToken Watch(string filter) { throw new NotImplementedException(); } } }