using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; using TEAMModelOS.Filter; using TEAMModelOS.SDK.DI; namespace TEAMModelAPI.Controllers { [ApiController] [Route("weather")] public class WeatherForecastController : ControllerBase { private readonly DingDing _dingDing; private readonly AzureStorageFactory _azureStorage; private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; private readonly ILogger _logger; public WeatherForecastController(DingDing dingDing, AzureStorageFactory azureStorage, ILogger logger) { _dingDing = dingDing; _azureStorage = azureStorage; _logger = logger; } [HttpGet] [ApiToken(Auth ="5")] public IEnumerable Get() { var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray(); } [HttpGet("aaaa")] [ApiToken(Auth = "1")] public IEnumerable Getaaaa() { var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray(); } /// /// 删除prefix 不管是内容 模块还是其他试题试卷 评测 问卷投票等都在使用。 /// /// {"cntr":"","prefix":"res/test"} /// /// /// [HttpPost("delete-prefix")] public async Task DeletePrefix(JsonElement json) { string blobContainerName = null; string prefix = null; if (json.TryGetProperty("cntr", out JsonElement cntr) && cntr.ValueKind.Equals(JsonValueKind.String)) { blobContainerName = $"{cntr}"; } if (json.TryGetProperty("prefix", out JsonElement prefixjson) && prefixjson.ValueKind.Equals(JsonValueKind.String)) { prefix = prefixjson.GetString(); } if (prefix != null && blobContainerName != null) { var list = await _azureStorage.GetBlobContainerClient($"{cntr}").List(prefix); var status = await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, blobContainerName, new List { 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]; } return Ok(new { list }); } else { return BadRequest(); } } } }