mirror of
https://github.com/sphildreth/roadie
synced 2025-02-16 13:08:25 +00:00
Better handling of unicode named releases.
This commit is contained in:
parent
2df0d09326
commit
022920b3f3
6 changed files with 75 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Roadie.Library.Configuration;
|
||||
using Roadie.Library.Extensions;
|
||||
using Roadie.Library.Utility;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
@ -146,6 +147,7 @@ namespace Roadie.Library.Tests
|
|||
[InlineData("Sinatra's Swingin' Session!!! And More", "01/01/1981", @"I\IR\Iron Maiden [9909]", @"I\IR\Iron Maiden [9909]\[1981] Sinatras Swingin Session And More")]
|
||||
[InlineData("01234567890123456789012345678901234567890123456789", "01/01/1974", @"I\IR\Iron Maiden [9909]", @"I\IR\Iron Maiden [9909]\[1974] 01234567890123456789012345678901234567890123456789")]
|
||||
[InlineData("At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non providenta", "01/01/1975", @"I\IR\Iron Maiden [9909]", @"I\IR\Iron Maiden [9909]\[1975] At Vero Eos Et Accusamus Et Iusto Odio Dignissimos Ducimus Qui Blanditiis Praesentium Volupta")]
|
||||
[InlineData("ΕΚΛΕΙΨΙΣ", "01/01/1981", @"E\EM\Empire Of The Moon [9909]", @"E\EM\Empire Of The Moon [9909]\[1981] _8c009a9a3d03d66b1a0dd24df400203b")]
|
||||
public void GenerateReleaseFolderNames(string input, string releaseDate, string artistFolder, string shouldBe)
|
||||
{
|
||||
var af = new DirectoryInfo(Path.Combine(Configuration.LibraryFolder, artistFolder));
|
||||
|
|
|
@ -194,7 +194,12 @@ namespace Roadie.Library.Utility
|
|||
var releasePathTitle = rt.ToString().ToAlphanumericName(false, false).ToFolderNameFriendly().ToTitleCase(false);
|
||||
if(string.IsNullOrEmpty(releasePathTitle))
|
||||
{
|
||||
throw new Exception($"ReleaseTitle [{ releaseTitle }] is invalid. ArtistFolder [{ artistFolder }].");
|
||||
releasePathTitle = $"_{ HashHelper.CreateMD5(rt.ToString()).ToFolderNameFriendly() }";
|
||||
if (string.IsNullOrEmpty(releasePathTitle))
|
||||
{
|
||||
throw new Exception($"ReleaseTitle [{ releaseTitle }] is invalid. ArtistFolder [{ artistFolder }].");
|
||||
}
|
||||
Trace.WriteLine($"Using [{ releasePathTitle }] for ReleaseFolder for ReleaseTitle [{ releaseTitle }]");
|
||||
}
|
||||
var maxFnLength = MaximumReleaseFolderNameLength - 7;
|
||||
if (releasePathTitle.Length > maxFnLength)
|
||||
|
|
|
@ -38,19 +38,31 @@ namespace Roadie.Api.Services
|
|||
private IFileDirectoryProcessorService FileDirectoryProcessorService { get; }
|
||||
|
||||
private IGenreService GenreService { get; }
|
||||
|
||||
private ILabelService LabelService { get; }
|
||||
|
||||
private IReleaseLookupEngine ReleaseLookupEngine { get; }
|
||||
|
||||
private IReleaseService ReleaseService { get; }
|
||||
|
||||
protected IHubContext<ScanActivityHub> ScanActivityHub { get; }
|
||||
|
||||
public AdminService(IRoadieSettings configuration, IHttpEncoder httpEncoder, IHttpContext httpContext,
|
||||
IRoadieDbContext context, ICacheManager cacheManager, ILogger<ArtistService> logger,
|
||||
IHubContext<ScanActivityHub> scanActivityHub, IFileDirectoryProcessorService fileDirectoryProcessorService, IArtistService artistService,
|
||||
IReleaseService releaseService, IArtistLookupEngine artistLookupEngine, IReleaseLookupEngine releaseLookupEngine,
|
||||
ILabelService labelService, IGenreService genreService, IBookmarkService bookmarkService
|
||||
)
|
||||
public AdminService(
|
||||
IRoadieSettings configuration,
|
||||
IHttpEncoder httpEncoder,
|
||||
IHttpContext httpContext,
|
||||
IRoadieDbContext context,
|
||||
ICacheManager cacheManager,
|
||||
ILogger<ArtistService> logger,
|
||||
IHubContext<ScanActivityHub> scanActivityHub,
|
||||
IFileDirectoryProcessorService fileDirectoryProcessorService,
|
||||
IArtistService artistService,
|
||||
IReleaseService releaseService,
|
||||
IArtistLookupEngine artistLookupEngine,
|
||||
IReleaseLookupEngine releaseLookupEngine,
|
||||
ILabelService labelService,
|
||||
IGenreService genreService,
|
||||
IBookmarkService bookmarkService)
|
||||
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)
|
||||
{
|
||||
ScanActivityHub = scanActivityHub;
|
||||
|
@ -1075,6 +1087,30 @@ namespace Roadie.Api.Services
|
|||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> ScanLastGiveNumberOfReleasesAsync(User user, int count, bool isReadOnly = false, bool wasDoneForInvalidTrackPlay = false)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
var errors = new List<Exception>();
|
||||
var releaseIds = await DbContext.Releases.OrderByDescending(x => x.CreatedDate).Select(x => x.RoadieId).Take(count).ToListAsync().ConfigureAwait(false);
|
||||
foreach (var releaseId in releaseIds)
|
||||
{
|
||||
var result = await ScanReleaseAsync(user, releaseId, isReadOnly, wasDoneForInvalidTrackPlay).ConfigureAwait(false);
|
||||
if (!result.IsSuccess && (result.Errors?.Any() ?? false))
|
||||
{
|
||||
errors.AddRange(result.Errors);
|
||||
}
|
||||
}
|
||||
sw.Stop();
|
||||
await LogAndPublishAsync($"** Completed! ScanLastGiveNumberOfReleasesAsync: Release Count [{ releaseIds.Count() }], Elapsed Time [{sw.Elapsed}]").ConfigureAwait(false);
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
IsSuccess = errors.Count == 0,
|
||||
OperationTime = sw.ElapsedMilliseconds,
|
||||
Errors = errors
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> ScanReleasesAsync(User user, IEnumerable<Guid> releaseIds, bool isReadOnly = false, bool wasDoneForInvalidTrackPlay = false)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
|
|
@ -49,6 +49,8 @@ namespace Roadie.Api.Services
|
|||
|
||||
Task<OperationResult<bool>> ScanReleasesAsync(User user, IEnumerable<Guid> releaseId, bool isReadOnly = false, bool wasDoneForInvalidTrackPlay = false);
|
||||
|
||||
Task<OperationResult<bool>> ScanLastGiveNumberOfReleasesAsync(User user, int count, bool isReadOnly = false, bool wasDoneForInvalidTrackPlay = false);
|
||||
|
||||
Task<OperationResult<bool>> UpdateInviteTokenUsedAsync(Guid? tokenId);
|
||||
|
||||
Task<OperationResult<bool>> ValidateInviteTokenAsync(Guid? tokenId);
|
||||
|
|
|
@ -52,8 +52,13 @@ namespace Roadie.Api.Services
|
|||
|
||||
protected ILogger Logger => _logger;
|
||||
|
||||
public ServiceBase(IRoadieSettings configuration, IHttpEncoder httpEncoder, IRoadieDbContext context,
|
||||
ICacheManager cacheManager, ILogger logger, IHttpContext httpContext)
|
||||
public ServiceBase(
|
||||
IRoadieSettings configuration,
|
||||
IHttpEncoder httpEncoder,
|
||||
IRoadieDbContext context,
|
||||
ICacheManager cacheManager,
|
||||
ILogger logger,
|
||||
IHttpContext httpContext)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_httpEncoder = httpEncoder;
|
||||
|
|
|
@ -343,5 +343,21 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("scan/releases/last/{count}")]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> ScanLastGiveNumberOfReleasesAsync(int count)
|
||||
{
|
||||
var result = await AdminService.ScanLastGiveNumberOfReleasesAsync(await UserManager.GetUserAsync(User).ConfigureAwait(false), count).ConfigureAwait(false);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
if (result.Messages?.Any() ?? false)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.BadRequest, result.Messages);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue