L1SvrFileProvider.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.Linq;
  8. using System.Threading.Tasks;
  9. namespace LJProxy.Providers
  10. {
  11. public class L1SvrFileProvider : IFileProvider
  12. {
  13. private string _contentRoot;
  14. private LJClientPoolService _ljClient;
  15. private string _token;
  16. IHttpContextAccessor _accessor;
  17. public L1SvrFileProvider(string contentRoot, LJClientPoolService ljClient,IHttpContextAccessor accessor)
  18. {
  19. _contentRoot = contentRoot;
  20. _ljClient = ljClient;
  21. _accessor = accessor;
  22. }
  23. public IDirectoryContents GetDirectoryContents(string subpath)
  24. {
  25. throw new NotImplementedException();
  26. }
  27. public IFileInfo GetFileInfo(string subpath)
  28. {
  29. string physicSubpath = subpath.Replace("/","\\");
  30. string directory = @$"{_contentRoot}\wwwroot";
  31. var fullFilepath = @$"{directory}{physicSubpath}";
  32. _token = _accessor.HttpContext.Request.Headers["Authorization"];
  33. var result = new L1SvrFileInfo(fullFilepath, physicSubpath,_ljClient.Pool,_token);
  34. return result;
  35. }
  36. public IChangeToken Watch(string filter)
  37. {
  38. throw new NotImplementedException();
  39. }
  40. }
  41. }