mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Implements file hashing media library scan job
This commit is contained in:
1 parent
66998055f0
commit
03a000e1e4
63 files changed
+2009
-287
No files matched your search
+1
-1
@@ -36,7 +36,7 @@ public class LibraryScanResultEntity : IStorageEntity
|
||||
/// <summary>
|
||||
/// Gets the hash calculated for the media library scan file.
|
||||
/// </summary>
|
||||
public required string ContentHash { get; init; }
|
||||
public required ulong ContentHash { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the media library scan file.
|
||||
|
||||
-1
@@ -4,7 +4,6 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for media library scan results.
|
||||
/// </summary>
|
||||
public interface ILibraryScanResultRepository : IRepository<LibraryScanResultEntity>,
|
||||
IInsertRepositoryAction<LibraryScanResultEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all media library scan results that belong to the last scan of a library identified by <paramref name="libraryId"/>, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The unique identifier of the library for which to get the results of the last scans.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a path mapped dictionary of <see cref="LibraryScanResultEntity"/>, or an error.</returns>
|
||||
Task<ErrorOr<Dictionary<string, LibraryScanResultEntity>>> GetPathMappedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Models.MediaLibraryScanJobPayloads;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an item for the payload of the file hashing media library scan job.
|
||||
/// </summary>
|
||||
/// <param name="File">The file to whom <paramref name="FileHash"/> belongs.</param>
|
||||
/// <param name="FileHash">The hash of <paramref name="File"/>.</param>
|
||||
[DebuggerDisplay("File: {File}; FileHash: {FileHash}")]
|
||||
public record ChangedFileSystemFile(FileInfo File, ulong FileHash);
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Models.MediaLibraryScanJobPayloads;
|
||||
|
||||
/// <summary>
|
||||
/// Generic file system node.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public class FileSystemTreeNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the full path of the file or directory.
|
||||
/// </summary>
|
||||
public string Path { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the file or directory.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the item, indicating whether it is a file, directory, or drive.
|
||||
/// </summary>
|
||||
public FileSystemItemType ItemType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of child nodes.
|
||||
/// </summary>
|
||||
public List<FileSystemTreeNode> Children { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Infrastructure.Models.MediaLibraryScanJobPayloads;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Security;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service for hashing files by sampling chunks from them.
|
||||
/// </summary>
|
||||
public interface IFileHashService
|
||||
{
|
||||
/// <summary>
|
||||
/// Hashes <paramref name="files"/> by sampling chunks from them.
|
||||
/// </summary>
|
||||
/// <param name="files">The collection of files to hash.</param>
|
||||
/// <param name="previousScanResults">Lookup dictionary of a previous media library scan, used to determine if a file changed or not.</param>
|
||||
/// <param name="callback">Callback to invoke during processing of elements.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A collection of files that changed since last library scan, along with their hashes.</returns>
|
||||
List<ChangedFileSystemFile> HashFiles(
|
||||
List<FileInfo> files,
|
||||
Dictionary<string, LibraryScanResultEntity> previousScanResults,
|
||||
Func<Task> callback,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ namespace Lumina.Application.Common.Infrastructure.Security;
|
||||
/// <summary>
|
||||
/// Interface for the service for hashing passwords.
|
||||
/// </summary>
|
||||
public interface IHashService
|
||||
public interface IPasswordHashService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a hash from a string.
|
||||
+2
-2
@@ -25,7 +25,7 @@ namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApp
|
||||
public class SetupApplicationCommandHandler : IRequestHandler<SetupApplicationCommand, ErrorOr<RegistrationResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IHashService _hashService;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
private readonly ITotpTokenGenerator _totpTokenGenerator;
|
||||
private readonly IQRCodeGenerator _qRCodeGenerator;
|
||||
@@ -44,7 +44,7 @@ public class SetupApplicationCommandHandler : IRequestHandler<SetupApplicationCo
|
||||
/// <param name="dataSeedService">Injected service for the initial persistence medium data seed.</param>
|
||||
public SetupApplicationCommandHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
IHashService hashService,
|
||||
IPasswordHashService hashService,
|
||||
ICryptographyService cryptographyService,
|
||||
ITotpTokenGenerator totpTokenGenerator,
|
||||
IQRCodeGenerator qRCodeGenerator,
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Commands.Change
|
||||
public class ChangePasswordCommandHandler : IRequestHandler<ChangePasswordCommand, ErrorOr<ChangePasswordResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IHashService _hashService;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChangePasswordCommandHandler"/> class.
|
||||
@@ -29,7 +29,7 @@ public class ChangePasswordCommandHandler : IRequestHandler<ChangePasswordComman
|
||||
/// <param name="hashService">Injected service for password hashing functionality.</param>
|
||||
public ChangePasswordCommandHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
IHashService hashService)
|
||||
IPasswordHashService hashService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_hashService = hashService;
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Commands.Recove
|
||||
public class RecoverPasswordCommandHandler : IRequestHandler<RecoverPasswordCommand, ErrorOr<RecoverPasswordResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IHashService _hashService;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
private readonly ITotpTokenGenerator _totpTokenGenerator;
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class RecoverPasswordCommandHandler : IRequestHandler<RecoverPasswordComm
|
||||
/// <param name="cryptographyService">Injected service for cryptographic functionality.</param>
|
||||
public RecoverPasswordCommandHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
IHashService hashService,
|
||||
IPasswordHashService hashService,
|
||||
ITotpTokenGenerator totpTokenGenerator,
|
||||
ICryptographyService cryptographyService)
|
||||
{
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Commands.Regist
|
||||
public class RegisterUserCommandHandler : IRequestHandler<RegisterUserCommand, ErrorOr<RegistrationResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IHashService _hashService;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
private readonly ITotpTokenGenerator _totpTokenGenerator;
|
||||
private readonly IQRCodeGenerator _qRCodeGenerator;
|
||||
@@ -39,7 +39,7 @@ public class RegisterUserCommandHandler : IRequestHandler<RegisterUserCommand, E
|
||||
/// <param name="dateTimeProvider">Injected service for time related concerns.</param>
|
||||
public RegisterUserCommandHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
IHashService hashService,
|
||||
IPasswordHashService hashService,
|
||||
ICryptographyService cryptographyService,
|
||||
ITotpTokenGenerator totpTokenGenerator,
|
||||
IQRCodeGenerator qRCodeGenerator,
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUs
|
||||
public class LoginUserQueryHandler : IRequestHandler<LoginUserQuery, ErrorOr<LoginResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IHashService _hashService;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
private readonly IJwtTokenGenerator _jwtTokenGenerator;
|
||||
private readonly ITotpTokenGenerator _totpTokenGenerator;
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
@@ -39,7 +39,7 @@ public class LoginUserQueryHandler : IRequestHandler<LoginUserQuery, ErrorOr<Log
|
||||
/// <param name="dateTimeProvider">Injected service for time related concerns.</param>
|
||||
public LoginUserQueryHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
IHashService hashService,
|
||||
IPasswordHashService hashService,
|
||||
IJwtTokenGenerator jwtTokenGenerator,
|
||||
ITotpTokenGenerator totpTokenGenerator,
|
||||
ICryptographyService cryptographyService,
|
||||
|
||||
Reference in new issue
Block a user