Forráskód Böngészése

整合HTEX到大云,并实现网络连接下载处理。

CrazyIter 4 éve
szülő
commit
e405880d44

+ 16 - 5
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -10,6 +10,7 @@ using System;
 using System.IO;
 using Azure.Storage.Blobs.Specialized;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace TEAMModelOS.SDK.DI
 {
@@ -38,14 +39,13 @@ namespace TEAMModelOS.SDK.DI
         }
 
         /// <summary>
+        /// https://teammodelstorage.blob.core.chinacloudapi.cn/ydzt/112315401795%2F
         /// 批量刪除Blobs
-        /// 注意單個批次最多支持256個子請求。批處理請求的正文大小不能超過4MB,超過返回False
         /// </summary>      
         /// <param name="prefix">篩選開頭名稱,Null代表容器</param>        
         public static async Task<bool> DelectBlobs(this BlobServiceClient client, string blobContainerName, string prefix = null)
         {
             if (string.IsNullOrWhiteSpace(prefix)) return false;
-
             try
             {
                 BlobContainerClient bcc = client.GetBlobContainerClient(blobContainerName);
@@ -57,9 +57,20 @@ namespace TEAMModelOS.SDK.DI
                     urib.Path += "/" + item.Name;
                     blobs.Add(urib.Uri);
                 };
-
-                await bbc.DeleteBlobsAsync(blobs);
-                return true;
+                if (blobs.Count <= 256)
+                {
+                    await bbc.DeleteBlobsAsync(blobs);
+                    return true;
+                }
+                else {
+                    int pages = (int)Math.Ceiling((double)blobs.Count / 256);
+                    for (int i = 0; i < pages; i++)
+                    {
+                        List<Uri> lists = blobs.Skip((i) * 256).Take(256).ToList();
+                        await bbc.DeleteBlobsAsync(lists);
+                    }
+                    return true;
+                }
             }
             catch
             {

+ 9 - 10
TEAMModelOS/Controllers/Exam/ImportExerciseController.cs

@@ -82,9 +82,9 @@ namespace TEAMModelOS.Controllers
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        [HttpPost("analysis-pptx")]
+        [HttpPost("parse-pptx")]
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
-        public async Task<IActionResult> AnalysisPPTX(JsonElement request)
+        public async Task<IActionResult> ParsePPTX(JsonElement request)
         {
             //string id_token = HttpContext.GetXAuth("IdToken");
             //if (string.IsNullOrEmpty(id_token)) return BadRequest();
@@ -98,13 +98,13 @@ namespace TEAMModelOS.Controllers
             string ContainerName = a.Item1;
             string BlobName = a.Item2;
             bool flg = IsBlobName(BlobName);
-            var codes = code.ToString().Split("/");
-            var FileName = codes[codes.Length - 1];
+            var codes = azureBlobSAS.Split("/");
+            var FileName = codes[codes.Length - 1].Split(".")[0];
             if (flg)
             {
                 //TODO 需驗證
                 BlobAuth blobAuth = _azureStorage.GetBlobSasUriRead(ContainerName, BlobName);
-                var response = await _clientFactory.CreateClient().GetAsync(new Uri(blobAuth.url + blobAuth.sas));
+                var response = await _clientFactory.CreateClient().GetAsync(new Uri(blobAuth.url));
                 response.EnsureSuccessStatusCode();
                 Stream stream=  await response.Content.ReadAsStreamAsync();
                 string  index = await PPTXTranslator(ContainerName, FileName, stream);
@@ -144,7 +144,7 @@ namespace TEAMModelOS.Controllers
             var id = jwt.Payload.Sub;
             if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx") || FileType.GetExtention(file.FileName).ToLower().Equals("xml"))
             {
-                string FileName = file.FileName;
+                string FileName = file.FileName.Split(".")[0];
                 Stream streamFile = file.OpenReadStream();
                 string index = await PPTXTranslator(id, FileName, streamFile);
                 return Ok(new { index = index });
@@ -237,20 +237,19 @@ namespace TEAMModelOS.Controllers
 
         private async Task<string> PPTXTranslator(string id, string FileName, Stream streamFile)
         {
-            //var day = new DateTimeOffset(DateTime.UtcNow).ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
-            string shaCode = ShaHashHelper.GetSHA1(streamFile);
+            var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(id, $"res/{FileName}");
+            string shaCode = Guid.NewGuid().ToString("N");
             HTEXLib.Htex htex = htexGenerator.Generator(streamFile);
             htex.name = FileName;
             var slides = htex.slides;
             List<Task> tasks = new List<Task>();
             HTEX hTEX = new HTEX() { name = FileName, size = htex.size, thumbnail = htex.thumbnail, id = shaCode };
-
             Dictionary<string, string> texts = new Dictionary<string, string>();
             List<string> shas = new List<string>();
             foreach (var slide in slides)
             {
                 string text = JsonHelper.ToJson(slide, ignoreNullValue: false);
-                string sha = ShaHashHelper.GetSHA1(text);
+                string sha = Guid.NewGuid().ToString("N");
                 texts.Add(sha, text);
                 shas.Add(sha);
             }

+ 16 - 0
TEAMModelOS/Controllers/xTest/BlobController.cs

@@ -100,6 +100,9 @@ namespace TEAMModelOS.Controllers.Core
             return responseBuilder.Data(await _azureStorage.UploadFileByContainer("hbcn", request.ToJsonString(), "exam", _snowflakeId.NextId() + ".json")).build();
 
         }
+      
+
+        
         /// <summary>
         /// 获取文件内容
         /// </summary>
@@ -131,6 +134,19 @@ namespace TEAMModelOS.Controllers.Core
 
         }
 
+        /// <summary>
+        /// 测试单个文本内容的上传
+        /// </summary>
+        /// <param name="azureBlobSASDto"></param>
+        /// <returns></returns>
+        [HttpPost("deleteBlob")]
+        public async Task<BaseResponse> DeleteBlob(JsonElement request)
+        {
+            ResponseBuilder responseBuilder = new ResponseBuilder();
+            var client = _azureStorage.GetBlobBatchClient().DeleteBlobs(new Uri[] {new Uri("https://teammodelstorage.blob.core.chinacloudapi.cn/ydzt/%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9%2FAnimation.xml") });
+            return responseBuilder.Data(client[0].Status).build();
+
+        }
         /// <summary>
         /// 测试单个文本内容的上传
         /// </summary>