mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Took care of SonarCloud code issues (#1041)
This commit is contained in:
parent
5b32a958dc
commit
0e2fafe396
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Order;
|
||||
@ -29,37 +30,26 @@ namespace API.Benchmark
|
||||
Console.WriteLine($"Performing benchmark on {_names.Count} series");
|
||||
}
|
||||
|
||||
private static void NormalizeOriginal(string name)
|
||||
{
|
||||
Regex.Replace(name.ToLower(), "[^a-zA-Z0-9]", string.Empty);
|
||||
}
|
||||
|
||||
private static void NormalizeNew(string name)
|
||||
private static string Normalize(string name)
|
||||
{
|
||||
// ReSharper disable once UnusedVariable
|
||||
var ret = NormalizeRegex.Replace(name, string.Empty).ToLower();
|
||||
var normalized = NormalizeRegex.Replace(name, string.Empty).ToLower();
|
||||
return string.IsNullOrEmpty(normalized) ? name : normalized;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Benchmark]
|
||||
public void TestNormalizeName()
|
||||
{
|
||||
foreach (var name in _names)
|
||||
{
|
||||
NormalizeOriginal(name);
|
||||
Normalize(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Benchmark]
|
||||
public void TestNormalizeName_New()
|
||||
{
|
||||
foreach (var name in _names)
|
||||
{
|
||||
NormalizeNew(name);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TestIsEpub()
|
||||
{
|
||||
|
@ -151,6 +151,7 @@ namespace API.Tests.Parser
|
||||
[InlineData("Darker Than_Black", "darkerthanblack")]
|
||||
[InlineData("Citrus", "citrus")]
|
||||
[InlineData("Citrus+", "citrus+")]
|
||||
[InlineData("Again!!!!", "again")]
|
||||
[InlineData("카비타", "카비타")]
|
||||
[InlineData("", "")]
|
||||
public void NormalizeTest(string input, string expected)
|
||||
|
@ -155,7 +155,7 @@ namespace API.Controllers
|
||||
if (!string.IsNullOrEmpty(key) && mappings.ContainsKey(key))
|
||||
{
|
||||
var part = string.Empty;
|
||||
if (anchor.Attributes["href"].Value.Contains("#"))
|
||||
if (anchor.Attributes["href"].Value.Contains('#'))
|
||||
{
|
||||
part = anchor.Attributes["href"].Value.Split("#")[1];
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ public class OpdsController : BaseApiController
|
||||
private static void AddPagination(Feed feed, PagedList<SeriesDto> list, string href)
|
||||
{
|
||||
var url = href;
|
||||
if (href.Contains("?"))
|
||||
if (href.Contains('?'))
|
||||
{
|
||||
url += "&";
|
||||
}
|
||||
|
@ -30,11 +30,6 @@ namespace API.Data
|
||||
};
|
||||
}
|
||||
|
||||
public static SeriesMetadata SeriesMetadata(ComicInfo info)
|
||||
{
|
||||
return SeriesMetadata(Array.Empty<CollectionTag>());
|
||||
}
|
||||
|
||||
public static Volume Volume(string volumeNumber)
|
||||
{
|
||||
return new Volume()
|
||||
@ -61,6 +56,11 @@ namespace API.Data
|
||||
};
|
||||
}
|
||||
|
||||
public static SeriesMetadata SeriesMetadata(ComicInfo info)
|
||||
{
|
||||
return SeriesMetadata(Array.Empty<CollectionTag>());
|
||||
}
|
||||
|
||||
public static SeriesMetadata SeriesMetadata(ICollection<CollectionTag> collectionTags)
|
||||
{
|
||||
return new SeriesMetadata()
|
||||
|
@ -9,11 +9,10 @@ using Microsoft.Extensions.Logging;
|
||||
namespace API.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Responsible to migrate existing bookmarks to files
|
||||
/// Responsible to migrate existing bookmarks to files. Introduced in v0.4.9.27
|
||||
/// </summary>
|
||||
public static class MigrateBookmarks
|
||||
{
|
||||
private static readonly Version VersionBookmarksChanged = new Version(0, 4, 9, 27);
|
||||
/// <summary>
|
||||
/// This will migrate existing bookmarks to bookmark folder based
|
||||
/// </summary>
|
||||
|
@ -93,13 +93,10 @@ namespace API.Data
|
||||
await context.Database.EnsureCreatedAsync();
|
||||
|
||||
var users = await context.AppUser.ToListAsync();
|
||||
foreach (var user in users)
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.ApiKey))
|
||||
foreach (var user in users.Where(user => string.IsNullOrEmpty(user.ApiKey)))
|
||||
{
|
||||
user.ApiKey = HashUtil.ApiKey();
|
||||
}
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,5 @@ namespace API.Extensions
|
||||
return chapter.IsSpecial ? infos.Any(v => v.Filename == chapter.Range)
|
||||
: infos.Any(v => v.Chapters == chapter.Range);
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Returns the MangaFormat that is common to all the files. Unknown if files are mixed (should never happen) or no infos
|
||||
// /// </summary>
|
||||
// /// <param name="infos"></param>
|
||||
// /// <returns></returns>
|
||||
// public static MangaFormat GetFormat(this IList<ParserInfo> infos)
|
||||
// {
|
||||
// if (infos.Count == 0) return MangaFormat.Unknown;
|
||||
// return infos.DistinctBy(x => x.Format).First().Format;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -25,17 +25,5 @@ namespace API.Helpers.Converters
|
||||
|
||||
return destination;
|
||||
}
|
||||
|
||||
// public static string ConvertFromCronNotation(string cronNotation)
|
||||
// {
|
||||
// var destination = string.Empty;
|
||||
// destination = cronNotation.ToLower() switch
|
||||
// {
|
||||
// "0 0 31 2 *" => "disabled",
|
||||
// _ => destination
|
||||
// };
|
||||
//
|
||||
// return destination;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -659,20 +659,17 @@ namespace API.Parser
|
||||
|
||||
private static string FormatValue(string value, bool hasPart)
|
||||
{
|
||||
if (!value.Contains("-"))
|
||||
if (!value.Contains('-'))
|
||||
{
|
||||
return RemoveLeadingZeroes(hasPart ? AddChapterPart(value) : value);
|
||||
}
|
||||
|
||||
var tokens = value.Split("-");
|
||||
var from = RemoveLeadingZeroes(tokens[0]);
|
||||
if (tokens.Length == 2)
|
||||
{
|
||||
var to = RemoveLeadingZeroes(hasPart ? AddChapterPart(tokens[1]) : tokens[1]);
|
||||
return $"{@from}-{to}";
|
||||
}
|
||||
if (tokens.Length != 2) return from;
|
||||
|
||||
return @from;
|
||||
var to = RemoveLeadingZeroes(hasPart ? AddChapterPart(tokens[1]) : tokens[1]);
|
||||
return $"{from}-{to}";
|
||||
}
|
||||
|
||||
public static string ParseChapter(string filename)
|
||||
@ -696,7 +693,7 @@ namespace API.Parser
|
||||
|
||||
private static string AddChapterPart(string value)
|
||||
{
|
||||
if (value.Contains("."))
|
||||
if (value.Contains('.'))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@ -876,15 +873,12 @@ namespace API.Parser
|
||||
/// <returns>A zero padded number</returns>
|
||||
public static string PadZeros(string number)
|
||||
{
|
||||
if (number.Contains("-"))
|
||||
{
|
||||
if (!number.Contains('-')) return PerformPadding(number);
|
||||
|
||||
var tokens = number.Split("-");
|
||||
return $"{PerformPadding(tokens[0])}-{PerformPadding(tokens[1])}";
|
||||
}
|
||||
|
||||
return PerformPadding(number);
|
||||
}
|
||||
|
||||
private static string PerformPadding(string number)
|
||||
{
|
||||
var num = int.Parse(number);
|
||||
@ -964,7 +958,6 @@ namespace API.Parser
|
||||
|
||||
public static string Normalize(string name)
|
||||
{
|
||||
// TODO: This can eat upto 100MB on a file scan. Look into optimizing
|
||||
var normalized = NormalizeRegex.Replace(name, string.Empty).ToLower();
|
||||
return string.IsNullOrEmpty(normalized) ? name : normalized;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public interface IImageService
|
||||
/// Creates a Thumbnail version of a base64 image
|
||||
/// </summary>
|
||||
/// <param name="encodedImage">base64 encoded image</param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns>File name with extension of the file. This will always write to <see cref="DirectoryService.CoverImageDirectory"/></returns>
|
||||
string CreateThumbnailFromBase64(string encodedImage, string fileName);
|
||||
|
||||
@ -88,7 +89,7 @@ public class ImageService : IImageService
|
||||
try
|
||||
{
|
||||
_directoryService.FileSystem.File.Delete(_directoryService.FileSystem.Path.Join(outputDirectory, filename));
|
||||
} catch (Exception ex) {/* Swallow exception */}
|
||||
} catch (Exception) {/* Swallow exception */}
|
||||
thumbnail.WriteToFile(_directoryService.FileSystem.Path.Join(outputDirectory, filename));
|
||||
return filename;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user