123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using Azure.Storage.Blobs.Specialized;
- using HTEXScreen.Service;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using PuppeteerSharp;
- using PuppeteerSharp.Media;
- using System.Configuration;
- using System.Drawing;
- using System.IO;
- using System.Net;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Text.Json;
- using System.Text.RegularExpressions;
- using System.Web;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- namespace HTEXScreen.Controllers
- {
- [ApiController]
- [Route("api")]
- public class IndexController : ControllerBase
- {
- private readonly AzureStorageFactory _azureStorage;
- private readonly HttpClient _httpClient;
- private readonly IConfiguration _configuration;
- // private readonly HttpContext _httpContext;
- public IndexController(HttpClient httpClient, AzureStorageFactory azureStorage, IConfiguration configuration)
- {
- _httpClient = httpClient;
- _azureStorage = azureStorage;
- _configuration = configuration;
- // _httpContext=httpContext;
- }
- /// <summary>
- /// 上传到blob
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("http-log")]
- [RequestSizeLimit(102_400_000_00)] //最大10000m左右
- public async Task<IActionResult> HttpLog(JsonElement json)
- {
- try {
- string data = json.ToJsonString();
- var gmt8Time = DateTimeOffset.Now.GetGMTTime(8);
- var appendBlob = _azureStorage.GetBlobContainerClient("0-service-log").GetAppendBlobClient($"http-log/{gmt8Time:yyyy}/{gmt8Time:MM}/{gmt8Time:dd}/{gmt8Time:HH}.log");
- if (!await appendBlob.ExistsAsync())
- {
- await appendBlob.CreateAsync();
- }
- using (var stream = new MemoryStream(Encoding.UTF8.GetBytes($"{data},\n")))
- {
- await appendBlob.AppendBlockAsync(stream);
- }
- return Ok(new { code = 1 });
- }
- catch (Exception ex) {
- return Ok(new { code = 1 });
- }
- }
- }
- }
|