WeatherForecastController.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.Json;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.Filter;
  10. using TEAMModelOS.SDK.DI;
  11. namespace TEAMModelAPI.Controllers
  12. {
  13. [ApiController]
  14. [Route("weather")]
  15. public class WeatherForecastController : ControllerBase
  16. {
  17. private readonly DingDing _dingDing;
  18. private readonly AzureStorageFactory _azureStorage;
  19. private static readonly string[] Summaries = new[]
  20. {
  21. "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
  22. };
  23. private readonly ILogger<WeatherForecastController> _logger;
  24. public WeatherForecastController(DingDing dingDing, AzureStorageFactory azureStorage, ILogger<WeatherForecastController> logger)
  25. {
  26. _dingDing = dingDing;
  27. _azureStorage = azureStorage;
  28. _logger = logger;
  29. }
  30. [HttpGet]
  31. [ApiToken]
  32. public IEnumerable<WeatherForecast> Get()
  33. {
  34. var rng = new Random();
  35. return Enumerable.Range(1, 5).Select(index => new WeatherForecast
  36. {
  37. Date = DateTime.Now.AddDays(index),
  38. TemperatureC = rng.Next(-20, 55),
  39. Summary = Summaries[rng.Next(Summaries.Length)]
  40. })
  41. .ToArray();
  42. }
  43. /// <summary>
  44. /// 删除prefix 不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。
  45. ///
  46. /// {"cntr":"","prefix":"res/test"}
  47. /// </summary>
  48. /// <param name="request"></param>
  49. /// <returns></returns>
  50. [HttpPost("delete-prefix")]
  51. public async Task<IActionResult> DeletePrefix(JsonElement json)
  52. {
  53. string blobContainerName = null;
  54. string prefix = null;
  55. if (json.TryGetProperty("cntr", out JsonElement cntr) && cntr.ValueKind.Equals(JsonValueKind.String))
  56. {
  57. blobContainerName = $"{cntr}";
  58. }
  59. if (json.TryGetProperty("prefix", out JsonElement prefixjson) && prefixjson.ValueKind.Equals(JsonValueKind.String))
  60. {
  61. prefix = prefixjson.GetString();
  62. }
  63. if (prefix != null && blobContainerName != null)
  64. {
  65. var list = await _azureStorage.GetBlobContainerClient($"{cntr}").List(prefix);
  66. var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobContainerName, new List<string> { prefix });
  67. string u = "";
  68. string[] uls = System.Web.HttpUtility.UrlDecode($"{prefixjson}", Encoding.UTF8).Split("/");
  69. if (uls != null)
  70. {
  71. u = !string.IsNullOrEmpty(uls[0]) ? uls[0] : uls[1];
  72. }
  73. return Ok(new { list });
  74. }
  75. else
  76. {
  77. return BadRequest();
  78. }
  79. }
  80. }
  81. }