Version Update Modal Rework + A few bugfixes (#3664)
This commit is contained in:
parent
9fb3bdd548
commit
43d0d1277f
65 changed files with 1963 additions and 805 deletions
|
@ -29,6 +29,7 @@ using API.DTOs.Theme;
|
|||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Entities.Metadata;
|
||||
using API.Entities.MetadataMatching;
|
||||
using API.Entities.Scrobble;
|
||||
using API.Extensions.QueryExtensions.Filtering;
|
||||
using API.Helpers.Converters;
|
||||
|
@ -336,7 +337,7 @@ public class AutoMapperProfiles : Profile
|
|||
CreateMap<UserReviewDto, ExternalReview>()
|
||||
.ForMember(dest => dest.BodyJustText,
|
||||
opt =>
|
||||
opt.MapFrom(src => ReviewService.GetCharacters(src.Body)));
|
||||
opt.MapFrom(src => ReviewHelper.GetCharacters(src.Body)));
|
||||
|
||||
CreateMap<ExternalRecommendation, ExternalSeriesDto>();
|
||||
CreateMap<Series, ManageMatchSeriesDto>()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
|
||||
namespace API.Extensions;
|
||||
namespace API.Helpers;
|
||||
|
||||
public static class DayOfWeekHelper
|
||||
{
|
||||
|
|
88
API/Helpers/ReviewHelper.cs
Normal file
88
API/Helpers/ReviewHelper.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using API.DTOs.SeriesDetail;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace API.Helpers;
|
||||
|
||||
public static class ReviewHelper
|
||||
{
|
||||
private const int BodyTextLimit = 175;
|
||||
public static IEnumerable<UserReviewDto> SelectSpectrumOfReviews(IList<UserReviewDto> reviews)
|
||||
{
|
||||
IList<UserReviewDto> externalReviews;
|
||||
var totalReviews = reviews.Count;
|
||||
|
||||
if (totalReviews > 10)
|
||||
{
|
||||
var stepSize = Math.Max((totalReviews - 4) / 8, 1);
|
||||
|
||||
var selectedReviews = new List<UserReviewDto>()
|
||||
{
|
||||
reviews[0],
|
||||
reviews[1],
|
||||
};
|
||||
for (var i = 2; i < totalReviews - 2; i += stepSize)
|
||||
{
|
||||
selectedReviews.Add(reviews[i]);
|
||||
|
||||
if (selectedReviews.Count >= 8)
|
||||
break;
|
||||
}
|
||||
|
||||
selectedReviews.Add(reviews[totalReviews - 2]);
|
||||
selectedReviews.Add(reviews[totalReviews - 1]);
|
||||
|
||||
externalReviews = selectedReviews;
|
||||
}
|
||||
else
|
||||
{
|
||||
externalReviews = reviews;
|
||||
}
|
||||
|
||||
return externalReviews.OrderByDescending(r => r.Score);
|
||||
}
|
||||
|
||||
public static string GetCharacters(string body)
|
||||
{
|
||||
if (string.IsNullOrEmpty(body)) return body;
|
||||
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(body);
|
||||
|
||||
var textNodes = doc.DocumentNode.SelectNodes("//text()[not(parent::script)]");
|
||||
if (textNodes == null) return string.Empty;
|
||||
var plainText = string.Join(" ", textNodes
|
||||
.Select(node => node.InnerText)
|
||||
.Where(s => !s.Equals("\n")));
|
||||
|
||||
// Clean any leftover markdown out
|
||||
plainText = Regex.Replace(plainText, @"\*\*(.*?)\*\*", "$1"); // Bold with **
|
||||
plainText = Regex.Replace(plainText, @"_(.*?)_", "$1"); // Italic with _
|
||||
plainText = Regex.Replace(plainText, @"\[(.*?)\]\((.*?)\)", "$1"); // Links [text](url)
|
||||
plainText = Regex.Replace(plainText, @"[_*\[\]~]", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"img\d*\((.*?)\)", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"~~~(.*?)~~~", "$1");
|
||||
plainText = Regex.Replace(plainText, @"\+{3}(.*?)\+{3}", "$1");
|
||||
plainText = Regex.Replace(plainText, @"~~(.*?)~~", "$1");
|
||||
plainText = Regex.Replace(plainText, @"__(.*?)__", "$1");
|
||||
plainText = Regex.Replace(plainText, @"#\s(.*?)", "$1");
|
||||
|
||||
|
||||
// Just strip symbols
|
||||
plainText = Regex.Replace(plainText, @"[_*\[\]~]", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"img\d*\((.*?)\)", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"~~~", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"\+", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"~~", string.Empty);
|
||||
plainText = Regex.Replace(plainText, @"__", string.Empty);
|
||||
|
||||
// Take the first BodyTextLimit characters
|
||||
plainText = plainText.Length > BodyTextLimit ? plainText.Substring(0, BodyTextLimit) : plainText;
|
||||
|
||||
return plainText + "…";
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue