浏览代码

文件上传

CrazyIter_Bin 4 年之前
父节点
当前提交
a8c9cd7d20

+ 113 - 0
TEAMModelFunction/Properties/ServiceDependencies/TEAMModelOSFunction - 压缩部署/profile.arm.json

@@ -0,0 +1,113 @@
+{
+  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
+  "contentVersion": "1.0.0.0",
+  "metadata": {
+    "_dependencyType": "appService.windows"
+  },
+  "parameters": {
+    "resourceGroupName": {
+      "type": "string",
+      "defaultValue": "TEAMModelChengdu",
+      "metadata": {
+        "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
+      }
+    },
+    "resourceGroupLocation": {
+      "type": "string",
+      "defaultValue": "",
+      "metadata": {
+        "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support."
+      }
+    },
+    "resourceName": {
+      "type": "string",
+      "defaultValue": "TEAMModelOSFunction",
+      "metadata": {
+        "description": "Name of the main resource to be created by this template."
+      }
+    },
+    "resourceLocation": {
+      "type": "string",
+      "defaultValue": "[parameters('resourceGroupLocation')]",
+      "metadata": {
+        "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
+      }
+    }
+  },
+  "variables": {
+    "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+    "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]"
+  },
+  "resources": [
+    {
+      "type": "Microsoft.Resources/resourceGroups",
+      "name": "[parameters('resourceGroupName')]",
+      "location": "[parameters('resourceGroupLocation')]",
+      "apiVersion": "2019-10-01"
+    },
+    {
+      "type": "Microsoft.Resources/deployments",
+      "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+      "resourceGroup": "[parameters('resourceGroupName')]",
+      "apiVersion": "2019-10-01",
+      "dependsOn": [
+        "[parameters('resourceGroupName')]"
+      ],
+      "properties": {
+        "mode": "Incremental",
+        "template": {
+          "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+          "contentVersion": "1.0.0.0",
+          "resources": [
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[parameters('resourceName')]",
+              "type": "Microsoft.Web/sites",
+              "apiVersion": "2015-08-01",
+              "tags": {
+                "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty"
+              },
+              "dependsOn": [
+                "[variables('appServicePlan_ResourceId')]"
+              ],
+              "kind": "app",
+              "properties": {
+                "name": "[parameters('resourceName')]",
+                "kind": "app",
+                "httpsOnly": true,
+                "reserved": false,
+                "serverFarmId": "[variables('appServicePlan_ResourceId')]",
+                "siteConfig": {
+                  "metadata": [
+                    {
+                      "name": "CURRENT_STACK",
+                      "value": "dotnetcore"
+                    }
+                  ]
+                }
+              },
+              "identity": {
+                "type": "SystemAssigned"
+              }
+            },
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[variables('appServicePlan_name')]",
+              "type": "Microsoft.Web/serverFarms",
+              "apiVersion": "2015-08-01",
+              "sku": {
+                "name": "S1",
+                "tier": "Standard",
+                "family": "S",
+                "size": "S1"
+              },
+              "properties": {
+                "name": "[variables('appServicePlan_name')]"
+              }
+            }
+          ]
+        }
+      }
+    }
+  ]
+}

+ 15 - 10
TEAMModelOS/Controllers/Core/ImportController.cs

@@ -86,6 +86,13 @@ namespace TEAMModelOS.Controllers
             //if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
             //var id = jwt.Payload.Sub;
             var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
+            var containerid = id;
+            if (request.TryGetProperty("scope", out JsonElement jscope)) {
+                if (jscope.GetString().Equals("school"))
+                {
+                    containerid = school;
+                }
+            }
             request.TryGetProperty("file", out JsonElement code);
             string azureBlobSAS = System.Web.HttpUtility.UrlDecode(code.ToString(), Encoding.UTF8);
             (string, string) a = BlobUrlString(azureBlobSAS);
@@ -105,7 +112,7 @@ namespace TEAMModelOS.Controllers
 
                 if (ext.ToLower() == "pptx" || ext.ToLower() == "xml")
                 {
-                    string index = await PPTXTranslator(id, FileName, stream);
+                    string index = await PPTXTranslator(containerid, FileName, stream);
                     return Ok(new { index = index });
                 }
                 else if (ext.ToLower() == "docx" || ext.ToLower() == "doc")
@@ -155,8 +162,6 @@ namespace TEAMModelOS.Controllers
             {
                 return BadRequest("type is not pptx or xml !");
             }
-
-
         }
 
         /// <summary>
@@ -213,12 +218,12 @@ namespace TEAMModelOS.Controllers
         }
 
 
-        private async Task<string> PPTXTranslator(string id, string FileName, Stream streamFile)
+        private async Task<string> PPTXTranslator(string containerid, string FileName, Stream streamFile)
         {
-            if (string.IsNullOrWhiteSpace(id)) {
-                id = "teammodelos";
+            if (string.IsNullOrWhiteSpace(containerid)) {
+                containerid = "teammodelos";
             }
-            var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(id, $"res/{FileName}");
+            var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(containerid, $"res/{FileName}");
             
             string shaCode = Guid.NewGuid().ToString();
             HTEXLib.Htex htex = _PPTX2HTEXTranslator.Translate(streamFile);
@@ -238,7 +243,7 @@ namespace TEAMModelOS.Controllers
             foreach (var key in blobslidenames)
             {
                 slds.Add(new Sld { type = "normal", url = $"{key.Key}.json", scoring = null }); ;
-                tasks.Add(_azureStorage.UploadFileByContainer(id, key.Value, "res", $"{FileName}/{key.Key}.json" ,  false));
+                tasks.Add(_azureStorage.UploadFileByContainer(containerid, key.Value, "res", $"{FileName}/{key.Key}.json" ,  false));
             }
             await Task.WhenAll(tasks);
            // Dictionary<string, Store> dict = new Dictionary<string, Store>();
@@ -259,7 +264,7 @@ namespace TEAMModelOS.Controllers
                    // var urlstrs = key.Split("/");
                     var name = key.Replace("/","");
                     str.url = $"{name}";
-                    tasksFiles.Add(_azureStorage.UploadFileByContainer(id, stream, "res", $"{FileName}/{name}", false));
+                    tasksFiles.Add(_azureStorage.UploadFileByContainer(containerid, stream, "res", $"{FileName}/{name}", false));
                 }
                 else
                 {
@@ -270,7 +275,7 @@ namespace TEAMModelOS.Controllers
             await Task.WhenAll(tasksFiles);
            // index.stores = dict;
             index.slides = slds;
-            var BlobUrl = await _azureStorage.UploadFileByContainer(id, JsonHelper.ToJson(index, ignoreNullValue: false), "res", FileName + "/" + "index.json", false);
+            var BlobUrl = await _azureStorage.UploadFileByContainer(containerid, JsonHelper.ToJson(index, ignoreNullValue: false), "res", FileName + "/" + "index.json", false);
             return System.Web.HttpUtility.UrlDecode(BlobUrl, Encoding.UTF8);
         }
     }