IndexController.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Azure.Storage.Blobs.Specialized;
  2. using HTEXScreen.Service;
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Mvc;
  5. using PuppeteerSharp;
  6. using PuppeteerSharp.Media;
  7. using System.Configuration;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Net;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Text.Json;
  14. using System.Text.RegularExpressions;
  15. using System.Web;
  16. using TEAMModelOS.SDK;
  17. using TEAMModelOS.SDK.DI;
  18. namespace HTEXScreen.Controllers
  19. {
  20. [ApiController]
  21. [Route("api")]
  22. public class IndexController : ControllerBase
  23. {
  24. private readonly AzureStorageFactory _azureStorage;
  25. private readonly HttpClient _httpClient;
  26. private readonly IConfiguration _configuration;
  27. // private readonly HttpContext _httpContext;
  28. public IndexController(HttpClient httpClient, AzureStorageFactory azureStorage, IConfiguration configuration)
  29. {
  30. _httpClient = httpClient;
  31. _azureStorage = azureStorage;
  32. _configuration = configuration;
  33. // _httpContext=httpContext;
  34. }
  35. /// <summary>
  36. /// 上传到blob
  37. /// </summary>
  38. /// <param name="request"></param>
  39. /// <returns></returns>
  40. [HttpPost("http-log")]
  41. [RequestSizeLimit(102_400_000_00)] //最大10000m左右
  42. public async Task<IActionResult> HttpLog(JsonElement json)
  43. {
  44. string data = json.ToJsonString();
  45. var gmt8Time = DateTimeOffset.Now.GetGMTTime(8);
  46. var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
  47. if (!appendBlob.Exists())
  48. {
  49. await appendBlob.CreateAsync();
  50. using var stream = new MemoryStream(Encoding.UTF8.GetBytes($"{data},\n"));
  51. _= appendBlob.AppendBlockAsync(stream);
  52. }
  53. else
  54. {
  55. using var stream = new MemoryStream(Encoding.UTF8.GetBytes($"{data},\n"));
  56. _= appendBlob.AppendBlockAsync(stream);
  57. }
  58. return Ok(new { code=1});
  59. }
  60. }
  61. }