From 55549818af9984c49729266c6cc825fc5be848b9 Mon Sep 17 00:00:00 2001 From: XShine555 Date: Mon, 1 Jun 2026 00:24:41 +0200 Subject: [PATCH] Cleanup --- .../Configuration/PlayListConfiguration.cs | 3 +-- .../Configuration/TrackConfiguration.cs | 3 +-- .../UploadIntentConfiguration.cs | 20 +++++-------------- ...uestPlayListPictureUploadCommandHandler.cs | 2 +- .../RequestTrackUploadUrlsCommandHandler.cs | 4 ++-- Domain/Entities/UploadIntent.cs | 2 -- .../Jobs/TemporalUploadsCleanupJob.cs | 10 +++++----- .../Jobs/UploadIntentExpirationJob.cs | 2 -- .../20260530020027_InitialCreate.Designer.cs | 5 ++--- .../20260530020027_InitialCreate.cs | 11 ++++------ .../Migrations/DatabaseModelSnapshot.cs | 2 +- .../Services/ServicesDependencyInjection.cs | 2 -- 12 files changed, 22 insertions(+), 44 deletions(-) diff --git a/Application/Configuration/PlayListConfiguration.cs b/Application/Configuration/PlayListConfiguration.cs index 8290d26..c2fc6cc 100644 --- a/Application/Configuration/PlayListConfiguration.cs +++ b/Application/Configuration/PlayListConfiguration.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Musify.Application.Configuration { @@ -69,7 +69,6 @@ namespace Musify.Application.Configuration public string BuildLargePicturePath(string pictureName) => CombineKey(ParentFolders, LargePicturesFolder, pictureName); - // Temp path used in Phase 2 for pre-signed upload keys (moved to final on consumption) public string BuildTempPicturePath(string tempRootPrefix, long userId, string objectName) => CombineKey(tempRootPrefix, userId.ToString(), ParentFolders, objectName); diff --git a/Application/Configuration/TrackConfiguration.cs b/Application/Configuration/TrackConfiguration.cs index 4740944..ec3189f 100644 --- a/Application/Configuration/TrackConfiguration.cs +++ b/Application/Configuration/TrackConfiguration.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace Musify.Application.Configuration { @@ -85,7 +85,6 @@ namespace Musify.Application.Configuration public string BuildProcessedAudioPath(string audioName) => CombineKey(ProcessedAudiosPath, audioName); - // Temp paths used in Phase 2 for pre-signed upload keys (moved to final on consumption) public string BuildTempPicturePath(string tempRootPrefix, long userId, string objectName) => CombineKey(tempRootPrefix, userId.ToString(), ParentFolder, objectName); diff --git a/Application/Configuration/UploadIntentConfiguration.cs b/Application/Configuration/UploadIntentConfiguration.cs index d25741f..b18d32d 100644 --- a/Application/Configuration/UploadIntentConfiguration.cs +++ b/Application/Configuration/UploadIntentConfiguration.cs @@ -6,47 +6,37 @@ namespace Musify.Application.Configuration { public const string SectionName = "UploadIntent"; - // Pre-signed URL TTL in seconds [Range(10, 3600)] public int UploadUrlExpiresInSeconds { get; set; } = 120; - // Max concurrent Issued intents per user [Range(1, 100)] public int MaxActiveUploadIntentsPerUser { get; set; } = 5; - // Max total bytes across all Issued intents for a user (default 200MB) [Range(1, long.MaxValue)] public long MaxActiveUploadBytesPerUser { get; set; } = 200L * 1024 * 1024; - // Max size validated via HEAD before consuming an intent (default 100MB) [Range(1, long.MaxValue)] public long MaxUploadBytes { get; set; } = 100L * 1024 * 1024; - // Conservative fallback size used when ExpectedSizeBytes is not provided [Range(1, long.MaxValue)] - public long DefaultExpectedPictureSizeBytes { get; set; } = 10L * 1024 * 1024; // 10MB + public long DefaultExpectedPictureSizeBytes { get; set; } = 10L * 1024 * 1024; [Range(1, long.MaxValue)] - public long DefaultExpectedAudioSizeBytes { get; set; } = 100L * 1024 * 1024; // 100MB + public long DefaultExpectedAudioSizeBytes { get; set; } = 100L * 1024 * 1024; - // How often the expiration job runs [Range(30, 86400)] public int ExpirationJobIntervalSeconds { get; set; } = 300; - // How many days to retain Expired intents before deleting the DB row [Range(0, 365)] public int ExpiredIntentsRetentionDays { get; set; } = 7; - // Root S3 prefix for temporary uploads (Phase 2) [Required, MinLength(1)] - public string TempRootPrefix { get; set; } = "temp"; + public string TemporalRootPrefix { get; set; } = "temporal"; - // How many days to retain orphaned temp objects in S3 before the cleanup job deletes them [Range(1, 30)] - public int TempUploadsRetentionDays { get; set; } = 3; + public int TemporalUploadsRetentionDays { get; set; } = 3; - // How often the temp-upload cleanup job runs [Range(60, 86400)] - public int TempCleanupJobIntervalSeconds { get; set; } = 3600; + public int TemporalCleanUpJobIntervalSeconds { get; set; } = 3600; } } diff --git a/Application/PlayLists/Handlers/RequestPlayListPictureUploadCommandHandler.cs b/Application/PlayLists/Handlers/RequestPlayListPictureUploadCommandHandler.cs index 4c0d25d..ff0ef0d 100644 --- a/Application/PlayLists/Handlers/RequestPlayListPictureUploadCommandHandler.cs +++ b/Application/PlayLists/Handlers/RequestPlayListPictureUploadCommandHandler.cs @@ -39,7 +39,7 @@ namespace Musify.Application.PlayLists.Handlers var objectName = $"{Guid.NewGuid() }.{request.FileType.TrimStart('.').ToLowerInvariant() }"; var tempKey = playListConfiguration.Routes.BuildTempPicturePath( - uploadIntentConfiguration.TempRootPrefix, request.UserId, objectName); + uploadIntentConfiguration.TemporalRootPrefix, request.UserId, objectName); try { diff --git a/Application/Tracks/Handlers/RequestTrackUploadUrlsCommandHandler.cs b/Application/Tracks/Handlers/RequestTrackUploadUrlsCommandHandler.cs index f20c9b3..c651282 100644 --- a/Application/Tracks/Handlers/RequestTrackUploadUrlsCommandHandler.cs +++ b/Application/Tracks/Handlers/RequestTrackUploadUrlsCommandHandler.cs @@ -42,9 +42,9 @@ namespace Musify.Application.Tracks.Handlers var audioObjectName = $"{Guid.NewGuid()}.{request.AudioFileType.TrimStart('.').ToLowerInvariant()}"; var tempPictureKey = trackConfiguration.Routes.BuildTempPicturePath( - uploadIntentConfiguration.TempRootPrefix, request.UserId, pictureObjectName); + uploadIntentConfiguration.TemporalRootPrefix, request.UserId, pictureObjectName); var tempAudioKey = trackConfiguration.Routes.BuildTempAudioPath( - uploadIntentConfiguration.TempRootPrefix, request.UserId, audioObjectName); + uploadIntentConfiguration.TemporalRootPrefix, request.UserId, audioObjectName); try { diff --git a/Domain/Entities/UploadIntent.cs b/Domain/Entities/UploadIntent.cs index d4f772b..4f1d15e 100644 --- a/Domain/Entities/UploadIntent.cs +++ b/Domain/Entities/UploadIntent.cs @@ -17,11 +17,9 @@ namespace Musify.Domain.Entities [Required, MaxLength(128)] public required string Bucket { get; set; } - // Full S3 key (including prefix and object name) [Required, MaxLength(512)] public required string Key { get; set; } - // Just the filename portion stored in Track/PlayList entities (e.g. "{guid}.webp") [Required, MaxLength(128)] public required string ObjectName { get; set; } diff --git a/Infrastructure/Jobs/TemporalUploadsCleanupJob.cs b/Infrastructure/Jobs/TemporalUploadsCleanupJob.cs index d11924a..ac20eb7 100644 --- a/Infrastructure/Jobs/TemporalUploadsCleanupJob.cs +++ b/Infrastructure/Jobs/TemporalUploadsCleanupJob.cs @@ -16,8 +16,8 @@ namespace Musify.Infrastructure.Jobs protected override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation("TemporalUploadsCleanUpJob started (interval: {Interval}s, prefix: {Prefix})", - uploadIntentConfiguration.TempCleanupJobIntervalSeconds, - uploadIntentConfiguration.TempRootPrefix); + uploadIntentConfiguration.TemporalCleanUpJobIntervalSeconds, + uploadIntentConfiguration.TemporalRootPrefix); while (!stoppingToken.IsCancellationRequested) { @@ -30,7 +30,7 @@ namespace Musify.Infrastructure.Jobs logger.LogError(exception, "Error in TemporalUploadsCleanUpJob"); } - await Task.Delay(TimeSpan.FromSeconds(uploadIntentConfiguration.TempCleanupJobIntervalSeconds), stoppingToken); + await Task.Delay(TimeSpan.FromSeconds(uploadIntentConfiguration.TemporalCleanUpJobIntervalSeconds), stoppingToken); } } @@ -39,13 +39,13 @@ namespace Musify.Infrastructure.Jobs await using var scope = scopeFactory.CreateAsyncScope(); var storageService = scope.ServiceProvider.GetRequiredService(); - var cutOff = DateTime.UtcNow.AddDays(-uploadIntentConfiguration.TempUploadsRetentionDays); + var cutOff = DateTime.UtcNow.AddDays(-uploadIntentConfiguration.TemporalUploadsRetentionDays); var deleted = 0; var errors = 0; await foreach (var (key, lastModified) in storageService.ListObjectsAsync( storageConfiguration.Bucket, - uploadIntentConfiguration.TempRootPrefix, + uploadIntentConfiguration.TemporalRootPrefix, cancellationToken)) { if (lastModified >= cutOff) diff --git a/Infrastructure/Jobs/UploadIntentExpirationJob.cs b/Infrastructure/Jobs/UploadIntentExpirationJob.cs index 2f21219..6e0cc78 100644 --- a/Infrastructure/Jobs/UploadIntentExpirationJob.cs +++ b/Infrastructure/Jobs/UploadIntentExpirationJob.cs @@ -40,7 +40,6 @@ namespace Musify.Infrastructure.Jobs var now = DateTime.UtcNow; - // Mark expired intents var expiredIntents = await database.UploadIntents .Where(i => i.Status == UploadIntentStatus.Issued && i.ExpiresAt < now) .ToListAsync(cancellationToken); @@ -54,7 +53,6 @@ namespace Musify.Infrastructure.Jobs logger.LogInformation("Marked {Count} upload intents as Expired", expiredIntents.Count); } - // Delete old Expired intents past retention window if (uploadIntentConfiguration.ExpiredIntentsRetentionDays >= 0) { var retentionCutoff = now.AddDays(-uploadIntentConfiguration.ExpiredIntentsRetentionDays); diff --git a/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.Designer.cs b/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.Designer.cs index 1b193c6..f8d67e5 100644 --- a/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.Designer.cs +++ b/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.Designer.cs @@ -1,4 +1,4 @@ -// + using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -15,8 +15,7 @@ namespace Musify.Infrastructure.Persistence.Migrations [Migration("20260530020027_InitialCreate")] partial class InitialCreate { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) + protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder diff --git a/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.cs b/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.cs index 839e7d6..eb0d10c 100644 --- a/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.cs +++ b/Infrastructure/Persistence/Migrations/20260530020027_InitialCreate.cs @@ -1,15 +1,13 @@ -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Musify.Infrastructure.Persistence.Migrations { - /// - public partial class InitialCreate : Migration + public partial class InitialCreate : Migration { - /// - protected override void Up(MigrationBuilder migrationBuilder) + protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "InboxState", @@ -321,8 +319,7 @@ namespace Musify.Infrastructure.Persistence.Migrations column: "UserId"); } - /// - protected override void Down(MigrationBuilder migrationBuilder) + protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "OutboxMessage"); diff --git a/Infrastructure/Persistence/Migrations/DatabaseModelSnapshot.cs b/Infrastructure/Persistence/Migrations/DatabaseModelSnapshot.cs index 3293df5..09f5aa4 100644 --- a/Infrastructure/Persistence/Migrations/DatabaseModelSnapshot.cs +++ b/Infrastructure/Persistence/Migrations/DatabaseModelSnapshot.cs @@ -1,4 +1,4 @@ -// + using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; diff --git a/Infrastructure/Services/ServicesDependencyInjection.cs b/Infrastructure/Services/ServicesDependencyInjection.cs index 3597e68..45df273 100644 --- a/Infrastructure/Services/ServicesDependencyInjection.cs +++ b/Infrastructure/Services/ServicesDependencyInjection.cs @@ -44,7 +44,6 @@ namespace Musify.Infrastructure.Services return serviceDescriptors; } - // Called by both the web API host and the worker public static IServiceCollection AddUploadIntentConfiguration(this IServiceCollection serviceDescriptors, IConfiguration configuration) { serviceDescriptors @@ -60,7 +59,6 @@ namespace Musify.Infrastructure.Services return serviceDescriptors; } - // Called only by the worker host (registers background jobs) public static IServiceCollection AddUploadIntentJobs(this IServiceCollection serviceDescriptors, IConfiguration configuration) { serviceDescriptors.AddUploadIntentConfiguration(configuration);