Преглед на файлове

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

zhousheng преди 4 години
родител
ревизия
865e9f64c0

+ 32 - 1
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -37,7 +37,38 @@ namespace TEAMModelOS.SDK.DI
                 return size;
             }
         }
-
+        /// <summary>        
+        /// 批量刪除Blobs
+        /// </summary>      
+        /// <param name="prefix">篩選開頭名稱,Null代表容器</param>        
+        public static async Task<bool> DelectBlobs(this BlobServiceClient client, string blobContainerName, List<Uri> blobs = null)
+        {
+            
+            try
+            {
+                BlobContainerClient bcc = client.GetBlobContainerClient(blobContainerName);
+                BlobBatchClient bbc = client.GetBlobBatchClient();
+                if (blobs.Count <= 256)
+                {
+                    await bbc.DeleteBlobsAsync(blobs);
+                    return true;
+                }
+                else
+                {
+                    int pages = (blobs.Count + 255) / 256; //256是批量操作最大值,pages = (total + max -1) / max;
+                    for (int i = 0; i < pages; i++)
+                    {
+                        List<Uri> lists = blobs.Skip((i) * 256).Take(256).ToList();
+                        await bbc.DeleteBlobsAsync(lists);
+                    }
+                    return true;
+                }
+            }
+            catch
+            {
+                return false;
+            }
+        }
         /// <summary>        
         /// 批量刪除Blobs
         /// </summary>      

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Vote.cs

@@ -90,5 +90,6 @@ namespace TEAMModelOS.SDK.Models
     public class OptionsVote { 
         public string code { get; set; }
         public string value { get; set; }
+        public string desc { get; set; }
     }
 }

+ 85 - 7
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -14,6 +14,7 @@ using TEAMModelOS.SDK.DI;
 using System.Net.Http;
 using TEAMModelOS.SDK.Helper.Security.ShaHash;
 using TEAMModelOS.SDK.Extension;
+using System.IdentityModel.Tokens.Jwt;
 
 namespace TEAMModelOS.Controllers.Core
 {
@@ -39,8 +40,7 @@ namespace TEAMModelOS.Controllers.Core
         [HttpPost("sas-r")]
         public IActionResult BlobSasR(BlobSas request)
         {
-            ///返回金钥过期时间
-            ResponseBuilder builder = new ResponseBuilder();
+            ///返回金钥过期时间 
             // Dictionary<string, object> dict = await azureBlobDBRepository.GetBlobSasUri(request.@params,true);
             // dict.Add(d.Key, d.Value);
             return Ok(_azureStorage.GetContainerSasUri(request, true));
@@ -54,12 +54,92 @@ namespace TEAMModelOS.Controllers.Core
         public IActionResult BlobSasRCW(BlobSas request)
         {
             ///返回金钥过期时间
-            ResponseBuilder builder = new ResponseBuilder();
             // Dictionary<string,object> dict=  await azureBlobDBRepository.GetBlobSasUri(request.@params,false);
             //   Dictionary<string, object> dict = ;
             //dict.Add(d.Key, d.Value);
             return Ok(_azureStorage.GetContainerSasUri(request, false));
         }
+
+        /// <summary>
+        /// 删除prefix
+        /// 
+        /// {"cntr":"","prefix":"res/test"}
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("delete-prefix")]
+        public async Task<IActionResult> DeletePrefix(JsonElement json)
+        {
+            var (id,_,_,school) = HttpContext.GetAuthTokenInfo();
+            string blobContainerName = null;
+            string prefix = null;
+            if (json.TryGetProperty("cntr", out JsonElement cntr)) {
+                var cntrs= cntr.ToString();
+              
+                if (cntrs.Equals(id))
+                {
+                    blobContainerName = id;
+                }
+                else if(cntrs.Equals(school))
+                {
+                    blobContainerName = school;
+                }
+            }
+            if (json.TryGetProperty("prefix", out JsonElement prefixjson))
+            {
+                prefix = prefixjson.ToString();
+            }
+            if (prefix != null && blobContainerName != null)
+            {
+                var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, prefix);
+                return Ok(new { status });
+            }
+            else {
+                return BadRequest();
+            }
+            
+        }
+
+        /// <summary>
+        /// 删除多个Url
+        /// 
+        /// {"cntr":"","urls":["res/test/1.json","res/test/2.json"]}
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("delete-blobs")]
+        public async Task<IActionResult> DeleteBlobs(JsonElement json)
+        {
+            var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
+            string blobContainerName = null;
+            List<Uri> uris = null;
+            if (json.TryGetProperty("cntr", out JsonElement cntr))
+            {
+                var cntrs = cntr.ToString();
+
+                if (cntrs.Equals(id))
+                {
+                    blobContainerName = id;
+                }
+                else if (cntrs.Equals(school))
+                {
+                    blobContainerName = school;
+                }
+            }
+            if (json.TryGetProperty("urls", out JsonElement urlsjson)) {
+                uris= urlsjson.ToObject<List<Uri>>();
+            }
+            if (blobContainerName != null && uris != null && uris.Count > 0)
+            {
+                var status = await _azureStorage.GetBlobServiceClient().DelectBlobs("", new List<Uri>());
+                return Ok(new { });
+            }
+            else {
+                return BadRequest();
+            }
+        }
+
+
         /// <summary>
         /// 链接只读(读)
         /// </summary>
