|
@@ -20,7 +20,6 @@ using StackExchange.Redis;
|
|
|
using Azure.Messaging.ServiceBus;
|
|
|
using static TEAMModelOS.SDK.DI.AzureStorageBlobExtensions;
|
|
|
using System.Linq;
|
|
|
-using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using TEAMModelOS.SDK.Context.Constant.Common;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
@@ -516,20 +515,63 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
@"(?!((^(con)$)|^(con)\\..*|(^(prn)$)|^(prn)\\..*|(^(aux)$)|^(aux)\\..*|(^(nul)$)|^(nul)\\..*|(^(com)[1-9]$)|^(com)[1-9]\\..*|(^(lpt)[1-9]$)|^(lpt)[1-9]\\..*)|^\\s+|.*\\s$)(^[^\\\\\\:\\<\\>\\*\\?\\\\\\""\\\\|]{1,255}$)");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
[HttpPost("bloblog-list")]
|
|
|
public async Task<ActionResult> BloblogList(JsonElement request) {
|
|
|
- request.TryGetProperty("name", out JsonElement name);
|
|
|
- request.TryGetProperty("type", out JsonElement type);
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- var queryslt = $"SELECT value(c) FROM c WHERE c.type='{type}' c.code = 'Bloblog-{name}'";
|
|
|
List<Bloblog> bloblogs = new List<Bloblog>();
|
|
|
- await foreach (var item in client.GetDatabaseQueryIterator<Bloblog>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") })) {
|
|
|
- bloblogs.Add(item);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ request.TryGetProperty("name", out JsonElement name);
|
|
|
+ request.TryGetProperty("type", out JsonElement type);
|
|
|
+ request.TryGetProperty("scope", out JsonElement scope);
|
|
|
+ request.TryGetProperty("period", out JsonElement period);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var queryslt = $"SELECT value(c) FROM c WHERE c.type='{type}' and c.period='{period}'";
|
|
|
+ if (scope.GetString().Equals("school"))
|
|
|
+ {
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Bloblog>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
+ {
|
|
|
+ bloblogs.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (scope.GetString().Equals("teacher"))
|
|
|
+ {
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Bloblog>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
+ {
|
|
|
+ bloblogs.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(new { bloblogs = bloblogs });
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ return Ok(new { bloblogs = bloblogs });
|
|
|
}
|
|
|
- return Ok(new { bloblogs = bloblogs });
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /*
|
|
|
+ 新增 编辑接口
|
|
|
+ {
|
|
|
+ "period": "",
|
|
|
+ "scope": "school",
|
|
|
+ "name": "hbcn",
|
|
|
+ "url": "video/xxx.png",
|
|
|
+ "opt": "add",
|
|
|
+ }
|
|
|
+ */
|
|
|
+ /*
|
|
|
+ {
|
|
|
+ "scope": "school",
|
|
|
+ "name": "hbcn",
|
|
|
+ "opt": "del",
|
|
|
+ "id": "19ccce98-c524-4ea7-aabc-887d1391e551"
|
|
|
+ }
|
|
|
+ */
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
@@ -546,12 +588,12 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
request.TryGetProperty("url", out JsonElement jurl);
|
|
|
request.TryGetProperty("opt", out JsonElement opt);
|
|
|
request.TryGetProperty("id", out JsonElement id);
|
|
|
- request.TryGetProperty("type", out JsonElement type);
|
|
|
var url = System.Web.HttpUtility.UrlDecode(jurl.GetString(), Encoding.UTF8);
|
|
|
string[] uls = url.Split("/");
|
|
|
+ var u = "";
|
|
|
if (uls != null)
|
|
|
{
|
|
|
- var u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
+ u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
|
|
|
}
|
|
|
var size = await _azureStorage.GetBlobContainerClient($"{name}").GetBlobsSize(url);
|
|
@@ -560,34 +602,60 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
if (opt.GetString().Equals("add"))
|
|
|
{
|
|
|
- var blob = new Bloblog
|
|
|
- {
|
|
|
- id = Guid.NewGuid().ToString(),
|
|
|
- pk = "Bloblog",
|
|
|
- code = $"Bloblog-{name}",
|
|
|
- url = url,
|
|
|
- time = now,
|
|
|
- size = size != null && size.HasValue ? size.Value : 0,
|
|
|
- period = $"{period}"
|
|
|
- };
|
|
|
- if (scope.GetString().Equals("school"))
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "school").CreateItemAsync(blob, new Azure.Cosmos.PartitionKey(blob.code));
|
|
|
+ //地址相同的,直接更新
|
|
|
+ bool exsit = false;
|
|
|
+ try {
|
|
|
+ var queryslt = $"SELECT value(c) FROM c WHERE c.url='{url}'";
|
|
|
+ if (scope.GetString().Equals("school"))
|
|
|
+ {
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Bloblog>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
+ {
|
|
|
+ item.size = size != null && size.HasValue ? size.Value : 0;
|
|
|
+ await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Bloblog>(item, item.id, new Azure.Cosmos.PartitionKey(item.code));
|
|
|
+ exsit = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (scope.GetString().Equals("teacher")) {
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Bloblog>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
+ {
|
|
|
+ item.size = size != null && size.HasValue ? size.Value : 0;
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Bloblog>(item, item.id, new Azure.Cosmos.PartitionKey(item.code));
|
|
|
+ exsit = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
}
|
|
|
- else if (scope.GetString().Equals("teacher"))
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "teacher").CreateItemAsync(blob, new Azure.Cosmos.PartitionKey(blob.code));
|
|
|
+ if (!exsit) {
|
|
|
+ var blob = new Bloblog
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ pk = "Bloblog",
|
|
|
+ code = $"Bloblog-{name}",
|
|
|
+ url = url,
|
|
|
+ time = now,
|
|
|
+ size = size != null && size.HasValue ? size.Value : 0,
|
|
|
+ period = $"{period}",
|
|
|
+ type = u
|
|
|
+ };
|
|
|
+ if (scope.GetString().Equals("school"))
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(blob, new Azure.Cosmos.PartitionKey(blob.code));
|
|
|
+ }
|
|
|
+ else if (scope.GetString().Equals("teacher"))
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(blob, new Azure.Cosmos.PartitionKey(blob.code));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else if (opt.GetString().Equals("del"))
|
|
|
{
|
|
|
if (scope.GetString().Equals("school"))
|
|
|
{
|
|
|
- await client.GetContainer("TEAMModelOS", "school").DeleteItemStreamAsync($"{id}", new Azure.Cosmos.PartitionKey($"Bloblog-{name}"));
|
|
|
+ await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{id}", new Azure.Cosmos.PartitionKey($"Bloblog-{name}"));
|
|
|
}
|
|
|
else if (scope.GetString().Equals("teacher"))
|
|
|
{
|
|
|
- await client.GetContainer("TEAMModelOS", "teacher").DeleteItemStreamAsync($"{id}", new Azure.Cosmos.PartitionKey($"Bloblog-{name}"));
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync($"{id}", new Azure.Cosmos.PartitionKey($"Bloblog-{name}"));
|
|
|
}
|
|
|
}
|
|
|
else { return BadRequest(); }
|