L1SvrFileProvider.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using LJProxy.Services;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.Extensions.FileProviders;
  4. using Microsoft.Extensions.Primitives;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace LJProxy.Providers
  11. {
  12. public class L1SvrFileProvider : IFileProvider
  13. {
  14. private string _contentRoot;
  15. private LJClientPoolService _ljClient;
  16. private string _token;
  17. IHttpContextAccessor _accessor;
  18. public L1SvrFileProvider(string contentRoot, LJClientPoolService ljClient,IHttpContextAccessor accessor)
  19. {
  20. _contentRoot = contentRoot;
  21. _ljClient = ljClient;
  22. _accessor = accessor;
  23. }
  24. public IDirectoryContents GetDirectoryContents(string subpath)
  25. {
  26. throw new NotImplementedException();
  27. }
  28. public IFileInfo GetFileInfo(string subpath)
  29. {
  30. string physicSubpath = subpath.Replace("/","\\");
  31. int suffixIndex = physicSubpath.IndexOf(DocumentSuffix);
  32. if (suffixIndex > 0)
  33. {
  34. string fileExtension = Path.GetExtension(physicSubpath);
  35. physicSubpath = physicSubpath.Substring(0, suffixIndex);
  36. physicSubpath = physicSubpath + fileExtension;
  37. }
  38. string directory = @$"{_contentRoot}\wwwroot";
  39. var fullFilepath = @$"{directory}{physicSubpath}";
  40. _token = _accessor.HttpContext.Request.Headers["Authorization"];
  41. var result = new L1SvrFileInfo(fullFilepath, physicSubpath,_ljClient.Pool,_token);
  42. return result;
  43. }
  44. private readonly static string DocumentSuffix = "$27BAljSuffix!";
  45. public IChangeToken Watch(string filter)
  46. {
  47. throw new NotImplementedException();
  48. }
  49. }
  50. }