|
@@ -322,6 +322,61 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
return Ok(new { bloblogs = bloblogs });
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 测试单个文本内容的上传
|
|
|
+ /// {"containerName":"hbcn","uploadSize":5000,"optUrls":[{"url":"video/37Z888piCvm9.mp4","size":0},{}]}
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="azureBlobSASDto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("update-blobsize")]
|
|
|
+ public async Task<ActionResult> updateBlobsSize(JsonElement request)
|
|
|
+ {
|
|
|
+ request.TryGetProperty("containerName", out JsonElement containerName);
|
|
|
+ request.TryGetProperty("optUrls", out JsonElement optUrls);
|
|
|
+ var name = containerName.GetString();
|
|
|
+ var urls = optUrls.ToObject<List<OptUrl>>();
|
|
|
+ var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
+ var disSize = urls.Select(x => x.size).Sum();
|
|
|
+ RedisValue value = default;
|
|
|
+ long blobSize = 0;
|
|
|
+ value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
|
|
|
+ if (value != default && !value.IsNullOrEmpty)
|
|
|
+ {
|
|
|
+ JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
+ if (record.TryGetInt64(out blobSize))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long? useSize = blobSize + disSize;
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
|
|
|
+ Dictionary<string, double?> catalog = new Dictionary<string, double?>();
|
|
|
+ HashSet<string> root = new HashSet<string>();
|
|
|
+ foreach (var x in urls)
|
|
|
+ {
|
|
|
+ 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()); ;
|
|
|
+ messageBlob.ApplicationProperties.Add("name", "Blob");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
+ return Ok(new { size = useSize, catalog });
|
|
|
+ }
|
|
|
+
|
|
|
+ //public string BloblogRename(JsonElement json) {
|
|
|
+ //}
|
|
|
|
|
|
/*
|
|
|
新增 编辑接口
|
|
@@ -414,7 +469,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"IES5,{_option.Location},blob/refresh-blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},blob/bloblog-blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
if (!exsit)
|
|
|
{
|
|
@@ -461,7 +516,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"IES5,{_option.Location},blob/refresh-blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},blob/bloblog-blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
return Ok(new { status = 200 });
|
|
|
}
|
|
@@ -522,11 +577,16 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public record ContBlob {
|
|
|
+ public string path { get; set; }
|
|
|
+ public string id { get; set; }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除多个Url,只会在内容模块使用该接口
|
|
|
///
|
|
|
/// {"cntr":"","urls":["res/test/1.json","res/test/2.json"]}
|
|
|
+ /// {"scope":"school","cntr":"hbcn","blobs":[{"path":"other/test/1.json","id":"c107069d-4553-46c2-8c81-b3e6b4599393"},{"path":"res/test","id":"09d59b87-68c0-45fa-8221-9931a4190a2f"}]}
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
@@ -534,64 +594,53 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
public async Task<IActionResult> DeleteBlobs(JsonElement json)
|
|
|
{
|
|
|
- var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
- string blobContainerName = null;
|
|
|
- List<string> uris = null;
|
|
|
- if (!json.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
- if (!json.TryGetProperty("ids", out JsonElement _ids)) return BadRequest();
|
|
|
- if (json.TryGetProperty("cntr", out JsonElement cntr))
|
|
|
- {
|
|
|
- var cntrs = cntr.ToString();
|
|
|
- if (cntrs.Equals(id))
|
|
|
+ ///BlobBaseClient copy
|
|
|
+ try {
|
|
|
+ var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ string blobContainerName = null;
|
|
|
+ if (!json.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
+ if (!json.TryGetProperty("blobs", out JsonElement _blobs)) return BadRequest();
|
|
|
+ if (json.TryGetProperty("cntr", out JsonElement cntr))
|
|
|
{
|
|
|
- blobContainerName = id;
|
|
|
- }
|
|
|
- else if (cntrs.Equals(school))
|
|
|
- {
|
|
|
- blobContainerName = school;
|
|
|
+ var cntrs = cntr.ToString();
|
|
|
+ if (cntrs.Equals(id))
|
|
|
+ {
|
|
|
+ blobContainerName = id;
|
|
|
+ }
|
|
|
+ else if (cntrs.Equals(school))
|
|
|
+ {
|
|
|
+ blobContainerName = school;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest("只能删除本人管理的文件");
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ bool flag = true;
|
|
|
+ List<ContBlob> blobs = _blobs.ToObject<List<ContBlob>>();
|
|
|
+ try
|
|
|
{
|
|
|
- return BadRequest("只能删除本人管理的文件");
|
|
|
- }
|
|
|
- }
|
|
|
- bool flag = true;
|
|
|
- if (json.TryGetProperty("urls", out JsonElement urlsjson))
|
|
|
- {
|
|
|
- uris = urlsjson.ToObject<List<string>>();
|
|
|
- uris.ForEach(x => {
|
|
|
- (string, string) a = BlobUrlString(x.ToString());
|
|
|
- string ContainerName = a.Item1;
|
|
|
- string BlobName = a.Item2;
|
|
|
- if (ContainerName != blobContainerName)
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ List<string> ids = blobs.Select(x => x.id).ToList();
|
|
|
+ string containerId = "School";
|
|
|
+ if (_scope.GetString().Equals("school"))
|
|
|
{
|
|
|
- flag = false;
|
|
|
+ containerId = "School";
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- try
|
|
|
- {
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- List<string> ids = _ids.ToObject<List<string>>();
|
|
|
- if (_scope.GetString().Equals("school"))
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "School").DeleteItemsAsync<Bloblog>(ids, $"Bloblog-{blobContainerName}");
|
|
|
+ else if (_scope.GetString().Equals("private"))
|
|
|
+ {
|
|
|
+ containerId = "Teacher";
|
|
|
+ }
|
|
|
+ await client.GetContainer("TEAMModelOS", containerId).DeleteItemsAsync<Bloblog>(ids, $"Bloblog-{blobContainerName}");
|
|
|
}
|
|
|
- else if (_scope.GetString().Equals("private"))
|
|
|
+ catch
|
|
|
{
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemsAsync<Bloblog>(ids, $"Bloblog-{blobContainerName}");
|
|
|
+ //仅处理 cosmos不存在 但容器又存在的
|
|
|
}
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- //仅处理 cosmos不存在 但容器又存在的
|
|
|
- }
|
|
|
- if (flag)
|
|
|
- {
|
|
|
- if (blobContainerName != null && uris != null && uris.Count > 0)
|
|
|
+ if (flag)
|
|
|
{
|
|
|
- var urls = urlsjson.ToObject<List<string>>();
|
|
|
- var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, uris);
|
|
|
+ var urls = blobs.Select(x => x.path).ToList();
|
|
|
+ var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, urls);
|
|
|
//释放的空间
|
|
|
HashSet<string> root = new HashSet<string>();
|
|
|
foreach (var x in urls)
|
|
@@ -613,12 +662,12 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return BadRequest();
|
|
|
+ return BadRequest("只能删除本人管理的文件");
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return BadRequest("只能删除本人管理的文件");
|
|
|
+ } catch (Exception ex) {
|
|
|
+
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},blob/delete-blobs\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
}
|