|
@@ -106,121 +106,6 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
//dict.Add(d.Key, d.Value);
|
|
|
return Ok(_azureStorage.GetContainerSasUri(request, false));
|
|
|
}
|
|
|
- /// <summary>
|
|
|
- /// 删除prefix 不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。
|
|
|
- ///
|
|
|
- /// {"cntr":"","prefix":"res/test","scope":"school","id":"1111"}
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("delete-prefix")]
|
|
|
- [AuthToken(Roles = "teacher,admin")]
|
|
|
- public async Task<IActionResult> DeletePrefixContent(JsonElement json)
|
|
|
- {
|
|
|
- var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
- string blobContainerName = null;
|
|
|
- string prefix = null;
|
|
|
- if (json.TryGetProperty("cntr", out JsonElement cntr) && cntr.ValueKind.Equals(JsonValueKind.String))
|
|
|
- {
|
|
|
- var cntrs = cntr.GetString();
|
|
|
-
|
|
|
- if (cntrs.Equals(id))
|
|
|
- {
|
|
|
- blobContainerName = id;
|
|
|
- }
|
|
|
- else if (cntrs.Equals(school))
|
|
|
- {
|
|
|
- blobContainerName = school;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return BadRequest("只能删除本人管理的文件夹");
|
|
|
- }
|
|
|
- }
|
|
|
- if (json.TryGetProperty("prefix", out JsonElement prefixjson) && prefixjson.ValueKind.Equals(JsonValueKind.String))
|
|
|
- {
|
|
|
- prefix = prefixjson.GetString();
|
|
|
- }
|
|
|
- if (prefix != null && blobContainerName != null)
|
|
|
- {
|
|
|
- var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, prefix);
|
|
|
- string u = "";
|
|
|
- string[] uls = System.Web.HttpUtility.UrlDecode($"{prefixjson}", Encoding.UTF8).Split("/");
|
|
|
- if (uls != null)
|
|
|
- {
|
|
|
- u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
- }
|
|
|
- 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 });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return BadRequest();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 删除prefix 不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。
|
|
|
- ///
|
|
|
- /// {"cntr":"","prefix":"res/test"}
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("delete-prefix")]
|
|
|
- [AuthToken(Roles = "teacher,admin")]
|
|
|
- public async Task<IActionResult> DeletePrefix(JsonElement json)
|
|
|
- {
|
|
|
- var (id,_,_,school) = HttpContext.GetAuthTokenInfo();
|
|
|
- string blobContainerName = null;
|
|
|
- string prefix = null;
|
|
|
- if (json.TryGetProperty("cntr", out JsonElement cntr)&& cntr.ValueKind.Equals(JsonValueKind.String)) {
|
|
|
- var cntrs= cntr.GetString();
|
|
|
-
|
|
|
- if (cntrs.Equals(id))
|
|
|
- {
|
|
|
- blobContainerName = id;
|
|
|
- }
|
|
|
- else if(cntrs.Equals(school))
|
|
|
- {
|
|
|
- blobContainerName = school;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return BadRequest("只能删除本人管理的文件夹");
|
|
|
- }
|
|
|
- }
|
|
|
- if (json.TryGetProperty("prefix", out JsonElement prefixjson) && prefixjson.ValueKind.Equals(JsonValueKind.String))
|
|
|
- {
|
|
|
- prefix = prefixjson.GetString();
|
|
|
- }
|
|
|
- if (prefix != null && blobContainerName != null)
|
|
|
- {
|
|
|
- var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, prefix);
|
|
|
- string u ="";
|
|
|
- string[] uls = System.Web.HttpUtility.UrlDecode($"{prefixjson}", Encoding.UTF8).Split("/");
|
|
|
- if (uls != null)
|
|
|
- {
|
|
|
- u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
- }
|
|
|
- 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 });
|
|
|
- }
|
|
|
- else {
|
|
|
- return BadRequest();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 链接只读(读)
|
|
|
/// </summary>
|
|
@@ -288,6 +173,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ //学校已经分配给所有教师的空间大小GB。
|
|
|
long teach = 0;
|
|
|
request.TryGetProperty("scope", out JsonElement _scope);
|
|
|
request.TryGetProperty("containerName", out JsonElement containerName);
|
|
@@ -306,10 +192,10 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- request.TryGetProperty("cache", out JsonElement cache);
|
|
|
+ // request.TryGetProperty("cache", out JsonElement cache);
|
|
|
var name =containerName.GetString();
|
|
|
- if (cache.GetBoolean())
|
|
|
- {
|
|
|
+ //if (cache.GetBoolean())
|
|
|
+ //{
|
|
|
long blobsize = 0;
|
|
|
RedisValue value = default;
|
|
|
value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
|
|
@@ -355,18 +241,18 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
return Ok(new { size = size.Item1, catalog = size.Item2, teach });
|
|
|
}
|
|
|
- }
|
|
|
- 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, teach });
|
|
|
- }
|
|
|
+ // }
|
|
|
+ // 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, teach });
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
|
catch (Exception ex){
|
|
@@ -580,6 +466,61 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
return Ok(new { status = 200 });
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 删除prefix 不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。
|
|
|
+ ///
|
|
|
+ /// {"cntr":"","prefix":"res/test"}
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("delete-prefix")]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ public async Task<IActionResult> DeletePrefix(JsonElement json)
|
|
|
+ {
|
|
|
+ var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ string blobContainerName = null;
|
|
|
+ string prefix = null;
|
|
|
+ if (json.TryGetProperty("cntr", out JsonElement cntr) && cntr.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ var cntrs = cntr.GetString();
|
|
|
+
|
|
|
+ if (cntrs.Equals(id))
|
|
|
+ {
|
|
|
+ blobContainerName = id;
|
|
|
+ }
|
|
|
+ else if (cntrs.Equals(school))
|
|
|
+ {
|
|
|
+ blobContainerName = school;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest("只能删除本人管理的文件夹");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (json.TryGetProperty("prefix", out JsonElement prefixjson) && prefixjson.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ prefix = prefixjson.GetString();
|
|
|
+ }
|
|
|
+ if (prefix != null && blobContainerName != null)
|
|
|
+ {
|
|
|
+ var status = await _azureStorage.GetBlobServiceClient().DelectBlobs(blobContainerName, new List<string> { prefix });
|
|
|
+ string u = "";
|
|
|
+ string[] uls = System.Web.HttpUtility.UrlDecode($"{prefixjson}", Encoding.UTF8).Split("/");
|
|
|
+ if (uls != null)
|
|
|
+ {
|
|
|
+ u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
|
|
|
+ }
|
|
|
+ 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 });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
@@ -595,7 +536,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
{
|
|
|
var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
string blobContainerName = null;
|
|
|
- List<Uri> uris = 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))
|
|
@@ -617,7 +558,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
bool flag = true;
|
|
|
if (json.TryGetProperty("urls", out JsonElement urlsjson))
|
|
|
{
|
|
|
- uris = urlsjson.ToObject<List<Uri>>();
|
|
|
+ uris = urlsjson.ToObject<List<string>>();
|
|
|
uris.ForEach(x => {
|
|
|
(string, string) a = BlobUrlString(x.ToString());
|
|
|
string ContainerName = a.Item1;
|