isn/src/isnd/Controllers/PackagesController.cs

60 lines
2 KiB
C#
Raw Normal View History

2021-06-22 23:03:38 +01:00
using System.ComponentModel.DataAnnotations;
2021-04-08 02:03:17 +01:00
using System.IO;
using System.Linq;
2021-04-08 03:08:20 +01:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
2021-04-08 02:03:17 +01:00
using Microsoft.AspNetCore.Mvc;
2021-06-21 23:38:05 +01:00
using Microsoft.EntityFrameworkCore;
2021-04-08 02:03:17 +01:00
using Microsoft.Extensions.Logging;
2021-05-02 15:22:46 +01:00
using Microsoft.Extensions.Options;
2021-06-22 01:25:28 +01:00
using NuGet.Versioning;
2021-08-15 19:09:01 +01:00
using isnd.Data;
using isnd.Entities;
2021-07-05 12:55:52 +01:00
using Unleash;
using isnd.Services;
2021-08-15 19:09:01 +01:00
using isnd.ViewModels;
using System.Threading.Tasks;
2021-08-23 03:21:08 +01:00
using isnd.Interfaces;
2022-04-09 19:53:26 +01:00
using isn.Abstract;
2021-04-08 02:03:17 +01:00
2021-08-15 19:09:01 +01:00
namespace isnd.Controllers
2021-04-08 02:03:17 +01:00
{
2021-05-09 03:06:23 +01:00
[AllowAnonymous]
2021-06-21 23:38:05 +01:00
public partial class PackagesController : Controller
2021-04-08 02:03:17 +01:00
{
2021-07-05 12:55:52 +01:00
const int maxTake = 100;
2021-09-08 01:55:00 +01:00
private readonly Resource[] _resources;
2021-07-12 03:23:11 +01:00
private readonly ILogger<PackagesController> _logger;
private readonly IDataProtector _protector;
2021-04-08 02:03:17 +01:00
2021-08-15 01:50:07 +01:00
private readonly IsndSettings _isndSettings;
2021-07-12 03:23:11 +01:00
readonly ApplicationDbContext _dbContext;
2021-08-23 03:21:08 +01:00
private readonly IPackageManager _packageManager;
2021-07-11 18:08:49 +01:00
private readonly IUnleash _unleashĈlient;
2021-09-05 15:44:47 +01:00
const string _pkgRootPrefix = "~/";
2021-05-02 15:22:46 +01:00
public PackagesController(
ILoggerFactory loggerFactory,
IDataProtectionProvider provider,
2021-08-15 01:50:07 +01:00
IOptions<IsndSettings> isndOptions,
2021-07-11 22:13:48 +01:00
IUnleash unleashĈlient,
2021-08-23 03:21:08 +01:00
ApplicationDbContext dbContext,
IPackageManager pm)
2021-04-08 02:03:17 +01:00
{
2021-07-12 03:23:11 +01:00
_logger = loggerFactory.CreateLogger<PackagesController>();
2021-08-15 01:50:07 +01:00
_isndSettings = isndOptions.Value;
_protector = provider.CreateProtector(_isndSettings.ProtectionTitle);
2021-07-12 03:23:11 +01:00
_dbContext = dbContext;
2021-08-23 03:21:08 +01:00
_packageManager = pm;
2021-07-11 22:13:48 +01:00
_unleashĈlient = unleashĈlient;
2021-09-08 01:55:00 +01:00
_resources = _packageManager.GetResources(_unleashĈlient).ToArray();
2021-04-08 02:03:17 +01:00
}
2021-09-02 23:37:28 +01:00
[HttpGet(_pkgRootPrefix + ApiConfig.Base)]
2021-06-22 23:03:38 +01:00
public IActionResult ApiIndex()
{
2022-04-17 14:48:18 +01:00
return Ok(new ApiIndexViewModel{ Version = PackageManager.BASE_API_LEVEL, Resources = _resources });
2021-06-22 23:03:38 +01:00
}
2021-04-08 02:03:17 +01:00
}
2022-04-17 14:10:20 +01:00
2021-04-08 02:03:17 +01:00
}