using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NuGet.Versioning; using isnd.Data; using isnd.Entities; using Unleash; using isnd.Services; using isnd.ViewModels; using System.Threading.Tasks; using isnd.Interfaces; using isn.Abstract; namespace isnd.Controllers { [AllowAnonymous] public partial class PackagesController : Controller { const int maxTake = 100; const string defaultSemVer = "2.0.0"; private readonly Resource[] _resources; private readonly ILogger _logger; private readonly IDataProtector _protector; private readonly IsndSettings _isndSettings; readonly ApplicationDbContext _dbContext; private readonly IPackageManager _packageManager; private readonly IUnleash _unleashĈlient; const string _pkgRootPrefix = "~/"; public PackagesController( ILoggerFactory loggerFactory, IDataProtectionProvider provider, IOptions isndOptions, IUnleash unleashĈlient, ApplicationDbContext dbContext, IPackageManager pm) { _logger = loggerFactory.CreateLogger(); _isndSettings = isndOptions.Value; _protector = provider.CreateProtector(_isndSettings.ProtectionTitle); _dbContext = dbContext; _packageManager = pm; _unleashĈlient = unleashĈlient; _resources = _packageManager.GetResources(_unleashĈlient).ToArray(); } [HttpGet(_pkgRootPrefix + ApiConfig.Base)] public IActionResult ApiIndex() { return Ok(new ApiIndexViewModel{ Version = "3.0.0", Resources = _resources }); } } }