123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Azure.Cosmos;
- using System.Text.Json;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK;
- namespace HTEX.Complex.Controllers
- {
- [Route("official")]
- [ApiController]
- public class OfficialController : ControllerBase
- {
- private readonly DingDing _dingDing;
- private readonly System.Net.Http.IHttpClientFactory _httpClientFactory;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IConfiguration _configuration;
- private readonly IPSearcher _searcher;
- public OfficialController(IConfiguration configuration,
- AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, System.Net.Http.IHttpClientFactory httpClientFactory,
- DingDing dingDing, IPSearcher searcher)
- {
- _dingDing = dingDing;
- _httpClientFactory = httpClientFactory;
- _azureRedis = azureRedis;
- _azureStorage = azureStorage;
- _configuration = configuration;
- _searcher = searcher;
- }
- [ProducesDefaultResponseType]
- [HttpPost("video-list")]
- public IActionResult VideoList(JsonElement json)
- {
- List<OfficialVideo> videos = new List<OfficialVideo>();
- var table = _azureStorage.TableServiceClient().GetTableClient("ShortUrl");
- if (json.TryGetProperty("rowKey", out JsonElement _rowKey) && !string.IsNullOrWhiteSpace($"{_rowKey}"))
- {
- videos = table.Query<OfficialVideo>($"{Constant.PartitionKey} {Constant.Equal} 'OfficialVideo' and {Constant.RowKey} {Constant.Equal} '{_rowKey}'").ToList();
- }
- else
- {
- videos = table.Query<OfficialVideo>(filter: $"{Constant.PartitionKey} eq 'OfficialVideo'").ToList();
- }
- return Ok(new { videos });
- }
- [ProducesDefaultResponseType]
- [RequestSizeLimit(102_400_000_00)] //最大10000m左右
- [HttpPost("video-upload")]
- public async Task<IActionResult> VideoUpload([FromForm] string name, [FromForm] string type, [FromForm] string? rowKey = null, [FromForm] IFormFile? videoFile = null)
- {
- OfficialVideo video = null;
- string url = string.Empty;
- var table = _azureStorage.TableServiceClient().GetTableClient("ShortUrl");
- if (videoFile == null)
- {
- if (!string.IsNullOrWhiteSpace(rowKey))
- {
- try
- {
- video=await table.GetEntityAsync<OfficialVideo>("OfficialVideo", rowKey);
- }
- catch { return BadRequest(); }
- }
- else
- {
- return BadRequest();
- }
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(rowKey))
- {
- try
- {
- video=await table.GetEntityAsync<OfficialVideo>("OfficialVideo", rowKey);
- }
- catch { }
- }
- if (video== null)
- {
- video= new OfficialVideo { RowKey=$"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", PartitionKey="OfficialVideo" };
- }
- string fileExt = FileType.GetExtention(videoFile.FileName).ToLower();
- if (fileExt.Equals("mp4", StringComparison.OrdinalIgnoreCase))
- {
- var url_blob = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(videoFile.OpenReadStream(), "official", $"{video.RowKey}.{fileExt}", false);
- url=url_blob;
- }
- }
- video.name= name;
- video.type= type;
- video.url=string.IsNullOrWhiteSpace(url) ? video.url : url;
- table.UpsertEntity<OfficialVideo>(video);
- return Ok(new { video });
- }
- }
- //[TableName(Name = "ShortUrl")]
- public class OfficialVideo : HTableEntity
- {
- ///// <summary>
- ///// OfficialVideo
- ///// </summary>
- //public string PartitionKey { get; set; }
- ///// <summary>
- ///// 视频id
- ///// </summary>
- //public string RowKey { get; set; }
- /// <summary>
- /// 名称
- /// </summary>
- public string? name { get; set; }
- /// <summary>
- /// 类型
- /// </summary>
- public string? type { get; set; }
- /// <summary>
- /// 地址
- /// </summary>
- public string? url { get; set; }
- }
-
- }
|