|
@@ -24,6 +24,10 @@ using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using TEAMModelOS.SDK.Context.Constant.Common;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using Azure.Cosmos;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Core
|
|
|
{
|
|
@@ -36,17 +40,25 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
private readonly IHttpClientFactory _clientFactory;
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
public IConfiguration _configuration { get; set; }
|
|
|
- public BlobController(AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IHttpClientFactory clientFactory, AzureRedisFactory azureRedis, IConfiguration configuration)
|
|
|
+ public BlobController(AzureStorageFactory azureStorage, AzureServiceBusFactory serviceBus, IHttpClientFactory clientFactory, AzureRedisFactory azureRedis, IConfiguration configuration,
|
|
|
+ DingDing dingDing,
|
|
|
+ IOptionsSnapshot<Option> option, AzureCosmosFactory azureCosmos)
|
|
|
{
|
|
|
_azureStorage = azureStorage;
|
|
|
_clientFactory = clientFactory;
|
|
|
_serviceBus = serviceBus;
|
|
|
_azureRedis = azureRedis;
|
|
|
- _configuration = configuration;
|
|
|
+ _configuration = configuration;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 获取某个容器的只读权限
|
|
|
+ /// 上传文件到指定的0-public
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
@@ -94,7 +106,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
//dict.Add(d.Key, d.Value);
|
|
|
return Ok(_azureStorage.GetContainerSasUri(request, false));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 删除prefix
|
|
|
///
|
|
@@ -131,33 +143,18 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
if (prefix != null && blobContainerName != null)
|
|
|
{
|
|
|
- long? size= await _azureStorage.GetBlobContainerClient(blobContainerName). GetBlobsSize( prefix);
|
|
|
var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, prefix);
|
|
|
- RedisValue value = default;
|
|
|
- long blobSize = 0;
|
|
|
- value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", blobContainerName);
|
|
|
- if (value != default && !value.IsNullOrEmpty)
|
|
|
+ string u ="";
|
|
|
+ string[] uls = System.Web.HttpUtility.UrlDecode($"{prefixjson}", Encoding.UTF8).Split("/");
|
|
|
+ if (uls != null)
|
|
|
{
|
|
|
- JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
- if (record.TryGetInt64(out blobSize))
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- long? useSize = blobSize - size;
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", blobContainerName, useSize);
|
|
|
- Dictionary<string, double?> catalog = new Dictionary<string, double?>();
|
|
|
- string u = System.Web.HttpUtility.UrlDecode(prefix, Encoding.UTF8).Split("/")[0];
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{blobContainerName}", u, size.HasValue? - size.Value:0);
|
|
|
- catalog[u] = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{blobContainerName}", u);
|
|
|
- if (catalog[u] < 0) {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{blobContainerName}", u);
|
|
|
- catalog[u] = 0;
|
|
|
+ u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
}
|
|
|
- var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update",root=new string[] { u }, name = blobContainerName }.ToJsonString());
|
|
|
- messageBlob.ApplicationProperties.Add("name", "Blob");
|
|
|
+ var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root =u, name = $"{blobContainerName}" }.ToJsonString()); ;
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "BlobRoot");
|
|
|
var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
- return Ok(new { status, catalog,size=useSize });
|
|
|
+ return Ok(new { status });
|
|
|
}
|
|
|
else {
|
|
|
return BadRequest();
|
|
@@ -165,6 +162,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 删除多个Url
|
|
|
///
|
|
@@ -211,41 +209,25 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
if (blobContainerName != null && uris != null && uris.Count > 0)
|
|
|
{
|
|
|
var urls = urlsjson.ToObject<List<string>>();
|
|
|
- var urlSize= await _azureStorage.GetBlobServiceClient().GetBlobContainerClient(blobContainerName).GetBlobsSize(urls);
|
|
|
var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, uris);
|
|
|
- RedisValue value = default;
|
|
|
- long blobSize = 0;
|
|
|
- value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", blobContainerName);
|
|
|
- if (value != default && !value.IsNullOrEmpty)
|
|
|
- {
|
|
|
- JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
- if (record.TryGetInt64(out blobSize))
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
//释放的空间
|
|
|
- long? useSize = blobSize + urlSize.Select(x=>x.size).Sum();
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", blobContainerName, useSize);
|
|
|
- Dictionary<string, double?> catalog = new Dictionary<string, double?>();
|
|
|
HashSet<string> root = new HashSet<string>();
|
|
|
- foreach (var x in urlSize)
|
|
|
+ foreach (var x in urls)
|
|
|
{
|
|
|
- string u = System.Web.HttpUtility.UrlDecode(x.url, Encoding.UTF8).Split("/")[0];
|
|
|
- root.Add(u);
|
|
|
- //释放文件夹空间
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{blobContainerName}", u, -x.size);
|
|
|
- catalog[u] = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{blobContainerName}", u);
|
|
|
- if (catalog[u] < 0)
|
|
|
+ string[] uls = System.Web.HttpUtility.UrlDecode(x, Encoding.UTF8).Split("/");
|
|
|
+ if (uls != null)
|
|
|
{
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{blobContainerName}", u);
|
|
|
- catalog[u] = 0;
|
|
|
+ string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
+ root.Add(u);
|
|
|
}
|
|
|
}
|
|
|
- var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = root.ToArray(), name = blobContainerName }.ToJsonString());
|
|
|
- messageBlob.ApplicationProperties.Add("name", "Blob");
|
|
|
- var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
- return Ok(new { status,size= useSize,catalog });
|
|
|
+ root.ToList().ForEach(async x => {
|
|
|
+ var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = x, name = $"{blobContainerName}" }.ToJsonString()); ;
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "BlobRoot");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
+ });
|
|
|
+ return Ok(new { status });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -255,7 +237,6 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
else {
|
|
|
return BadRequest("只能删除本人管理的文件");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -316,17 +297,18 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 测试单个文本内容的上传
|
|
|
+ /// 获取容器的 分类及总量
|
|
|
/// </summary>
|
|
|
/// <param name="azureBlobSASDto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("get-blobsize")]
|
|
|
public async Task<ActionResult> GetBlobsSize(JsonElement request)
|
|
|
{
|
|
|
- request.TryGetProperty("containerName", out JsonElement containerName);
|
|
|
- request.TryGetProperty("cache", out JsonElement cache);
|
|
|
- var name =containerName.GetString();
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ request.TryGetProperty("containerName", out JsonElement containerName);
|
|
|
+ request.TryGetProperty("cache", out JsonElement cache);
|
|
|
+ var name =containerName.GetString();
|
|
|
if (cache.GetBoolean())
|
|
|
{
|
|
|
long blobsize = 0;
|
|
@@ -335,34 +317,66 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
if (value != default && !value.IsNullOrEmpty)
|
|
|
{
|
|
|
JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
- if (record.TryGetInt64(out blobsize))
|
|
|
+ if (record.TryGetInt64(out blobsize))
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
+ }
|
|
|
+ return Ok(new { size = size.Item1, catalog = size.Item2 });
|
|
|
+ }
|
|
|
Dictionary<string, double> catalog = new Dictionary<string, double>();
|
|
|
SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{name}");
|
|
|
- if (Scores != null )
|
|
|
+ if (Scores != null)
|
|
|
{
|
|
|
- foreach (var score in Scores) {
|
|
|
+ foreach (var score in Scores)
|
|
|
+ {
|
|
|
double val = score.Score;
|
|
|
string key = score.Element.ToString();
|
|
|
catalog.Add(key, val);
|
|
|
- }
|
|
|
+ }
|
|
|
+ return Ok(new { size = blobsize, catalog = catalog });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
+ }
|
|
|
+ return Ok(new { size = size.Item1, catalog = size.Item2 });
|
|
|
}
|
|
|
- return Ok(new { size = blobsize, catalog= catalog });
|
|
|
}
|
|
|
- } catch { }
|
|
|
- var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
- var size = await client.GetBlobsCatalogSize();
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
- foreach (var key in size.Item2.Keys) {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue?size.Item2[key].Value:0);
|
|
|
+ else {
|
|
|
+ var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
+ }
|
|
|
+ return Ok(new { size = size.Item1, catalog = size.Item2 });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},blon/get-blobsize()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
- return Ok(new { size = size.Item1, catalog = size.Item2 });
|
|
|
+ return BadRequest();
|
|
|
}
|
|
|
|
|
|
+ //TODO 不要了
|
|
|
/// <summary>
|
|
|
/// 测试单个文本内容的上传
|
|
|
/// {"containerName":"hbcn","urls":["video/xxx.mp4","res/xxx.png"],"prefix":["res/xxx","res/aaa"]}
|
|
@@ -401,6 +415,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
]
|
|
|
}
|
|
|
*/
|
|
|
+ //TODO 不要了
|
|
|
/// <summary>
|
|
|
/// 测试单个文本内容的上传
|
|
|
/// {"containerName":"hbcn","uploadSize":5000,"optUrls":[{"url":"video/37Z888piCvm9.mp4","size":0},{}]}
|
|
@@ -431,13 +446,19 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
Dictionary<string, double?> catalog = new Dictionary<string, double?>();
|
|
|
HashSet<string> root = new HashSet<string>();
|
|
|
foreach (var x in urls) {
|
|
|
- string u = System.Web.HttpUtility.UrlDecode(x.url, Encoding.UTF8).Split("/")[0];
|
|
|
- root.Add(u);
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, x.size);
|
|
|
- catalog[u]= await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{name}", u);
|
|
|
- if (catalog[u] < 0) {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
|
|
|
- catalog[u] = 0;
|
|
|
+ string[] uls = System.Web.HttpUtility.UrlDecode(x.url, Encoding.UTF8).Split("/");
|
|
|
+ if (uls != null)
|
|
|
+ {
|
|
|
+ string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
+ root.Add(u);
|
|
|
+
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, x.size);
|
|
|
+ catalog[u] = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{name}", u);
|
|
|
+ if (catalog[u] < 0)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
|
|
|
+ catalog[u] = 0;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
var messageBlob = new ServiceBusMessage(new {id=Guid.NewGuid().ToString(), progress = "update", root= root.ToArray(), name=name}.ToJsonString());;
|
|
@@ -447,6 +468,38 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
return Ok(new { size=useSize, catalog });
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// {"name":"hbcn","urls":["root/xxxx/xxx.json","root/xxxx/xxx.json"]}
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="azureBlobSASDto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("refresh-blobsize")]
|
|
|
+ public async Task<ActionResult> RefreshBlob(JsonElement request) {
|
|
|
+ try {
|
|
|
+ request.TryGetProperty("name", out JsonElement name);
|
|
|
+ request.TryGetProperty("urls", out JsonElement jurls);
|
|
|
+ var urls = jurls.ToObject<List<string>>();
|
|
|
+ HashSet<string> root = new HashSet<string>();
|
|
|
+ foreach (var x in urls)
|
|
|
+ {
|
|
|
+ string[] uls = System.Web.HttpUtility.UrlDecode(x, Encoding.UTF8).Split("/");
|
|
|
+ if (uls != null) {
|
|
|
+ string u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
+ root.Add(u);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ root.ToList().ForEach(async x => {
|
|
|
+ var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root =x, name = $"{name}" }.ToJsonString()); ;
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "BlobRoot");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
+ });
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ } catch (Exception ex) {
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},blon/refresh-blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ return Ok(new { status = 500 });
|
|
|
+ }
|
|
|
private static (string, string) BlobUrlString(string sasUrl)
|
|
|
{
|
|
|
sasUrl = sasUrl.Substring(8);
|
|
@@ -462,5 +515,91 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
return System.Text.RegularExpressions.Regex.IsMatch(BlobName,
|
|
|
@"(?!((^(con)$)|^(con)\\..*|(^(prn)$)|^(prn)\\..*|(^(aux)$)|^(aux)\\..*|(^(nul)$)|^(nul)\\..*|(^(com)[1-9]$)|^(com)[1-9]\\..*|(^(lpt)[1-9]$)|^(lpt)[1-9]\\..*)|^\\s+|.*\\s$)(^[^\\\\\\:\\<\\>\\*\\?\\\\\\""\\\\|]{1,255}$)");
|
|
|
}
|
|
|
+
|
|
|
+ [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);
|
|
|
+ }
|
|
|
+ return Ok(new { bloblogs = bloblogs });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("bloblog-upsert")]
|
|
|
+ public async Task<ActionResult> BloblogUpsert(JsonElement request) {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ request.TryGetProperty("period", out JsonElement period);
|
|
|
+ request.TryGetProperty("scope", out JsonElement scope);
|
|
|
+ request.TryGetProperty("name", out JsonElement name);
|
|
|
+ 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("/");
|
|
|
+ if (uls != null)
|
|
|
+ {
|
|
|
+ var u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
+
|
|
|
+ }
|
|
|
+ var size = await _azureStorage.GetBlobContainerClient($"{name}").GetBlobsSize(url);
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ //获取文件的大小
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ 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}"));
|
|
|
+ }
|
|
|
+ else if (scope.GetString().Equals("teacher"))
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "teacher").DeleteItemStreamAsync($"{id}", new Azure.Cosmos.PartitionKey($"Bloblog-{name}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else { return BadRequest(); }
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},blon/refresh-blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|