浏览代码

Merge branch 'develop3.0-tmd' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop3.0-tmd

OnePsycho 4 年之前
父节点
当前提交
647b22e87b
共有 1 个文件被更改,包括 32 次插入2 次删除
  1. 32 2
      TEAMModelOS/Controllers/Core/BlobController.cs

+ 32 - 2
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -16,6 +16,7 @@ using TEAMModelOS.SDK.Extension;
 using System.IdentityModel.Tokens.Jwt;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.Filter;
+using StackExchange.Redis;
 
 namespace TEAMModelOS.Controllers.Core
 {
@@ -26,11 +27,14 @@ namespace TEAMModelOS.Controllers.Core
 
         private readonly AzureStorageFactory _azureStorage;
         private readonly IHttpClientFactory _clientFactory;
-
-        public BlobController(AzureStorageFactory azureStorage, IHttpClientFactory clientFactory)
+        private readonly AzureRedisFactory _azureRedis;
+        private readonly AzureServiceBusFactory _serviceBus;
+        public BlobController(AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IHttpClientFactory clientFactory, AzureRedisFactory azureRedis)
         {
             _azureStorage = azureStorage;
             _clientFactory = clientFactory;
+            _serviceBus = serviceBus;
+            _azureRedis = azureRedis;
         }
 
         /// <summary>
@@ -230,8 +234,34 @@ namespace TEAMModelOS.Controllers.Core
         [HttpPost("get-blobsize")]
         public async Task<ActionResult> GetBlobsSize(JsonElement request)
         {
+            
             request.TryGetProperty("containerName", out JsonElement containerName);
             var name =containerName.GetString();
+            RedisValue value = default;
+            value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
+            if (value != default && !value.IsNullOrEmpty)
+            {
+                JsonElement record = value.ToString().ToObject<JsonElement>();
+                if (record.TryGetInt64(out long blobsize))
+                {
+                    return Ok(new { size= blobsize });
+                }
+            }
+            var client = _azureStorage.GetBlobContainerClient(name);
+            var size = await client.GetBlobsSize();
+            await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size);
+            return Ok(new { size });
+        }
+        /// <summary>
+        /// 测试单个文本内容的上传
+        /// </summary>
+        /// <param name="azureBlobSASDto"></param>
+        /// <returns></returns>
+        [HttpPost("update-blobsize")]
+        public async Task<ActionResult> updateBlobsSize(JsonElement request)
+        {
+            request.TryGetProperty("containerName", out JsonElement containerName);
+            var name = containerName.GetString();
             var client = _azureStorage.GetBlobContainerClient(name);
             var size = await client.GetBlobsSize();
             return Ok(new { size });