@@ -68,7 +148,6 @@ namespace TEAMModelOS.Controllers.Core
         [HttpPost("sas-url-r")]
         public IActionResult GetContainerSASRead(JsonElement azureBlobSASDto)
         {
-            ResponseBuilder responseBuilder = new ResponseBuilder();
             azureBlobSASDto.TryGetProperty("url", out JsonElement azureBlobSAS);
             //string azureBlobSAS = azureBlobSASDto;
             (string, string) a = BlobUrlString(azureBlobSAS.ToString());
@@ -95,8 +174,7 @@ namespace TEAMModelOS.Controllers.Core
         [HttpPost("get-text")]
         public async Task<IActionResult> GetText(JsonElement request)
         {
-            request.TryGetProperty("code", out JsonElement code);
-            ResponseBuilder responseBuilder = new ResponseBuilder();
+            request.TryGetProperty("code", out JsonElement code); 
             string azureBlobSAS = System.Web.HttpUtility.UrlDecode(code.ToString(), Encoding.UTF8);
             (string, string) a = BlobUrlString(azureBlobSAS);
             string ContainerName = a.Item1;
@@ -117,7 +195,7 @@ namespace TEAMModelOS.Controllers.Core
             };
 
         }
-
+        
         /// <summary>
         /// 测试单个文本内容的上传
         /// </summary>

+ 3 - 8
TEAMModelOS/Controllers/Import/ImportController.cs

@@ -85,7 +85,7 @@ namespace TEAMModelOS.Controllers
             //var jwt = new JwtSecurityToken(id_token);
             //if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
             //var id = jwt.Payload.Sub;
-
+            var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
             request.TryGetProperty("file", out JsonElement code);
             string azureBlobSAS = System.Web.HttpUtility.UrlDecode(code.ToString(), Encoding.UTF8);
             (string, string) a = BlobUrlString(azureBlobSAS);
@@ -105,7 +105,7 @@ namespace TEAMModelOS.Controllers
 
                 if (ext.ToLower() == "pptx" || ext.ToLower() == "xml")
                 {
-                    string index = await PPTXTranslator(ContainerName, FileName, stream);
+                    string index = await PPTXTranslator(id, FileName, stream);
                     return Ok(new { index = index });
                 }
                 else if (ext.ToLower() == "docx" || ext.ToLower() == "doc")
@@ -143,12 +143,7 @@ namespace TEAMModelOS.Controllers
         [RequestSizeLimit(102_400_000_00)] //最大10000m左右
         public async Task<IActionResult> UploadPPTX([FromForm] IFormFile file)
         {
-
-            string id_token = HttpContext.GetXAuth("IdToken");
-            if (string.IsNullOrEmpty(id_token)) return BadRequest();
-            var jwt = new JwtSecurityToken(id_token);
-            if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
-            var id = jwt.Payload.Sub;
+            var (id,_, _, school) = HttpContext.GetAuthTokenInfo();
             if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx") || FileType.GetExtention(file.FileName).ToLower().Equals("xml"))
             {
                 string FileName = file.FileName.Split(".")[0];

+ 61 - 0
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -0,0 +1,61 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+namespace TEAMModelOS.Controllers.XTest
+{
+    [Route("test")]
+    [ApiController]
+    public class TestController :ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        public TestController(AzureCosmosFactory azureCosmos) {
+            _azureCosmos = azureCosmos;
+        }
+
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher")]
+        [HttpPost("delete")]
+        public async Task<IActionResult> Delete(JsonElement request)
+        {
+            try
+            {
+             
+                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();
+                if (scope.ToString().Equals("school"))
+                {
+                    var query = $"select c.id from c ";
+                    var ids=  client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") });
+                    List<Task> tasksFiles = new List<Task>();
+                    await foreach (var id in ids) {
+                        using var json = await JsonDocument.ParseAsync(id.ContentStream);
+                        var jsonList= json.RootElement.GetProperty("Documents").EnumerateArray() ;
+                        //批量删除
+                        foreach (var obj in jsonList)
+                        {
+                            tasksFiles.Add(client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(obj.GetProperty("id").ToString(), new PartitionKey($"{code}")));
+                        }
+                    }
+                    await Task.WhenAll(tasksFiles);
+                }
+                return Ok(new { code = 1 });
+            }
+            catch (Exception e)
+            {
+                return BadRequest(e.StackTrace);
+            }
+        }
+    }
+}

+ 18 - 6
TEAMModelOS/JsonFile/Core/LangConfig.json

@@ -10,7 +10,9 @@
         "multiple": "多选题",
         "judge": "判断题",
         "complete": "填空题",
-        "subjective": "问答题"
+        "subjective": "问答题",
+        "connector": "连线题",
+        "correct": "改错题"
       },
       "AnswerTag": "答案",
       "AnalysisTag": "解析",
@@ -31,7 +33,9 @@
         "multiple": "多選題",
         "judge": "判斷題",
         "complete": "填空題",
-        "subjective": "問答題"
+        "subjective": "問答題",
+        "connector": "連綫題",
+        "correct": "改錯題"
       },
       "AnswerTag": "答案",
       "AnalysisTag": "解析",
@@ -52,7 +56,9 @@
         "multiple": "多選題",
         "judge": "判斷題",
         "complete": "填空題",
-        "subjective": "問答題"
+        "subjective": "問答題",
+        "connector": "連綫題",
+        "correct": "改錯題"
       },
       "AnswerTag": "答案",
       "AnalysisTag": "解析",
@@ -73,7 +79,9 @@
         "multiple": "複選題",
         "judge": "是非題",
         "complete": "填空題",
-        "subjective": "問答題"
+        "subjective": "問答題",
+        "connector": "連綫題",
+        "correct": "改錯題"
       },
       "AnswerTag": "答案",
       "AnalysisTag": "解析",
@@ -94,7 +102,9 @@
         "multiple": "Multiple-Answers",
         "judge": "True/False",
         "complete": "Fill-in-the-Blank",
-        "subjective": "Short-Answer"
+        "subjective": "Short-Answer",
+        "connector": "Connector",
+        "correct": "Correct"
       },
       "AnswerTag": "Answer",
       "AnalysisTag": "Explain",
@@ -115,7 +125,9 @@
         "multiple": "Multiple-Answers",
         "judge": "True/False",
         "complete": "Fill-in-the-Blank",
-        "subjective": "Short-Answer"
+        "subjective": "Short-Answer",
+        "connector": "Connector",
+        "correct": "Correct"
       },
       "AnswerTag": "Answer",
       "AnalysisTag": "Explain",