Skip to content

Commit

Permalink
fixes dependency cycle error
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed Aug 3, 2024
1 parent 77aeadd commit 91e00a1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
7 changes: 2 additions & 5 deletions src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
"Debug": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore.Hosting": "Warning",
"Microsoft.AspNetCore.Infrastructure": "Warning",
"Microsoft.AspNetCore.Routing": "Warning",
"Microsoft.AspNetCore.Mvc": "Warning"
"Microsoft.AspNetCore.*": "Warning"
}
},
"Console": {
"LogLevel": {
"Microsoft.Hosting.Lifetime": "Debug",
"Microsoft.AspNetCore.*": "Debug",
"Default": "Debug"
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/controllers/PackagePublishController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ namespace core.controllers;
using Sentry;
using vein.project.shards;

[Route("@/publish"), ApiKeyAuth]
[ApiController]

[ApiController, ApiKeyAuth]
public class PackagePublishController(
IPackageIndexingService indexer,
ILogger<PackagePublishController> logger,
IUserService userService,
IHub sentryHub)
: Controller
{
{
[Route("@/publish")]
public async Task Upload(CancellationToken cancellationToken)
{
var task = sentryHub.GetSpan()?.StartChild($"{nameof(PackagePublishController)}::{nameof(Upload)}");
Expand All @@ -27,9 +28,7 @@ public async Task Upload(CancellationToken cancellationToken)
return;
}

var me = await userService.GetMeAsync(cancellationToken);

logger.LogInformation($"indexer.IndexAsync");
var me = await userService.GetMeAsync(cancellationToken);
var result = await indexer.IndexAsync(uploadStream, me, cancellationToken);

switch (result.Item1)
Expand Down
23 changes: 13 additions & 10 deletions src/logic/services/PackageIndexingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,21 @@ public class PackageIndexingService(
var iconStream = default(Stream);

try
{
logger.LogInformation($"Shard.OpenAsync");
var packageReader = await Shard.OpenAsync(packageStream, true, token);
logger.LogInformation($"packageReader.GetManifestAsync");
{
var packageReader = await Shard.OpenAsync(packageStream, true, token);
var manifest = await packageReader.GetManifestAsync(token);
logger.LogInformation($"userService.UserAllowedPublishWorkloads");

if (manifest.IsWorkload && !await userService.UserAllowedPublishWorkloads())
return (PackageIndexingResult.InvalidPackage, "You cannot publish workload package!");
return (PackageIndexingResult.InvalidPackage, "You cannot publish workload package!");

package = mapper.Map<Package>(manifest);
package.Published = _time.UtcNow;
package.Listed = true;

if (package.HasEmbbededReadme)
readmeStream = await packageReader.GetReadmeAsync(token);
if (package.HasEmbeddedIcon)
iconStream = await packageReader.GetIconAsync(token);
logger.LogInformation($"PackageValidator.ValidateExistAsync");
await PackageValidator.ValidateExistAsync(packageReader);
}
catch (ShardPackageCorruptedException e) when (e.InnerException is PackageValidatorException validateError)
Expand All @@ -56,6 +53,13 @@ public class PackageIndexingService(
_logger.LogError(e.Message);

return (PackageIndexingResult.InvalidPackage, validateError.Message);
}
catch (PackageValidatorException e)
{
_logger.LogError(e, "Validation failed");
_logger.LogError(e.Message);

return (PackageIndexingResult.InvalidPackage, e.Message);
}
catch (Exception e)
{
Expand All @@ -64,7 +68,6 @@ public class PackageIndexingService(
return (PackageIndexingResult.InternalError, "unknown error");
}


// The package is well-formed. Ensure this is a new package.
if (await _packages.ExistsAsync(package.Name, package.Version, token))
{
Expand Down
6 changes: 4 additions & 2 deletions src/logic/services/searchs/FirestoreSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class OwnerIsNotMatchException : Exception

}

public class FireOperationBuilder(FirestoreDb firestore, IMapper mapper, IUserService userService)
public class FireOperationBuilder(FirestoreDb firestore, IMapper mapper, IServiceProvider serviceProvider)
{
public CollectionReference PackagesReference { get; private set; } = firestore.Collection("packages");
public CollectionReference PackagesLinks { get; private set; } = firestore.Collection("packages-links");
Expand Down Expand Up @@ -76,7 +76,9 @@ public async Task<WriteResult> AddPackage(Package package, UserRecord owner)

var verified = false;
var isServiced = false;


await using var scope = serviceProvider.CreateAsyncScope();
var userService = scope.ServiceProvider.GetRequiredService<IUserService>();

if (!snapshot.Exists)
{
Expand Down

0 comments on commit 91e00a1

Please sign in to comment.