Feature/image rework cleanup (#589)

* Added volume migrations. Added parser case for "Chapter 63 - The Promise Made for 520 Cenz.cbr"

* Added some info statements for when full library scans occur. For image apis, return the name of the file to aid in caching.

* When managing users, show the current logged in user at the top of the list. Added a message when no libraries have been setup but you are trying to add a user to a library.
This commit is contained in:
Joseph Milazzo 2021-09-22 06:00:14 -07:00 committed by GitHub
parent fb5866133a
commit a872165747
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 10 deletions

View file

@ -1,4 +1,6 @@
using System.IO;
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using API.Extensions;
using API.Interfaces;
@ -34,7 +36,7 @@ namespace API.Controllers
var format = Path.GetExtension(path).Replace(".", "");
Response.AddCacheHeader(path);
return PhysicalFile(path, "image/" + format);
return PhysicalFile(path, "image/" + format, Path.GetFileName(path));
}
/// <summary>
@ -50,7 +52,7 @@ namespace API.Controllers
var format = Path.GetExtension(path).Replace(".", "");
Response.AddCacheHeader(path);
return PhysicalFile(path, "image/" + format);
return PhysicalFile(path, "image/" + format, Path.GetFileName(path));
}
/// <summary>
@ -66,7 +68,7 @@ namespace API.Controllers
var format = Path.GetExtension(path).Replace(".", "");
Response.AddCacheHeader(path);
return PhysicalFile(path, "image/" + format);
return PhysicalFile(path, "image/" + format, Path.GetFileName(path));
}
/// <summary>
@ -82,7 +84,7 @@ namespace API.Controllers
var format = Path.GetExtension(path).Replace(".", "");
Response.AddCacheHeader(path);
return PhysicalFile(path, "image/" + format);
return PhysicalFile(path, "image/" + format, Path.GetFileName(path));
}
}
}

View file

@ -54,7 +54,7 @@ namespace API.Controllers
if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}");
var format = Path.GetExtension(path).Replace(".", "");
return PhysicalFile(path, "image/" + format);
return PhysicalFile(path, "image/" + format, Path.GetFileName(path));
}
catch (Exception)
{

View file

@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using API.Comparators;
using API.Helpers;
using API.Services;
using Microsoft.EntityFrameworkCore;
@ -23,6 +24,8 @@ namespace API.Data
/// </summary>
public static class MigrateCoverImages
{
private static readonly ChapterSortComparerZeroFirst ChapterSortComparerForInChapterSorting = new ();
/// <summary>
/// Run first. Will extract byte[]s from DB and write them to the cover directory.
/// </summary>
@ -140,6 +143,22 @@ namespace API.Data
await context.SaveChangesAsync();
Console.WriteLine("Updating Volume entities");
var volumes = await context.Volume.Include(v => v.Chapters).ToListAsync();
foreach (var volume in volumes)
{
var firstChapter = volume.Chapters.OrderBy(x => double.Parse(x.Number), ChapterSortComparerForInChapterSorting).FirstOrDefault();
if (firstChapter == null) continue;
if (File.Exists(Path.Join(DirectoryService.CoverImageDirectory,
$"{ImageService.GetChapterFormat(firstChapter.Id, firstChapter.VolumeId)}.png")))
{
volume.CoverImage = $"{ImageService.GetChapterFormat(firstChapter.Id, firstChapter.VolumeId)}.png";
}
}
await context.SaveChangesAsync();
Console.WriteLine("Updating Collection Tag entities");
var tags = await context.CollectionTag.ToListAsync();
foreach (var tag in tags)
@ -153,6 +172,7 @@ namespace API.Data
}
await context.SaveChangesAsync();
Console.WriteLine("Cover Image Migration completed");
}

View file

@ -448,7 +448,7 @@ namespace API.Parser
RegexTimeout),
// Hinowa ga CRUSH! 018 (2019) (Digital) (LuCaZ).cbz, Hinowa ga CRUSH! 018.5 (2019) (Digital) (LuCaZ).cbz
new Regex(
@"^(?!Vol)(?<Series>.*)\s(?<!vol\. )(?<Chapter>\d+(?:.\d+|-\d+)?)(?:\s\(\d{4}\))?(\b|_|-)",
@"^(?!Vol)(?<Series>.+?)\s(?<!vol\. )(?<Chapter>\d+(?:.\d+|-\d+)?)(?:\s\(\d{4}\))?(\b|_|-)",
RegexOptions.IgnoreCase | RegexOptions.Compiled,
RegexTimeout),
// Tower Of God S01 014 (CBT) (digital).cbz

View file

@ -128,12 +128,13 @@ namespace API.Services.Tasks
[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public async Task ScanLibraries()
{
_logger.LogInformation("Starting Scan of All Libraries");
var libraries = await _unitOfWork.LibraryRepository.GetLibrariesAsync();
foreach (var lib in libraries)
{
await ScanLibrary(lib.Id, false);
}
_logger.LogInformation("Scan of All Libraries Finished");
}