mirror of
https://github.com/Readarr/Readarr
synced 2025-12-06 08:24:52 +01:00
New: Author folder hint when selecting a root folder while adding a new author
(cherry picked from commit dd09f31abb4dd3f699bcff0a47577075300c70ee) Fix AuthorFolderAsRootFolderValidator (cherry picked from commit 0ce81e1ab69d43fde382cc4ae22cd46fe626dea7)
This commit is contained in:
parent
0972d41bf8
commit
f819e582cf
26 changed files with 225 additions and 29 deletions
|
|
@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
|
|||
import React from 'react';
|
||||
import Button from 'Components/Link/Button';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import styles from './NoAuthor.css';
|
||||
|
||||
function NoAuthor(props) {
|
||||
|
|
@ -31,7 +32,7 @@ function NoAuthor(props) {
|
|||
to="/settings/mediamanagement"
|
||||
kind={kinds.PRIMARY}
|
||||
>
|
||||
Add Root Folder
|
||||
{translate('AddRootFolder')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ function NoAuthor(props) {
|
|||
to="/add/search"
|
||||
kind={kinds.PRIMARY}
|
||||
>
|
||||
Add New Author
|
||||
{translate('AddNewAuthor')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ function createMapStateToProps() {
|
|||
if (includeNoChange) {
|
||||
values.unshift({
|
||||
key: 'noChange',
|
||||
value: '',
|
||||
name: translate('NoChange'),
|
||||
value: translate('NoChange'),
|
||||
isDisabled: includeNoChangeDisabled,
|
||||
isMissing: false
|
||||
});
|
||||
|
|
@ -39,7 +38,6 @@ function createMapStateToProps() {
|
|||
values.push({
|
||||
key: '',
|
||||
value: '',
|
||||
name: '',
|
||||
isDisabled: true,
|
||||
isHidden: true
|
||||
});
|
||||
|
|
@ -56,8 +54,7 @@ function createMapStateToProps() {
|
|||
|
||||
values.push({
|
||||
key: ADD_NEW_KEY,
|
||||
value: '',
|
||||
name: 'Add a new path'
|
||||
value: 'Add a new path'
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
.value {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.authorFolder {
|
||||
flex: 0 0 auto;
|
||||
color: var(--disabledColor);
|
||||
}
|
||||
|
||||
.freeSpace {
|
||||
margin-left: 15px;
|
||||
color: var(--darkGray);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'authorFolder': string;
|
||||
'freeSpace': string;
|
||||
'isMissing': string;
|
||||
'isMobile': string;
|
||||
'optionText': string;
|
||||
'value': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
export default cssExports;
|
||||
|
|
|
|||
|
|
@ -7,18 +7,24 @@ import styles from './RootFolderSelectInputOption.css';
|
|||
|
||||
function RootFolderSelectInputOption(props) {
|
||||
const {
|
||||
id,
|
||||
value,
|
||||
name,
|
||||
freeSpace,
|
||||
authorFolder,
|
||||
isMissing,
|
||||
isMobile,
|
||||
isWindows,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
const text = value === '' ? name : `${name} [${value}]`;
|
||||
const slashCharacter = isWindows ? '\\' : '/';
|
||||
|
||||
const text = name === '' ? value : `[${name}] ${value}`;
|
||||
|
||||
return (
|
||||
<EnhancedSelectInputOption
|
||||
id={id}
|
||||
isMobile={isMobile}
|
||||
{...otherProps}
|
||||
>
|
||||
|
|
@ -27,7 +33,18 @@ function RootFolderSelectInputOption(props) {
|
|||
isMobile && styles.isMobile
|
||||
)}
|
||||
>
|
||||
<div>{text}</div>
|
||||
<div className={styles.value}>
|
||||
{text}
|
||||
|
||||
{
|
||||
authorFolder && id !== 'addNew' ?
|
||||
<div className={styles.authorFolder}>
|
||||
{slashCharacter}
|
||||
{authorFolder}
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
</div>
|
||||
|
||||
{
|
||||
freeSpace == null ?
|
||||
|
|
@ -50,11 +67,18 @@ function RootFolderSelectInputOption(props) {
|
|||
}
|
||||
|
||||
RootFolderSelectInputOption.propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
value: PropTypes.string.isRequired,
|
||||
freeSpace: PropTypes.number,
|
||||
authorFolder: PropTypes.string,
|
||||
isMissing: PropTypes.bool,
|
||||
isMobile: PropTypes.bool.isRequired
|
||||
isMobile: PropTypes.bool.isRequired,
|
||||
isWindows: PropTypes.bool
|
||||
};
|
||||
|
||||
RootFolderSelectInputOption.defaultProps = {
|
||||
name: ''
|
||||
};
|
||||
|
||||
export default RootFolderSelectInputOption;
|
||||
|
|
|
|||
|
|
@ -7,10 +7,20 @@
|
|||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pathContainer {
|
||||
@add-mixin truncate;
|
||||
display: flex;
|
||||
flex: 1 0 0;
|
||||
}
|
||||
|
||||
.path {
|
||||
@add-mixin truncate;
|
||||
flex: 0 1 auto;
|
||||
}
|
||||
|
||||
flex: 1 0 0;
|
||||
.authorFolder {
|
||||
flex: 0 1 auto;
|
||||
color: var(--disabledColor);
|
||||
}
|
||||
|
||||
.freeSpace {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'authorFolder': string;
|
||||
'freeSpace': string;
|
||||
'path': string;
|
||||
'pathContainer': string;
|
||||
'selectedValue': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
|
|
|
|||
|
|
@ -9,19 +9,34 @@ function RootFolderSelectInputSelectedValue(props) {
|
|||
name,
|
||||
value,
|
||||
freeSpace,
|
||||
authorFolder,
|
||||
includeFreeSpace,
|
||||
isWindows,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
const text = value === '' ? name : `${name} [${value}]`;
|
||||
const slashCharacter = isWindows ? '\\' : '/';
|
||||
|
||||
const text = name === '' ? value : `[${name}] ${value}`;
|
||||
|
||||
return (
|
||||
<EnhancedSelectInputSelectedValue
|
||||
className={styles.selectedValue}
|
||||
{...otherProps}
|
||||
>
|
||||
<div className={styles.path}>
|
||||
{text}
|
||||
<div className={styles.pathContainer}>
|
||||
<div className={styles.path}>
|
||||
{text}
|
||||
</div>
|
||||
|
||||
{
|
||||
authorFolder ?
|
||||
<div className={styles.authorFolder}>
|
||||
{slashCharacter}
|
||||
{authorFolder}
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
</div>
|
||||
|
||||
{
|
||||
|
|
@ -38,10 +53,13 @@ RootFolderSelectInputSelectedValue.propTypes = {
|
|||
name: PropTypes.string,
|
||||
value: PropTypes.string,
|
||||
freeSpace: PropTypes.number,
|
||||
authorFolder: PropTypes.string,
|
||||
isWindows: PropTypes.bool,
|
||||
includeFreeSpace: PropTypes.bool.isRequired
|
||||
};
|
||||
|
||||
RootFolderSelectInputSelectedValue.defaultProps = {
|
||||
name: '',
|
||||
includeFreeSpace: true
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,11 +35,12 @@
|
|||
.message {
|
||||
margin-top: 30px;
|
||||
text-align: center;
|
||||
font-weight: 300;
|
||||
font-size: $largeFontSize;
|
||||
}
|
||||
|
||||
.helpText {
|
||||
margin-bottom: 10px;
|
||||
font-weight: 300;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ class AddNewItem extends Component {
|
|||
render() {
|
||||
const {
|
||||
error,
|
||||
items
|
||||
items,
|
||||
hasExistingAuthors
|
||||
} = this.props;
|
||||
|
||||
const term = this.state.term;
|
||||
|
|
@ -186,7 +187,8 @@ class AddNewItem extends Component {
|
|||
}
|
||||
|
||||
{
|
||||
!term &&
|
||||
term ?
|
||||
null :
|
||||
<div className={styles.message}>
|
||||
<div className={styles.helpText}>
|
||||
{translate('ItsEasyToAddANewAuthorOrBookJustStartTypingTheNameOfTheItemYouWantToAdd')}
|
||||
|
|
@ -199,6 +201,24 @@ class AddNewItem extends Component {
|
|||
</div>
|
||||
}
|
||||
|
||||
{
|
||||
!term && !hasExistingAuthors ?
|
||||
<div className={styles.message}>
|
||||
<div className={styles.noAuthorsText}>
|
||||
You haven't added any authors yet, do you want to add an existing library location (Root Folder) and update?
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
to="/settings/mediamanagement"
|
||||
kind={kinds.PRIMARY}
|
||||
>
|
||||
{translate('AddRootFolder')}
|
||||
</Button>
|
||||
</div>
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
|
||||
<div />
|
||||
</PageContentBody>
|
||||
</PageContent>
|
||||
|
|
@ -213,6 +233,7 @@ AddNewItem.propTypes = {
|
|||
isAdding: PropTypes.bool.isRequired,
|
||||
addError: PropTypes.object,
|
||||
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
hasExistingAuthors: PropTypes.bool.isRequired,
|
||||
onSearchChange: PropTypes.func.isRequired,
|
||||
onClearSearch: PropTypes.func.isRequired
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,13 +10,15 @@ import AddNewItem from './AddNewItem';
|
|||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
(state) => state.search,
|
||||
(state) => state.authors.items.length,
|
||||
(state) => state.router.location,
|
||||
(search, location) => {
|
||||
(search, existingAuthorsCount, location) => {
|
||||
const { params } = parseUrl(location.search);
|
||||
|
||||
return {
|
||||
...search,
|
||||
term: params.term,
|
||||
...search
|
||||
hasExistingAuthors: existingAuthorsCount > 0
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import ModalContent from 'Components/Modal/ModalContent';
|
|||
import ModalFooter from 'Components/Modal/ModalFooter';
|
||||
import ModalHeader from 'Components/Modal/ModalHeader';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import AddAuthorOptionsForm from '../Common/AddAuthorOptionsForm.js';
|
||||
import styles from './AddNewAuthorModalContent.css';
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ class AddNewAuthorModalContent extends Component {
|
|||
return (
|
||||
<ModalContent onModalClose={onModalClose}>
|
||||
<ModalHeader>
|
||||
Add new Author
|
||||
{translate('AddNewAuthor')}
|
||||
</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
|
|
@ -133,7 +134,7 @@ class AddNewAuthorModalContent extends Component {
|
|||
|
||||
AddNewAuthorModalContent.propTypes = {
|
||||
authorName: PropTypes.string.isRequired,
|
||||
disambiguation: PropTypes.string.isRequired,
|
||||
disambiguation: PropTypes.string,
|
||||
overview: PropTypes.string,
|
||||
images: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
isAdding: PropTypes.bool.isRequired,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { connect } from 'react-redux';
|
|||
import { createSelector } from 'reselect';
|
||||
import { addAuthor, setAuthorAddDefault } from 'Store/Actions/searchActions';
|
||||
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||
import createSystemStatusSelector from 'Store/Selectors/createSystemStatusSelector';
|
||||
import selectSettings from 'Store/Selectors/selectSettings';
|
||||
import AddNewAuthorModalContent from './AddNewAuthorModalContent';
|
||||
|
||||
|
|
@ -12,7 +13,8 @@ function createMapStateToProps() {
|
|||
(state) => state.search,
|
||||
(state) => state.settings.metadataProfiles,
|
||||
createDimensionsSelector(),
|
||||
(searchState, metadataProfiles, dimensions) => {
|
||||
createSystemStatusSelector(),
|
||||
(searchState, metadataProfiles, dimensions, systemStatus) => {
|
||||
const {
|
||||
isAdding,
|
||||
addError,
|
||||
|
|
@ -32,6 +34,7 @@ function createMapStateToProps() {
|
|||
isSmallScreen: dimensions.isSmallScreen,
|
||||
validationErrors,
|
||||
validationWarnings,
|
||||
isWindows: systemStatus.isWindows,
|
||||
...settings
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ class AddNewAuthorSearchResult extends Component {
|
|||
status,
|
||||
overview,
|
||||
ratings,
|
||||
folder,
|
||||
images,
|
||||
isExistingAuthor,
|
||||
isSmallScreen
|
||||
|
|
@ -205,6 +206,7 @@ class AddNewAuthorSearchResult extends Component {
|
|||
disambiguation={disambiguation}
|
||||
year={year}
|
||||
overview={overview}
|
||||
folder={folder}
|
||||
images={images}
|
||||
onModalClose={this.onAddAuthorModalClose}
|
||||
/>
|
||||
|
|
@ -222,6 +224,7 @@ AddNewAuthorSearchResult.propTypes = {
|
|||
status: PropTypes.string.isRequired,
|
||||
overview: PropTypes.string,
|
||||
ratings: PropTypes.object.isRequired,
|
||||
folder: PropTypes.string.isRequired,
|
||||
images: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
isExistingAuthor: PropTypes.bool.isRequired,
|
||||
isSmallScreen: PropTypes.bool.isRequired
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import ModalFooter from 'Components/Modal/ModalFooter';
|
|||
import ModalHeader from 'Components/Modal/ModalHeader';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import stripHtml from 'Utilities/String/stripHtml';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import AddAuthorOptionsForm from '../Common/AddAuthorOptionsForm.js';
|
||||
import styles from './AddNewBookModalContent.css';
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ class AddNewBookModalContent extends Component {
|
|||
return (
|
||||
<ModalContent onModalClose={onModalClose}>
|
||||
<ModalHeader>
|
||||
Add new Book
|
||||
{translate('AddNewBook')}
|
||||
</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { connect } from 'react-redux';
|
|||
import { createSelector } from 'reselect';
|
||||
import { addBook, setBookAddDefault } from 'Store/Actions/searchActions';
|
||||
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
|
||||
import createSystemStatusSelector from 'Store/Selectors/createSystemStatusSelector';
|
||||
import selectSettings from 'Store/Selectors/selectSettings';
|
||||
import AddNewBookModalContent from './AddNewBookModalContent';
|
||||
|
||||
|
|
@ -13,7 +14,8 @@ function createMapStateToProps() {
|
|||
(state) => state.search,
|
||||
(state) => state.settings.metadataProfiles,
|
||||
createDimensionsSelector(),
|
||||
(isExistingAuthor, searchState, metadataProfiles, dimensions) => {
|
||||
createSystemStatusSelector(),
|
||||
(isExistingAuthor, searchState, metadataProfiles, dimensions, systemStatus) => {
|
||||
const {
|
||||
isAdding,
|
||||
addError,
|
||||
|
|
@ -33,6 +35,7 @@ function createMapStateToProps() {
|
|||
isSmallScreen: dimensions.isSmallScreen,
|
||||
validationErrors,
|
||||
validationWarnings,
|
||||
isWindows: systemStatus.isWindows,
|
||||
...settings
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ class AddNewBookSearchResult extends Component {
|
|||
disambiguation={disambiguation}
|
||||
authorName={author.authorName}
|
||||
overview={overview}
|
||||
folder={author.folder}
|
||||
images={images}
|
||||
onModalClose={this.onAddBookModalClose}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ class AddAuthorOptionsForm extends Component {
|
|||
includeNoneMetadataProfile,
|
||||
includeSpecificBookMonitor,
|
||||
showMetadataProfile,
|
||||
folder,
|
||||
tags,
|
||||
isWindows,
|
||||
onInputChange,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
|
@ -54,6 +56,15 @@ class AddAuthorOptionsForm extends Component {
|
|||
<FormInputGroup
|
||||
type={inputTypes.ROOT_FOLDER_SELECT}
|
||||
name="rootFolderPath"
|
||||
valueOptions={{
|
||||
authorFolder: folder,
|
||||
isWindows
|
||||
}}
|
||||
selectedValueOptions={{
|
||||
authorFolder: folder,
|
||||
isWindows
|
||||
}}
|
||||
helpText={translate('AddNewAuthorRootFolderHelpText', { folder })}
|
||||
onChange={onInputChange}
|
||||
{...rootFolderPath}
|
||||
/>
|
||||
|
|
@ -179,8 +190,14 @@ AddAuthorOptionsForm.propTypes = {
|
|||
showMetadataProfile: PropTypes.bool.isRequired,
|
||||
includeNoneMetadataProfile: PropTypes.bool.isRequired,
|
||||
includeSpecificBookMonitor: PropTypes.bool.isRequired,
|
||||
folder: PropTypes.string.isRequired,
|
||||
tags: PropTypes.object.isRequired,
|
||||
isWindows: PropTypes.bool.isRequired,
|
||||
onInputChange: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
AddAuthorOptionsForm.defaultProps = {
|
||||
includeSpecificBookMonitor: false
|
||||
};
|
||||
|
||||
export default AddAuthorOptionsForm;
|
||||
|
|
|
|||
|
|
@ -108,6 +108,15 @@ public static string GetParentPath(this string childPath)
|
|||
return Directory.GetParent(cleanPath)?.FullName;
|
||||
}
|
||||
|
||||
public static string GetCleanPath(this string path)
|
||||
{
|
||||
var cleanPath = OsInfo.IsWindows
|
||||
? PARENT_PATH_END_SLASH_REGEX.Replace(path, "")
|
||||
: path.TrimEnd(Path.DirectorySeparatorChar);
|
||||
|
||||
return cleanPath;
|
||||
}
|
||||
|
||||
public static bool IsParentPath(this string parentPath, string childPath)
|
||||
{
|
||||
if (parentPath != "/" && !parentPath.EndsWith(":\\"))
|
||||
|
|
|
|||
|
|
@ -11,7 +11,11 @@
|
|||
"AddListExclusion": "Add List Exclusion",
|
||||
"AddMissing": "Add missing",
|
||||
"AddNew": "Add New",
|
||||
"AddNewBook": "Add New Book",
|
||||
"AddNewAuthor": "Add New Author",
|
||||
"AddNewAuthorRootFolderHelpText": "'{folder}' subfolder will be created automatically",
|
||||
"AddNewItem": "Add New Item",
|
||||
"AddRootFolder": "Add Root Folder",
|
||||
"AddedAuthorSettings": "Added Author Settings",
|
||||
"AddingTag": "Adding tag",
|
||||
"AgeWhenGrabbed": "Age (when grabbed)",
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ public AuthorController(IBroadcastSignalRMessage signalRBroadcaster,
|
|||
AuthorAncestorValidator authorAncestorValidator,
|
||||
SystemFolderValidator systemFolderValidator,
|
||||
QualityProfileExistsValidator qualityProfileExistsValidator,
|
||||
MetadataProfileExistsValidator metadataProfileExistsValidator)
|
||||
MetadataProfileExistsValidator metadataProfileExistsValidator,
|
||||
AuthorFolderAsRootFolderValidator authorFolderAsRootFolderValidator)
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_authorService = authorService;
|
||||
|
|
@ -89,7 +90,10 @@ public AuthorController(IBroadcastSignalRMessage signalRBroadcaster,
|
|||
SharedValidator.RuleFor(s => s.MetadataProfileId).SetValidator(metadataProfileExistsValidator);
|
||||
|
||||
PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace());
|
||||
PostValidator.RuleFor(s => s.RootFolderPath).IsValidPath().When(s => s.Path.IsNullOrWhiteSpace());
|
||||
PostValidator.RuleFor(s => s.RootFolderPath)
|
||||
.IsValidPath()
|
||||
.SetValidator(authorFolderAsRootFolderValidator)
|
||||
.When(s => s.Path.IsNullOrWhiteSpace());
|
||||
PostValidator.RuleFor(s => s.AuthorName).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.ForeignAuthorId).NotEmpty().SetValidator(authorExistsValidator);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using FluentValidation.Validators;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Organizer;
|
||||
|
||||
namespace Readarr.Api.V1.Author
|
||||
{
|
||||
public class AuthorFolderAsRootFolderValidator : PropertyValidator
|
||||
{
|
||||
private readonly IBuildFileNames _fileNameBuilder;
|
||||
|
||||
public AuthorFolderAsRootFolderValidator(IBuildFileNames fileNameBuilder)
|
||||
{
|
||||
_fileNameBuilder = fileNameBuilder;
|
||||
}
|
||||
|
||||
protected override string GetDefaultMessageTemplate() => "Root folder path contains author folder";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
if (context.PropertyValue == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var authorResource = context.ParentContext.InstanceToValidate as AuthorResource;
|
||||
|
||||
if (authorResource == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var rootFolderPath = context.PropertyValue.ToString();
|
||||
var rootFolder = new DirectoryInfo(rootFolderPath).Name;
|
||||
var author = authorResource.ToModel();
|
||||
var authorFolder = _fileNameBuilder.GetAuthorFolder(author);
|
||||
|
||||
if (authorFolder == rootFolder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var distance = authorFolder.LevenshteinDistance(rootFolder);
|
||||
|
||||
return distance >= Math.Max(1, authorFolder.Length * 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using Readarr.Http;
|
||||
|
||||
namespace Readarr.Api.V1.Author
|
||||
|
|
@ -11,11 +12,13 @@ namespace Readarr.Api.V1.Author
|
|||
public class AuthorLookupController : Controller
|
||||
{
|
||||
private readonly ISearchForNewAuthor _searchProxy;
|
||||
private readonly IBuildFileNames _fileNameBuilder;
|
||||
private readonly IMapCoversToLocal _coverMapper;
|
||||
|
||||
public AuthorLookupController(ISearchForNewAuthor searchProxy, IMapCoversToLocal coverMapper)
|
||||
public AuthorLookupController(ISearchForNewAuthor searchProxy, IBuildFileNames fileNameBuilder, IMapCoversToLocal coverMapper)
|
||||
{
|
||||
_searchProxy = searchProxy;
|
||||
_fileNameBuilder = fileNameBuilder;
|
||||
_coverMapper = coverMapper;
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +44,8 @@ private IEnumerable<AuthorResource> MapToResource(IEnumerable<NzbDrone.Core.Book
|
|||
resource.RemotePoster = poster.Url;
|
||||
}
|
||||
|
||||
resource.Folder = _fileNameBuilder.GetAuthorFolder(currentAuthor);
|
||||
|
||||
yield return resource;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public class AuthorResource : RestResource
|
|||
public NewItemMonitorTypes MonitorNewItems { get; set; }
|
||||
|
||||
public string RootFolderPath { get; set; }
|
||||
public string Folder { get; set; }
|
||||
public List<string> Genres { get; set; }
|
||||
public string CleanName { get; set; }
|
||||
public string SortName { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Books.Calibre;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
|
@ -47,7 +48,7 @@ public static RootFolderResource ToResource(this RootFolder model)
|
|||
Id = model.Id,
|
||||
|
||||
Name = model.Name,
|
||||
Path = model.Path,
|
||||
Path = model.Path.GetCleanPath(),
|
||||
DefaultMetadataProfileId = model.DefaultMetadataProfileId,
|
||||
DefaultQualityProfileId = model.DefaultQualityProfileId,
|
||||
DefaultMonitorOption = model.DefaultMonitorOption,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using Readarr.Api.V1.Author;
|
||||
using Readarr.Api.V1.Books;
|
||||
using Readarr.Http;
|
||||
|
|
@ -14,11 +15,13 @@ namespace Readarr.Api.V1.Search
|
|||
public class SearchController : Controller
|
||||
{
|
||||
private readonly ISearchForNewEntity _searchProxy;
|
||||
private readonly IBuildFileNames _fileNameBuilder;
|
||||
private readonly IMapCoversToLocal _coverMapper;
|
||||
|
||||
public SearchController(ISearchForNewEntity searchProxy, IMapCoversToLocal coverMapper)
|
||||
public SearchController(ISearchForNewEntity searchProxy, IBuildFileNames fileNameBuilder, IMapCoversToLocal coverMapper)
|
||||
{
|
||||
_searchProxy = searchProxy;
|
||||
_fileNameBuilder = fileNameBuilder;
|
||||
_coverMapper = coverMapper;
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +53,8 @@ private IEnumerable<SearchResource> MapToResource(IEnumerable<object> results)
|
|||
{
|
||||
resource.Author.RemotePoster = poster.Url;
|
||||
}
|
||||
|
||||
resource.Author.Folder = _fileNameBuilder.GetAuthorFolder(author);
|
||||
}
|
||||
else if (result is NzbDrone.Core.Books.Book book)
|
||||
{
|
||||
|
|
@ -67,6 +72,8 @@ private IEnumerable<SearchResource> MapToResource(IEnumerable<object> results)
|
|||
{
|
||||
resource.Book.RemoteCover = cover.Url;
|
||||
}
|
||||
|
||||
resource.Book.Author.Folder = _fileNameBuilder.GetAuthorFolder(book.Author);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue