Basic Metadata Polish (#3548)
This commit is contained in:
parent
c0b59d87a4
commit
4c44dbf3e2
20 changed files with 3596 additions and 467 deletions
|
@ -61,4 +61,10 @@ public class AppUserBuilder : IEntityBuilder<AppUser>
|
|||
return this;
|
||||
}
|
||||
|
||||
public AppUserBuilder WithRole(string role)
|
||||
{
|
||||
_appUser.UserRoles ??= new List<AppUserRole>();
|
||||
_appUser.UserRoles.Add(new AppUserRole() {Role = new AppRole() {Name = role}});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,13 @@ public class SeriesBuilder : IEntityBuilder<Series>
|
|||
_series = new Series()
|
||||
{
|
||||
Name = name,
|
||||
|
||||
LocalizedName = name.ToNormalized(),
|
||||
NormalizedLocalizedName = name.ToNormalized(),
|
||||
|
||||
OriginalName = name,
|
||||
SortName = name,
|
||||
NormalizedName = name.ToNormalized(),
|
||||
NormalizedLocalizedName = name.ToNormalized(),
|
||||
Metadata = new SeriesMetadataBuilder()
|
||||
.WithPublicationStatus(PublicationStatus.OnGoing)
|
||||
.Build(),
|
||||
|
@ -39,14 +41,25 @@ public class SeriesBuilder : IEntityBuilder<Series>
|
|||
/// </summary>
|
||||
/// <param name="localizedName"></param>
|
||||
/// <returns></returns>
|
||||
public SeriesBuilder WithLocalizedName(string localizedName)
|
||||
public SeriesBuilder WithLocalizedName(string localizedName, bool lockStatus = false)
|
||||
{
|
||||
// Why is this here?
|
||||
if (string.IsNullOrEmpty(localizedName))
|
||||
{
|
||||
localizedName = _series.Name;
|
||||
}
|
||||
|
||||
_series.LocalizedName = localizedName;
|
||||
_series.NormalizedLocalizedName = localizedName.ToNormalized();
|
||||
_series.LocalizedNameLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeriesBuilder WithLocalizedNameAllowEmpty(string localizedName, bool lockStatus = false)
|
||||
{
|
||||
_series.LocalizedName = localizedName;
|
||||
_series.NormalizedLocalizedName = localizedName.ToNormalized();
|
||||
_series.LocalizedNameLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -106,4 +119,15 @@ public class SeriesBuilder : IEntityBuilder<Series>
|
|||
}
|
||||
|
||||
|
||||
public SeriesBuilder WithRelationship(int targetSeriesId, RelationKind kind)
|
||||
{
|
||||
_series.Relations ??= [];
|
||||
_series.Relations.Add(new SeriesRelation()
|
||||
{
|
||||
RelationKind = kind,
|
||||
TargetSeriesId = targetSeriesId
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,15 +39,17 @@ public class SeriesMetadataBuilder : IEntityBuilder<SeriesMetadata>
|
|||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithPublicationStatus(PublicationStatus status)
|
||||
public SeriesMetadataBuilder WithPublicationStatus(PublicationStatus status, bool lockState = false)
|
||||
{
|
||||
_seriesMetadata.PublicationStatus = status;
|
||||
_seriesMetadata.PublicationStatusLocked = lockState;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithAgeRating(AgeRating rating)
|
||||
public SeriesMetadataBuilder WithAgeRating(AgeRating rating, bool lockState = false)
|
||||
{
|
||||
_seriesMetadata.AgeRating = rating;
|
||||
_seriesMetadata.AgeRatingLocked = lockState;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -60,7 +62,6 @@ public class SeriesMetadataBuilder : IEntityBuilder<SeriesMetadata>
|
|||
Person = person,
|
||||
SeriesMetadata = _seriesMetadata,
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -70,15 +71,40 @@ public class SeriesMetadataBuilder : IEntityBuilder<SeriesMetadata>
|
|||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithReleaseYear(int year)
|
||||
public SeriesMetadataBuilder WithReleaseYear(int year, bool lockStatus = false)
|
||||
{
|
||||
_seriesMetadata.ReleaseYear = year;
|
||||
_seriesMetadata.ReleaseYearLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithSummary(string summary)
|
||||
public SeriesMetadataBuilder WithSummary(string summary, bool lockStatus = false)
|
||||
{
|
||||
_seriesMetadata.Summary = summary;
|
||||
_seriesMetadata.SummaryLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithGenre(Genre genre, bool lockStatus = false)
|
||||
{
|
||||
_seriesMetadata.Genres ??= [];
|
||||
_seriesMetadata.Genres.Add(genre);
|
||||
_seriesMetadata.GenresLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithGenres(List<Genre> genres, bool lockStatus = false)
|
||||
{
|
||||
_seriesMetadata.Genres = genres;
|
||||
_seriesMetadata.GenresLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeriesMetadataBuilder WithTag(Tag tag, bool lockStatus = false)
|
||||
{
|
||||
_seriesMetadata.Tags ??= [];
|
||||
_seriesMetadata.Tags.Add(tag);
|
||||
_seriesMetadata.TagsLocked = lockStatus;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
42
API/Helpers/StringHelper.cs
Normal file
42
API/Helpers/StringHelper.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace API.Helpers;
|
||||
#nullable enable
|
||||
|
||||
public static class StringHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to squash duplicate break and new lines with a single new line.
|
||||
/// </summary>
|
||||
/// <example>Test br br Test -> Test br Test</example>
|
||||
/// <param name="summary"></param>
|
||||
/// <returns></returns>
|
||||
public static string? SquashBreaklines(string? summary)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(summary))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// First standardize all br tags to <br /> format
|
||||
summary = Regex.Replace(summary, @"<br\s*/?>", "<br />", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
// Replace multiple consecutive br tags with a single br tag
|
||||
summary = Regex.Replace(summary, @"(?:<br />\s*)+", "<br /> ", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
// Normalize remaining whitespace (replace multiple spaces with a single space)
|
||||
summary = Regex.Replace(summary, @"\s+", " ").Trim();
|
||||
|
||||
return summary.Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the (Source: MangaDex) type of tags at the end of descriptions from AL
|
||||
/// </summary>
|
||||
/// <param name="description"></param>
|
||||
/// <returns></returns>
|
||||
public static string? RemoveSourceInDescription(string? description)
|
||||
{
|
||||
return description?.Trim();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue