This commit is contained in:
Paul Schneider
2021-05-23 01:00:57 +01:00
parent be30ef3c25
commit 1266dd54db
5 changed files with 137 additions and 13 deletions

View File

@ -51,5 +51,9 @@ namespace nuget_host.Controllers
return Ok(ViewData);
}
public IActionResult Error()
{
return View();
}
}
}

View File

@ -87,19 +87,18 @@ namespace nuget_host.Controllers
string pkgpath = Path.Combine(pkgidpath, version.ToFullString());
string name = $"{pkgid}-{version}.nupkg";
string fullpath = Path.Combine(pkgpath, name);
Package package;
var destpkgiddir = new DirectoryInfo(pkgidpath);
if (destpkgiddir.Exists)
Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
if (package != null)
{
package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
if (package != null) if (package.OwnerId != apikey.UserId)
{
return new ForbidResult();
}
if (package.OwnerId != apikey.UserId)
{
return new ForbidResult();
}
}
else
else
{
destpkgiddir.Create();
package = new Package
{
Id = pkgid,
@ -108,6 +107,7 @@ namespace nuget_host.Controllers
};
dbContext.Packages.Add(package);
}
if (!destpkgiddir.Exists) destpkgiddir.Create();
var source = new FileInfo(initpath);
var dest = new FileInfo(fullpath);
@ -137,6 +137,7 @@ namespace nuget_host.Controllers
await dbContext.SaveChangesAsync();
logger.LogInformation($"new package : {entry.Name}");
}
break;
}
}
}
@ -146,7 +147,9 @@ namespace nuget_host.Controllers
}
catch (Exception ex)
{
return new ObjectResult(new { ViewData, ex.Message, ex.StackTrace })
logger.LogError(ex.Message);
logger.LogError("Stack Trace: "+ ex.StackTrace);
return new ObjectResult(new { ViewData, ex.Message})
{ StatusCode = 500 };
}
}

View File

@ -69,20 +69,22 @@ namespace nuget_host
}
else
{
app.UseExceptionHandler("/Home/Error");
// app.UseExceptionHandler("/Home/Error");
app.UseDeveloperExceptionPage();
dbContext.Database.Migrate();
}
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
template: "{controller=PackageVersion}/{action=Index}/{PackageId?}");
});
}
}

View File

@ -0,0 +1,4 @@
@{
ViewData["Title"] = "Error";
}