From d4a0a95635d13effd63aedf3a95af2367c7149e7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 14 Aug 2020 01:54:21 +0100 Subject: [PATCH] Create folders for scans. --- Marechai.sln.DotSettings | 1 + Marechai/Helpers/Photos.cs | 168 ++++++++++-------- Marechai/Marechai.csproj | 2 +- .../Admin/Details/CreateMachinePhoto.razor.cs | 3 +- Marechai/Program.cs | 21 ++- 5 files changed, 110 insertions(+), 85 deletions(-) diff --git a/Marechai.sln.DotSettings b/Marechai.sln.DotSettings index 47b384a5..a8bcdd0c 100644 --- a/Marechai.sln.DotSettings +++ b/Marechai.sln.DotSettings @@ -3,6 +3,7 @@ True True True + True True True True diff --git a/Marechai/Helpers/Photos.cs b/Marechai/Helpers/Photos.cs index 99d1d20d..1de10cb6 100644 --- a/Marechai/Helpers/Photos.cs +++ b/Marechai/Helpers/Photos.cs @@ -36,67 +36,67 @@ namespace Marechai.Helpers { public delegate Task ConversionFinished(bool result); - public static void EnsureCreated(string webRootPath) + public static void EnsureCreated(string webRootPath, bool scan, string item) { List paths = new List(); - string photosRoot = Path.Combine(webRootPath, "assets", "photos"); - string machinePhotosRoot = Path.Combine(photosRoot, "machines"); - string machineThumbsRoot = Path.Combine(machinePhotosRoot, "thumbs"); - string machineOriginalPhotosRoot = Path.Combine(machinePhotosRoot, "originals"); + string photosRoot = Path.Combine(webRootPath, "assets", scan ? "scan" : "photos"); + string itemPhotosRoot = Path.Combine(photosRoot, item); + string itemThumbsRoot = Path.Combine(itemPhotosRoot, "thumbs"); + string itemOriginalPhotosRoot = Path.Combine(itemPhotosRoot, "originals"); paths.Add(photosRoot); - paths.Add(machinePhotosRoot); - paths.Add(machineThumbsRoot); - paths.Add(machineOriginalPhotosRoot); + paths.Add(itemPhotosRoot); + paths.Add(itemThumbsRoot); + paths.Add(itemOriginalPhotosRoot); - paths.Add(Path.Combine(machineThumbsRoot, "jpeg", "hd")); - paths.Add(Path.Combine(machineThumbsRoot, "jpeg", "1440p")); - paths.Add(Path.Combine(machineThumbsRoot, "jpeg", "4k")); - paths.Add(Path.Combine(machinePhotosRoot, "jpeg", "hd")); - paths.Add(Path.Combine(machinePhotosRoot, "jpeg", "1440p")); - paths.Add(Path.Combine(machinePhotosRoot, "jpeg", "4k")); + paths.Add(Path.Combine(itemThumbsRoot, "jpeg", "hd")); + paths.Add(Path.Combine(itemThumbsRoot, "jpeg", "1440p")); + paths.Add(Path.Combine(itemThumbsRoot, "jpeg", "4k")); + paths.Add(Path.Combine(itemPhotosRoot, "jpeg", "hd")); + paths.Add(Path.Combine(itemPhotosRoot, "jpeg", "1440p")); + paths.Add(Path.Combine(itemPhotosRoot, "jpeg", "4k")); - paths.Add(Path.Combine(machineThumbsRoot, "jp2k", "hd")); - paths.Add(Path.Combine(machineThumbsRoot, "jp2k", "1440p")); - paths.Add(Path.Combine(machineThumbsRoot, "jp2k", "4k")); - paths.Add(Path.Combine(machinePhotosRoot, "jp2k", "hd")); - paths.Add(Path.Combine(machinePhotosRoot, "jp2k", "1440p")); - paths.Add(Path.Combine(machinePhotosRoot, "jp2k", "4k")); + paths.Add(Path.Combine(itemThumbsRoot, "jp2k", "hd")); + paths.Add(Path.Combine(itemThumbsRoot, "jp2k", "1440p")); + paths.Add(Path.Combine(itemThumbsRoot, "jp2k", "4k")); + paths.Add(Path.Combine(itemPhotosRoot, "jp2k", "hd")); + paths.Add(Path.Combine(itemPhotosRoot, "jp2k", "1440p")); + paths.Add(Path.Combine(itemPhotosRoot, "jp2k", "4k")); - paths.Add(Path.Combine(machineThumbsRoot, "webp", "hd")); - paths.Add(Path.Combine(machineThumbsRoot, "webp", "1440p")); - paths.Add(Path.Combine(machineThumbsRoot, "webp", "4k")); - paths.Add(Path.Combine(machinePhotosRoot, "webp", "hd")); - paths.Add(Path.Combine(machinePhotosRoot, "webp", "1440p")); - paths.Add(Path.Combine(machinePhotosRoot, "webp", "4k")); + paths.Add(Path.Combine(itemThumbsRoot, "webp", "hd")); + paths.Add(Path.Combine(itemThumbsRoot, "webp", "1440p")); + paths.Add(Path.Combine(itemThumbsRoot, "webp", "4k")); + paths.Add(Path.Combine(itemPhotosRoot, "webp", "hd")); + paths.Add(Path.Combine(itemPhotosRoot, "webp", "1440p")); + paths.Add(Path.Combine(itemPhotosRoot, "webp", "4k")); - paths.Add(Path.Combine(machineThumbsRoot, "heif", "hd")); - paths.Add(Path.Combine(machineThumbsRoot, "heif", "1440p")); - paths.Add(Path.Combine(machineThumbsRoot, "heif", "4k")); - paths.Add(Path.Combine(machinePhotosRoot, "heif", "hd")); - paths.Add(Path.Combine(machinePhotosRoot, "heif", "1440p")); - paths.Add(Path.Combine(machinePhotosRoot, "heif", "4k")); + paths.Add(Path.Combine(itemThumbsRoot, "heif", "hd")); + paths.Add(Path.Combine(itemThumbsRoot, "heif", "1440p")); + paths.Add(Path.Combine(itemThumbsRoot, "heif", "4k")); + paths.Add(Path.Combine(itemPhotosRoot, "heif", "hd")); + paths.Add(Path.Combine(itemPhotosRoot, "heif", "1440p")); + paths.Add(Path.Combine(itemPhotosRoot, "heif", "4k")); - paths.Add(Path.Combine(machineThumbsRoot, "avif", "hd")); - paths.Add(Path.Combine(machineThumbsRoot, "avif", "1440p")); - paths.Add(Path.Combine(machineThumbsRoot, "avif", "4k")); - paths.Add(Path.Combine(machinePhotosRoot, "avif", "hd")); - paths.Add(Path.Combine(machinePhotosRoot, "avif", "1440p")); - paths.Add(Path.Combine(machinePhotosRoot, "avif", "4k")); + paths.Add(Path.Combine(itemThumbsRoot, "avif", "hd")); + paths.Add(Path.Combine(itemThumbsRoot, "avif", "1440p")); + paths.Add(Path.Combine(itemThumbsRoot, "avif", "4k")); + paths.Add(Path.Combine(itemPhotosRoot, "avif", "hd")); + paths.Add(Path.Combine(itemPhotosRoot, "avif", "1440p")); + paths.Add(Path.Combine(itemPhotosRoot, "avif", "4k")); foreach(string path in paths.Where(path => !Directory.Exists(path))) Directory.CreateDirectory(path); } public static bool Convert(string webRootPath, Guid id, string originalPath, string sourceFormat, - string outputFormat, string resolution, bool thumbnail) + string outputFormat, string resolution, bool thumbnail, bool scan, string item) { outputFormat = outputFormat.ToLowerInvariant(); resolution = resolution.ToLowerInvariant(); sourceFormat = sourceFormat.ToLowerInvariant(); - string outputPath = Path.Combine(webRootPath, "assets", "photos", "machines"); + string outputPath = Path.Combine(webRootPath, "assets", scan ? "scans" : "photos", item); int width, height; if(thumbnail) @@ -268,75 +268,91 @@ namespace Marechai.Helpers } } - public void ConversionWorker(string webRootPath, Guid id, string originalFilePath, string sourceFormat) + public void ConversionWorker(string webRootPath, Guid id, string originalFilePath, string sourceFormat, + bool scan, string item) { List pool = new List { new Task(() => FinishedRenderingJpeg4kThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JPEG", "4k", true))), + sourceFormat, "JPEG", "4k", true, + scan, item))), new Task(() => FinishedRenderingJpeg1440Thumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JPEG", "1440p", - true))), + sourceFormat, "JPEG", "1440p", true, + scan, item))), new Task(() => FinishedRenderingJpegHdThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JPEG", "hd", true))), + sourceFormat, "JPEG", "hd", true, + scan, item))), new Task(() => FinishedRenderingJpeg4k?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "JPEG", "4k", false))), + "JPEG", "4k", false, scan, item))), new Task(() => FinishedRenderingJpeg1440?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JPEG", "1440p", false))), + sourceFormat, "JPEG", "1440p", false, scan, + item))), new Task(() => FinishedRenderingJpegHd?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "JPEG", "hd", false))), + "JPEG", "hd", false, scan, item))), new Task(() => FinishedRenderingJp2k4kThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JP2K", "4k", true))), + sourceFormat, "JP2K", "4k", true, + scan, item))), new Task(() => FinishedRenderingJp2k1440Thumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JP2K", "1440p", - true))), + sourceFormat, "JP2K", "1440p", true, + scan, item))), new Task(() => FinishedRenderingJp2kHdThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JP2K", "hd", true))), + sourceFormat, "JP2K", "hd", true, + scan, item))), new Task(() => FinishedRenderingJp2k4k?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "JP2K", "4k", false))), + "JP2K", "4k", false, scan, item))), new Task(() => FinishedRenderingJp2k1440?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "JP2K", "1440p", false))), + sourceFormat, "JP2K", "1440p", false, scan, + item))), new Task(() => FinishedRenderingJp2kHd?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "JP2K", "hd", false))), + "JP2K", "hd", false, scan, item))), new Task(() => FinishedRenderingWebp4kThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "WEBP", "4k", true))), + sourceFormat, "WEBP", "4k", true, + scan, item))), new Task(() => FinishedRenderingWebp1440Thumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "WEBP", "1440p", - true))), + sourceFormat, "WEBP", "1440p", true, + scan, item))), new Task(() => FinishedRenderingWebpHdThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "WEBP", "hd", true))), + sourceFormat, "WEBP", "hd", true, + scan, item))), new Task(() => FinishedRenderingWebp4k?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "WEBP", "4k", false))), + "WEBP", "4k", false, scan, item))), new Task(() => FinishedRenderingWebp1440?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "WEBP", "1440p", false))), + sourceFormat, "WEBP", "1440p", false, scan, + item))), new Task(() => FinishedRenderingWebpHd?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "WEBP", "hd", false))), + "WEBP", "hd", false, scan, item))), new Task(() => FinishedRenderingHeif4kThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "HEIF", "4k", true))), + sourceFormat, "HEIF", "4k", true, + scan, item))), new Task(() => FinishedRenderingHeif1440Thumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "HEIF", "1440p", - true))), + sourceFormat, "HEIF", "1440p", true, + scan, item))), new Task(() => FinishedRenderingHeifHdThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "HEIF", "hd", true))), + sourceFormat, "HEIF", "hd", true, + scan, item))), new Task(() => FinishedRenderingHeif4k?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "HEIF", "4k", false))), + "HEIF", "4k", false, scan, item))), new Task(() => FinishedRenderingHeif1440?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "HEIF", "1440p", false))), + sourceFormat, "HEIF", "1440p", false, scan, + item))), new Task(() => FinishedRenderingHeifHd?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "HEIF", "hd", false))), + "HEIF", "hd", false, scan, item))), new Task(() => FinishedRenderingAvif4kThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "AVIF", "4k", true))), + sourceFormat, "AVIF", "4k", true, + scan, item))), new Task(() => FinishedRenderingAvif1440Thumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "AVIF", "1440p", - true))), + sourceFormat, "AVIF", "1440p", true, + scan, item))), new Task(() => FinishedRenderingAvifHdThumbnail?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "AVIF", "hd", true))), + sourceFormat, "AVIF", "hd", true, + scan, item))), new Task(() => FinishedRenderingAvif4k?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "AVIF", "4k", false))), + "AVIF", "4k", false, scan, item))), new Task(() => FinishedRenderingAvif1440?.Invoke(Convert(webRootPath, id, originalFilePath, - sourceFormat, "AVIF", "1440p", false))), + sourceFormat, "AVIF", "1440p", false, scan, + item))), new Task(() => FinishedRenderingAvifHd?.Invoke(Convert(webRootPath, id, originalFilePath, sourceFormat, - "AVIF", "hd", false))) + "AVIF", "hd", false, scan, item))) }; foreach(Task thread in pool) diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 27e9411c..854c0a36 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 4.0.0.1833 + 4.0.0.1836 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Admin/Details/CreateMachinePhoto.razor.cs b/Marechai/Pages/Admin/Details/CreateMachinePhoto.razor.cs index f64aab66..f5d3e9c9 100644 --- a/Marechai/Pages/Admin/Details/CreateMachinePhoto.razor.cs +++ b/Marechai/Pages/Admin/Details/CreateMachinePhoto.razor.cs @@ -417,7 +417,8 @@ namespace Marechai.Pages.Admin.Details photos.FinishedRenderingAvifHdThumbnail += OnFinishedRenderingAvifHdThumbnail; #pragma warning disable 4014 - Task.Run(() => photos.ConversionWorker(Host.WebRootPath, _model.Id, originalFilePath, _imageFormat)); + Task.Run(() => photos.ConversionWorker(Host.WebRootPath, _model.Id, originalFilePath, _imageFormat, false, + "machines")); #pragma warning restore 4014 } diff --git a/Marechai/Program.cs b/Marechai/Program.cs index e26152c2..73e6eaca 100644 --- a/Marechai/Program.cs +++ b/Marechai/Program.cs @@ -213,7 +213,14 @@ namespace Marechai start = DateTime.Now; Console.WriteLine("\u001b[31;1mEnsuring photo folders exist...\u001b[0m"); - Photos.EnsureCreated("wwwroot"); + Photos.EnsureCreated("wwwroot", false, "machines"); + end = DateTime.Now; + + start = DateTime.Now; + Console.WriteLine("\u001b[31;1mEnsuring scan folders exist...\u001b[0m"); + Photos.EnsureCreated("wwwroot", true, "books"); + Photos.EnsureCreated("wwwroot", true, "documents"); + Photos.EnsureCreated("wwwroot", true, "magazines"); end = DateTime.Now; Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m", @@ -233,11 +240,11 @@ namespace Marechai host.Run(); } - public static IHost BuildHost(string[] args) => Host. - CreateDefaultBuilder(args). - ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup().UseUrls("http://*:5000"); - }).Build(); + public static IHost BuildHost(string[] args) => Host.CreateDefaultBuilder(args). + ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(). + UseUrls("http://*:5000"); + }).Build(); } } \ No newline at end of file