55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using isnd.Entities;
|
|
using Microsoft.AspNetCore.Http;
|
|
using isn.abst;
|
|
|
|
namespace isnd.Controllers
|
|
{
|
|
|
|
public partial class PackagesController
|
|
{
|
|
// TODO [Authorize(Policy = IsndConstants.RequireValidApiKey)]
|
|
[HttpPut("~" + Constants.ApiVersionPrefix + ApiConfig.Package)]
|
|
public async Task<IActionResult> Put()
|
|
{
|
|
try
|
|
{
|
|
var clientVersionId = Request.Headers["X-NuGet-Client-Version"];
|
|
string apiKey = Request.Headers["X-NuGet-ApiKey"][0];
|
|
ViewData["versionId"] = typeof(PackagesController).Assembly.FullName;
|
|
var files = new List<string>();
|
|
ViewData["files"] = files;
|
|
|
|
var clearKey = protector.Unprotect(apiKey);
|
|
var dbApiKey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearKey);
|
|
if (dbApiKey == null)
|
|
{
|
|
logger.LogError("403 : no api-key");
|
|
return Unauthorized();
|
|
}
|
|
foreach (IFormFile file in Request.Form.Files)
|
|
{
|
|
var version = await packageManager.PutPackageAsync(file.OpenReadStream(), dbApiKey.UserId);
|
|
logger.LogInformation($"new package : {version.PackageId} {version.NugetLink}");
|
|
}
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var message = $"PUT exception : {ex.Message} ({ex.GetType().Name})";
|
|
logger.LogError(message);
|
|
logger.LogError("Stack Trace : " + ex.StackTrace);
|
|
return new ObjectResult(new { ViewData, message })
|
|
{ StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|