JAELYS vor 4 Jahren
Ursprung
Commit
0e1da4a3cc

+ 1 - 6
TEAMModelOS.SDK/Extension/JsonExtensions.cs

@@ -52,11 +52,6 @@ namespace TEAMModelOS.SDK.Extension
             jelement.WriteTo(writer);
             writer.Flush();
             return JsonSerializer.Deserialize<T>(bufferWriter.WrittenSpan, options);
-        }
-        public static T ToObject<T>(this string jelement, JsonSerializerOptions options = null)
-        {
-           
-            return JsonSerializer.Deserialize<T>(jelement, options);
-        }
+        }        
     }
 }

+ 13 - 11
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -22,13 +22,13 @@ namespace TEAMModelOS.Controllers.Core
     public class BlobController : BaseController
     {
 
-        private readonly AzureStorageFactory _azureCosmos;
+        private readonly AzureStorageFactory _azureStorage;
         private readonly SnowflakeId _snowflakeId;
         private readonly IHttpClientFactory _clientFactory;
 
-        public BlobController(AzureStorageFactory azureCosmos, SnowflakeId snowflakeId, IHttpClientFactory clientFactory)
+        public BlobController(AzureStorageFactory azureStorage, SnowflakeId snowflakeId, IHttpClientFactory clientFactory)
         {
-            _azureCosmos = azureCosmos;
+            _azureStorage = azureStorage;
             _snowflakeId = snowflakeId;
             _clientFactory = clientFactory;
         }
@@ -45,7 +45,7 @@ namespace TEAMModelOS.Controllers.Core
             ResponseBuilder builder = new ResponseBuilder();
             // Dictionary<string, object> dict = await azureBlobDBRepository.GetBlobSasUri(request.@params,true);
             // dict.Add(d.Key, d.Value);
-            return builder.Data(_azureCosmos.GetContainerSasUri(request, true)).build();
+            return builder.Data(_azureStorage.GetContainerSasUri(request, true)).build();
         }
         /// <summary>
         /// 某个文件的上传SAS rcw权限
@@ -60,7 +60,7 @@ namespace TEAMModelOS.Controllers.Core
             // Dictionary<string,object> dict=  await azureBlobDBRepository.GetBlobSasUri(request.@params,false);
             //   Dictionary<string, object> dict = ;
             //dict.Add(d.Key, d.Value);
-            return builder.Data(_azureCosmos.GetContainerSasUri(request, false)).build();
+            return builder.Data(_azureStorage.GetContainerSasUri(request, false)).build();
         }
         /// <summary>
         /// 链接只读(读)
@@ -79,7 +79,7 @@ namespace TEAMModelOS.Controllers.Core
             bool flg = IsBlobName(BlobName);
             if (flg)
             {
-                return responseBuilder.Data(_azureCosmos.GetBlobSasUriRead(ContainerName, BlobName)).build();
+                return responseBuilder.Data(_azureStorage.GetBlobSasUriRead(ContainerName, BlobName)).build();
             }
             else
             {
@@ -103,10 +103,12 @@ namespace TEAMModelOS.Controllers.Core
             bool flg = IsBlobName(BlobName);
             if (flg)
             {
-                BlobAuth blobAuth=    azureBlobDBRepository.GetBlobSasUriRead(ContainerName, BlobName);
-                string  text= await HttpHelper.HttpGetAsync(blobAuth.url + blobAuth.sas);
-                JsonElement json = text.FromApiJson<JsonElement>();
-                return responseBuilder.Data(json).build();
+                //TODO 需驗證
+                BlobAuth blobAuth= _azureStorage.GetBlobSasUriRead(ContainerName, BlobName);
+                var  response= await _clientFactory.CreateClient().GetAsync(new Uri(blobAuth.url + blobAuth.sas));
+                response.EnsureSuccessStatusCode();
+                using var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());                
+                return responseBuilder.Data(json.RootElement).build();
             }
             else
             {
@@ -124,7 +126,7 @@ namespace TEAMModelOS.Controllers.Core
         public async Task<BaseResponse> UploadText(JsonElement request)
         {
             ResponseBuilder responseBuilder = new ResponseBuilder();
-            return responseBuilder.Data(await azureBlobDBRepository.UploadFileByContainer("hbcn", request, "exam", SnowflakeId.NextId() + ".json")).build();
+            return responseBuilder.Data(await _azureStorage.UploadFileByContainer("hbcn", request.ToJsonString(), "exam", _snowflakeId.NextId() + ".json")).build();
           
         }
 

+ 2 - 2
TEAMModelOS/Controllers/Task/HomeworkController.cs

@@ -51,7 +51,7 @@ namespace TEAMModelOS.Controllers.Learn
         {
             ResponseBuilder builder = ResponseBuilder.custom();
             request.TryGetProperty("id", out JsonElement homeWorkId);
-            List<Homework> homeWorks = await _cosmos.FindByDict<Homework>(new Dictionary<string, object> { { "id", homeWorkId.ToString() } });
+            List<Homework> homeWorks = await _azureCosmos.FindByDict<Homework>(new Dictionary<string, object> { { "id", homeWorkId.ToString() } });
 
             foreach (Homework homeWork in homeWorks)
             {
@@ -60,7 +60,7 @@ namespace TEAMModelOS.Controllers.Learn
             List<Homework> homeWorks1 = await _azureCosmos.UpdateAll<Homework>(homeWorks);
 
             //查询之前是否有 关联关系表 HomeWorkStudent 有则删除
-            List<HomeworkRecord> homeWorkStudents = await _cosmos.FindByDict<HomeworkRecord>(new Dictionary<string, object> { { "id", homeWorkId.ToString() } });
+            List<HomeworkRecord> homeWorkStudents = await _azureCosmos.FindByDict<HomeworkRecord>(new Dictionary<string, object> { { "id", homeWorkId.ToString() } });
             if (homeWorkStudents.IsNotEmpty())
             {