浏览代码

調整Code中,可啟動,尚未完成

JAELYS 4 年之前
父节点
当前提交
6287057d47

+ 53 - 4
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageFactory.cs

@@ -75,9 +75,57 @@ namespace TEAMModelOS.SDK.DI
             }
         }
 
+        /// <summary>
+        /// 取得Blob Container SAS (有效期預設一天)
+        /// </summary>
+        /// <param name="containerName">容器名稱</param>
+        /// <param name="blobName"></param>
+        /// <param name="blobContainerSasPermissions"></param>
+        /// <param name="name"></param>
+        /// <returns></returns>
+        public (string uri ,string sas) GetBlobContainerSAS(string containerName, BlobContainerSasPermissions blobContainerSasPermissions, string name = "Default")
+        {
+            try
+            {
+                var keys = Utils.ParseConnectionString(_optionsMonitor.Get(name).StorageAccountConnectionString);
+                var accountname = keys["AccountName"];
+                var accountkey = keys["AccountKey"];
+                var endpoint = keys["EndpointSuffix"];
+
+                var blobSasBuilder = new BlobSasBuilder
+                {
+                    StartsOn = DateTimeOffset.UtcNow.Subtract(new TimeSpan(0, 15, 0)),
+                    ExpiresOn = DateTimeOffset.UtcNow.Add(new TimeSpan(1, 0, 15, 0)),
+                    BlobContainerName = containerName
+                };
+
+                blobSasBuilder.SetPermissions(blobContainerSasPermissions);
+                var sskc = new StorageSharedKeyCredential(accountname, accountkey);
+                BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(sskc);
+                UriBuilder fullUri = new UriBuilder()
+                {
+                    Scheme = "https",
+                    Host = $"{accountname}.blob.{endpoint}",
+                    Path = containerName
+                    //Query = sasQueryParameters.ToString()
+                };
+
+                return (fullUri.Uri.ToString(), sasQueryParameters.ToString());
+            }
+            catch
+            {
+                return (null, null);
+            }
+        }
+
         /// <summary>
         /// 取得Blob SAS (有效期預設一天)
-        /// </summary>       
+        /// </summary>
+        /// <param name="containerName">容器名稱</param>
+        /// <param name="blobName"></param>
+        /// <param name="blobSasPermissions"></param>
+        /// <param name="name"></param>
+        /// <returns></returns>
         public string GetBlobSAS(string containerName, string blobName, BlobSasPermissions blobSasPermissions, string name = "Default")
         {
             try
@@ -91,7 +139,8 @@ namespace TEAMModelOS.SDK.DI
                 {
                     StartsOn = DateTimeOffset.UtcNow.Subtract(new TimeSpan(0, 15, 0)),
                     ExpiresOn = DateTimeOffset.UtcNow.Add(new TimeSpan(1, 0, 15, 0)),
-                    BlobContainerName = containerName
+                    BlobContainerName = containerName,
+                    BlobName = blobName
                 };
 
                 blobSasBuilder.SetPermissions(blobSasPermissions);
@@ -101,11 +150,11 @@ namespace TEAMModelOS.SDK.DI
                 {
                     Scheme = "https",
                     Host = $"{accountname}.blob.{endpoint}",
-                    Path = blobName,
+                    Path = $"{containerName}/{blobName}",
                     Query = sasQueryParameters.ToString()
                 };
 
-                return sasQueryParameters.ToString();
+                return fullUri.Uri.ToString();
             }
             catch
             {

+ 30 - 3
TEAMModelOS/Controllers/Client/AClassONEController.cs

@@ -1,18 +1,45 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
 
 namespace TEAMModelOS.Controllers.Client
 {
-    [Route("api/[controller]")]
+    [Route("aclassone")]
     [ApiController]
     public class AClassONEController : ControllerBase
     {
-        public AClassONEController()
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        public AClassONEController(DingDing dingDing, IOptionsSnapshot<Option> option)
         {
-          
+            _dingDing = dingDing;
+            _option = option?.Value;
+        }
+
+        [Authorize(Roles = "AClassONE")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        [ProducesResponseType(StatusCodes.Status400BadRequest)]
+        [ProducesDefaultResponseType]
+        [HttpPost("init")]
+        public async Task<IActionResult> Init()
+        {
+            try
+            {
+
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"CoreAPI2,{_option.Location},Channel/Create()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+            return Ok();
         }
     }
 }

+ 0 - 36
TEAMModelOS/Controllers/Client/ClientController.cs

@@ -1,36 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using TEAMModelOS.SDK;
-using TEAMModelOS.SDK.Helper.Common.JsonHelper;
-using TEAMModelOS.SDK.Helper.Common.LogHelper;
-using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
-using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
-
-namespace TEAMModelOS.Controllers.Client
-{
-    [Route("api/[controller]")]
-    [ApiController]
-    public class ClientController : BaseController
-    {
-        private readonly IAzureBlobDBRepository azureBlobDBRepository;
-        public ClientController(IAzureBlobDBRepository _azureBlobDBRepository)
-        {
-            azureBlobDBRepository = _azureBlobDBRepository;
-        }
-        /// <summary>
-        /// 某个文件的上传SAS rcw权限
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [HttpPost("blobSasRCW")]
-        public async Task<BaseResponse> BlobSasRCW(JosnRequest<BlobSas> request)
-        {
-
-            ResponseBuilder builder = new ResponseBuilder();
-            return builder.Data(await azureBlobDBRepository.GetContainerSasUri(request.@params, false)).build();
-        }
-    }
-}

+ 31 - 3
TEAMModelOS/Controllers/Client/HiTAControlller.cs

@@ -1,18 +1,46 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
 
 namespace TEAMModelOS.Controllers.Client
 {
-    [Route("api/[controller]")]
+    [Route("hita")]
     [ApiController]
     public class HiTAControlller : ControllerBase
     {
-        public HiTAControlller()
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+
+        public HiTAControlller(DingDing dingDing, IOptionsSnapshot<Option> option)
         {
-           
+            _dingDing = dingDing;
+            _option = option?.Value;
+        }
+
+        [Authorize(Roles = "HiTeach")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        [ProducesResponseType(StatusCodes.Status400BadRequest)]
+        [ProducesDefaultResponseType]
+        [HttpPost("init")]
+        public async Task<IActionResult> Init()
+        {
+            try
+            {
+
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"CoreAPI2,{_option.Location},Channel/Create()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+            return Ok();
         }
     }
 }

+ 3 - 3
TEAMModelOS/Properties/launchSettings.json

@@ -1,4 +1,4 @@
-{
+{
   "$schema": "http://json.schemastore.org/launchsettings.json",
   "iisSettings": {
     "windowsAuthentication": false,
@@ -19,8 +19,8 @@
     },
     "TEAMModelOS": {
       "commandName": "Project",
-      "launchBrowser": false,
-      "launchUrl": "login",
+      "launchBrowser": true,
+      //"launchUrl": "login",
       "applicationUrl": "https://localhost:5001;http://localhost:5000",
       "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"

+ 2 - 2
TEAMModelOS/Startup.cs

@@ -89,8 +89,8 @@ namespace TEAMModelOS
             
             services.AddAzureStorage(Configuration.GetValue<string>("Azure:Starage:ConnectionString"));
             services.AddAzureRedis( Configuration.GetValue<string>("Azure:Redis:ConnectionString"));            
-            services.AddAzureCosmos(Configuration.GetValue<string>("Azure:CosmosDB:ConnectionString"));
-            services.AddSnowflakeId(0, 1);
+            services.AddAzureCosmos(Configuration.GetValue<string>("Azure:Cosmos:ConnectionString"));
+            services.AddSnowflakeId(Convert.ToInt64(Configuration.GetValue<string>("Option:LocationNum")), 1);
             services.AddHttpClient();
             services.AddHttpClient<DingDing>();            
             services.AddMemoryCache();            

+ 1 - 1
TEAMModelOS/TEAMModelOS.csproj

@@ -41,9 +41,9 @@
   </ItemGroup>
 
   <ItemGroup>
-    <Folder Include="wwwroot\" />
     <Folder Include="JwtRsaFile\" />
     <Folder Include="logfile\" />
+    <Folder Include="wwwroot\" />
   </ItemGroup>
   
   <ItemGroup>

+ 4 - 1
TEAMModelOS/appsettings.json

@@ -8,7 +8,7 @@
   },
   "Option": {
     "Location": "China",
-    "LocationNum": "1",
+    "LocationNum": "8",
     "HostName": "localhost:5001",
     "AllowedHosts": [ "localhost", "*.teammodel.cn", "*.teammodel.net", "*.habookaclass.biz", "test" ],
     "Authority": "https://login.chinacloudapi.cn/4807e9cf-87b8-4174-aa5b-e76497d7392b/v2.0", //China:"https://login.chinacloudapi.cn/4807e9cf-87b8-4174-aa5b-e76497d7392b/v2.0", //Global:"https://login.microsoftonline.com/73a2bcc5-fe99-4566-aa8a-07e7bb287df1/v2.0"
@@ -26,6 +26,9 @@
       "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn",
       "Container": "teammodelos"
     },
+    "Cosmos": {
+      "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
+    },
     "CosmosDB": {
       "ConnectionString": "https://teammodelos.documents.azure.cn:443/",
       "ConnectionKey": "clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==",