Closes #1214 Closes #1467pull/4065/head
parent
86130751c2
commit
a16463eeb3
@ -1,9 +1,11 @@
|
|||||||
// This file is automatically generated.
|
// This file is automatically generated.
|
||||||
// Please do not change this file!
|
// Please do not change this file!
|
||||||
interface CssExports {
|
interface CssExports {
|
||||||
|
'artistFolder': string;
|
||||||
'freeSpace': string;
|
'freeSpace': string;
|
||||||
'isMobile': string;
|
'isMobile': string;
|
||||||
'optionText': string;
|
'optionText': string;
|
||||||
|
'value': string;
|
||||||
}
|
}
|
||||||
export const cssExports: CssExports;
|
export const cssExports: CssExports;
|
||||||
export default cssExports;
|
export default cssExports;
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using FluentValidation.Validators;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
|
|
||||||
|
namespace Lidarr.Api.V1.Artist
|
||||||
|
{
|
||||||
|
public class ArtistFolderAsRootFolderValidator : PropertyValidator
|
||||||
|
{
|
||||||
|
private readonly IBuildFileNames _fileNameBuilder;
|
||||||
|
|
||||||
|
public ArtistFolderAsRootFolderValidator(IBuildFileNames fileNameBuilder)
|
||||||
|
{
|
||||||
|
_fileNameBuilder = fileNameBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GetDefaultMessageTemplate() => "Root folder path '{rootFolderPath}' contains artist folder '{artistFolder}'";
|
||||||
|
|
||||||
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
|
{
|
||||||
|
if (context.PropertyValue == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.InstanceToValidate is not ArtistResource artistResource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootFolderPath = context.PropertyValue.ToString();
|
||||||
|
|
||||||
|
if (rootFolderPath.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootFolder = new DirectoryInfo(rootFolderPath!).Name;
|
||||||
|
var artist = artistResource.ToModel();
|
||||||
|
var artistFolder = _fileNameBuilder.GetArtistFolder(artist);
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("rootFolderPath", rootFolderPath);
|
||||||
|
context.MessageFormatter.AppendArgument("artistFolder", artistFolder);
|
||||||
|
|
||||||
|
if (artistFolder == rootFolder)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var distance = artistFolder.LevenshteinDistance(rootFolder);
|
||||||
|
|
||||||
|
return distance >= Math.Max(1, artistFolder.Length * 0.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue