|
@@ -68,66 +68,75 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
/// <returns></returns>
|
|
|
public static async Task FixBlobContent(CosmosClient client, DingDing _dingDing, AzureStorageFactory _azureStorage, JsonElement data)
|
|
|
{
|
|
|
-
|
|
|
+ if (data.TryGetProperty("doPrivate", out JsonElement _doPrivate)&& $"{_doPrivate}".Equals("yes",StringComparison.OrdinalIgnoreCase)) {
|
|
|
+ foreach (var cnt in _azureStorage.GetBlobServiceClient().GetBlobContainers())
|
|
|
+ {
|
|
|
+ if (cnt.Name.Length == 10 && int.TryParse(cnt.Name, out _))
|
|
|
+ {
|
|
|
+ await doFixBlob(client, _azureStorage, cnt.Name, "private");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (data.TryGetProperty("name", out JsonElement _name))
|
|
|
{
|
|
|
List<string> names = _name.ToObject<List<string>>();
|
|
|
foreach (string name in names)
|
|
|
{
|
|
|
- List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
|
|
|
- var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
|
|
|
- string scope = "private";
|
|
|
- if (data.TryGetProperty("scope", out JsonElement _scope))
|
|
|
- {
|
|
|
- scope = $"{_scope}";
|
|
|
- }
|
|
|
- var tb = "Teacher";
|
|
|
- if (scope != "private")
|
|
|
- {
|
|
|
- tb = "School";
|
|
|
- }
|
|
|
- List<string> ids = new List<string>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", tb).GetItemQueryIterator<Bloblog>(queryDefinition: new QueryDefinition("select c.id from c "), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
- {
|
|
|
- ids.Add(item.id);
|
|
|
- }
|
|
|
- await client.GetContainer("TEAMModelOS", tb).DeleteItemsStreamAsync(ids, $"Bloblog-{name}");
|
|
|
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- foreach (var prefix in prefixs)
|
|
|
+ await doFixBlob(client, _azureStorage, name, "school");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private static async Task doFixBlob(CosmosClient client, AzureStorageFactory _azureStorage,string name,string scope) {
|
|
|
+ List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
|
|
|
+ var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
|
|
|
+ var tb = "Teacher";
|
|
|
+ if (scope != "private")
|
|
|
+ {
|
|
|
+ tb = "School";
|
|
|
+ }
|
|
|
+ List<string> ids = new List<string>();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", tb).GetItemQueryIterator<Bloblog>(queryDefinition: new QueryDefinition("select c.id from c "), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Bloblog-{name}") }))
|
|
|
+ {
|
|
|
+ ids.Add(item.id);
|
|
|
+ }
|
|
|
+ await client.GetContainer("TEAMModelOS", tb).DeleteItemsStreamAsync(ids, $"Bloblog-{name}");
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ foreach (var prefix in prefixs)
|
|
|
+ {
|
|
|
+ if (prefix.Equals("res"))
|
|
|
+ {
|
|
|
+ List<string> itemres = await ContainerClient.List(prefix);
|
|
|
+ if (itemres.IsNotEmpty())
|
|
|
{
|
|
|
- if (prefix.Equals("res"))
|
|
|
+ HashSet<string> set = new HashSet<string>();
|
|
|
+ itemres.ForEach(x =>
|
|
|
+ {
|
|
|
+ var uri = x.Split("/");
|
|
|
+ set.Add($"res/{uri[1]}");
|
|
|
+ });
|
|
|
+ foreach (var item in set)
|
|
|
{
|
|
|
- List<string> itemres = await ContainerClient.List(prefix);
|
|
|
- if (itemres.IsNotEmpty()) {
|
|
|
- HashSet<string> set = new HashSet<string>();
|
|
|
- itemres.ForEach(x =>
|
|
|
- {
|
|
|
- var uri = x.Split("/");
|
|
|
- set.Add($"res/{uri[1]}");
|
|
|
- });
|
|
|
- foreach (var item in set)
|
|
|
- {
|
|
|
- var urlsSize = await ContainerClient.GetBlobsSize(item);
|
|
|
- var url = item;
|
|
|
- if (!item.EndsWith(".hte", StringComparison.OrdinalIgnoreCase) && !item.EndsWith(".HTEX", StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- url += ".HTEX";
|
|
|
- }
|
|
|
- Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = url, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
|
|
|
- await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
|
|
|
- }
|
|
|
+ var urlsSize = await ContainerClient.GetBlobsSize(item);
|
|
|
+ var url = item;
|
|
|
+ if (!item.EndsWith(".hte", StringComparison.OrdinalIgnoreCase) && !item.EndsWith(".HTEX", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ url += ".HTEX";
|
|
|
}
|
|
|
+ Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = url, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
|
|
|
+ await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
|
|
|
}
|
|
|
- else {
|
|
|
- List<string> items = await ContainerClient.List(prefix);
|
|
|
- if (items.IsNotEmpty()) {
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- var urlsSize = await ContainerClient.GetBlobsSize(item);
|
|
|
- Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = item, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
|
|
|
- await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<string> items = await ContainerClient.List(prefix);
|
|
|
+ if (items.IsNotEmpty())
|
|
|
+ {
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ var urlsSize = await ContainerClient.GetBlobsSize(item);
|
|
|
+ Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, url = item, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
|
|
|
+ await client.GetContainer("TEAMModelOS", tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
|
|
|
}
|
|
|
}
|
|
|
}
|