CrazyIter_Bin %!s(int64=3) %!d(string=hai) anos
pai
achega
45565b4b33

+ 1 - 0
BlobDownload/BlobDownload.csproj

@@ -7,6 +7,7 @@
 
   <ItemGroup>
     <PackageReference Include="Azure.Storage.Blobs.Batch" Version="12.6.0" />
+    <PackageReference Include="System.Drawing.Common" Version="5.0.2" />
   </ItemGroup>
 
 </Project>

+ 25 - 0
BlobDownload/Program.cs

@@ -3,6 +3,7 @@ using Azure.Storage.Blobs.Models;
 using Azure.Storage.Blobs.Specialized;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.IO;
 using System.Linq;
 using System.Text;
@@ -14,6 +15,29 @@ namespace BlobDownload
     {
         static async Task Main(string[] args)
         {
+            string base64 = "/base64.txt";
+            StreamReader sr = new StreamReader(base64, Encoding.Default);
+            StringBuilder content = new StringBuilder();
+            string line;
+            while ((line = sr.ReadLine()) != null)
+            {
+                content.Append(line);
+            }
+            byte[] bytes = Convert.FromBase64String(content.ToString());
+            Stream stream = new MemoryStream(bytes);
+
+            // MemoryStream memoryStream = new MemoryStream();
+            System.Drawing.Bitmap inFile = new System.Drawing.Bitmap(stream);
+            Graphics graphics = Graphics.FromImage(inFile);
+            graphics.Save();
+            graphics.Dispose();
+            inFile.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
+            //byte[] arr = new byte[memoryStream.Length];
+            //memoryStream.Position = 0;
+            //memoryStream.Read(arr, 0, (int)memoryStream.Length);
+            //memoryStream.Close();
+            //memoryStream.Dispose();
+            /*
             string StorageAccountConnectionString = "DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn";
             BlobServiceClient blobServiceClient = new BlobServiceClient(StorageAccountConnectionString);
             BlobContainerClient blobContainerClient = new BlobContainerClient(StorageAccountConnectionString, "hbcn");
@@ -55,6 +79,7 @@ namespace BlobDownload
             await Task.WhenAll(tasks);
             long end = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             Console.WriteLine($"文件个数:{count};下载时间:{end-start}毫秒");
+            */
         }
     }
 }

+ 2 - 2
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -473,8 +473,8 @@ namespace TEAMModelFunction
         /// <param name="req"></param>
         /// <param name="log"></param>
         /// <returns></returns>
-        [FunctionName("get-blobsize")]
-        public async Task<IActionResult> GetBlobsize(
+        [FunctionName("used-space")]
+        public async Task<IActionResult> UsedSpace(
             [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
             ILogger log)
         {

+ 1 - 1
TEAMModelOS/ClientApp/src/api/blob.js

@@ -37,7 +37,7 @@ export default {
     },
     //获取容器空间信息
     getContainerSize: function (data) {
-        return post('/blob/get-blobsize', data)
+        return post('/blob/used-space', data)
     },
     // 删除blob指定目录下的所有文件
     deletePrefix: function (data) {

+ 40 - 59
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -170,8 +170,8 @@ namespace TEAMModelOS.Controllers.Core
         /// </summary>
         /// <param name="azureBlobSASDto"></param>
         /// <returns></returns>
-        [HttpPost("get-blobsize")]
-        public async Task<ActionResult> GetBlobsSize(JsonElement request)
+        [HttpPost("used-space")]
+        public async Task<ActionResult> UsedSpace(JsonElement request)
         {
             try
             {
@@ -194,68 +194,52 @@ namespace TEAMModelOS.Controllers.Core
                         }
                     }
                 }
-               // request.TryGetProperty("cache", out JsonElement cache);
                 var name =containerName.GetString();
-                //if (cache.GetBoolean())
-                //{
-                    long blobsize = 0;
-                    RedisValue value = default;
-                    value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
-                    if (value != default && !value.IsNullOrEmpty)
+                long blobsize = 0;
+                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 blobsize))
                     {
-                        JsonElement record = value.ToString().ToObject<JsonElement>();
-                        if (record.TryGetInt64(out blobsize))
-                        {
-                        }
                     }
-                    else
+                }
+                else
+                {
+                    var client = _azureStorage.GetBlobContainerClient(name);
+                    var size = await client.GetBlobsCatalogSize();
+                    await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
+                    foreach (var key in size.Item2.Keys)
                     {
-                        var client = _azureStorage.GetBlobContainerClient(name);
-                        var size = await client.GetBlobsCatalogSize();
-                        await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
-                        foreach (var key in size.Item2.Keys)
-                        {
-                            await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
-                            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
-                        }
-                        return Ok(new { size = size.Item1, catalog = size.Item2 ,teach });
+                        await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
+                        await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
                     }
-                    Dictionary<string, double> catalog = new Dictionary<string, double>();
-                    SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{name}");
-                    if (Scores != null)
+                    return Ok(new { size = size.Item1, catalog = size.Item2 ,teach });
+                }
+                Dictionary<string, double> catalog = new Dictionary<string, double>();
+                SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{name}");
+                if (Scores != null)
+                {
+                    foreach (var score in Scores)
                     {
-                        foreach (var score in Scores)
-                        {
-                            double val = score.Score;
-                            string key = score.Element.ToString();
-                            catalog.Add(key, val);
-                        }
-                        return Ok(new { size = blobsize, catalog = catalog, teach });
+                        double val = score.Score;
+                        string key = score.Element.ToString();
+                        catalog.Add(key, val);
                     }
-                    else {
-                        var client = _azureStorage.GetBlobContainerClient(name);
-                        var size = await client.GetBlobsCatalogSize();
-                        await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
-                        foreach (var key in size.Item2.Keys)
-                        {
-                            await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
-                            await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
-                        }
-                        return Ok(new { size = size.Item1, catalog = size.Item2, teach });
+                    return Ok(new { size = blobsize, catalog = catalog, teach });
+                }
+                else {
+                    var client = _azureStorage.GetBlobContainerClient(name);
+                    var size = await client.GetBlobsCatalogSize();
+                    await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
+                    foreach (var key in size.Item2.Keys)
+                    {
+                        await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
+                        await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
                     }
-               // }
-               // else {
-                    //var client = _azureStorage.GetBlobContainerClient(name);
-                    //var size = await client.GetBlobsCatalogSize();
-                    //await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
-                    //foreach (var key in size.Item2.Keys)
-                    //{
-                    //    await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
-                    //    await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
-                    //}
-                    //return Ok(new { size = size.Item1, catalog = size.Item2, teach });
-              //  }
-                
+                    return Ok(new { size = size.Item1, catalog = size.Item2, teach });
+                }
             }
             catch (Exception  ex){
                 await _dingDing.SendBotMsg($"IES5,{_option.Location},blon/get-blobsize()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
@@ -415,9 +399,6 @@ namespace TEAMModelOS.Controllers.Core
             { 
                 return BadRequest();
             }
-
-
-          
         }
 
         /*