Create folders for scans.

This commit is contained in:
2020-08-14 01:54:21 +01:00
parent c5652cfb37
commit d4a0a95635
5 changed files with 110 additions and 85 deletions

View File

@@ -3,6 +3,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=claunia/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Exiftool/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=flif/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=heic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=heif/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ISSN/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=kibibytes/@EntryIndexedValue">True</s:Boolean>

View File

@@ -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<string> paths = new List<string>();
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<Task> pool = new List<Task>
{
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)

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>4.0.0.1833</Version>
<Version>4.0.0.1836</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>

View File

@@ -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
}

View File

@@ -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).
public static IHost BuildHost(string[] args) => Host.CreateDefaultBuilder(args).
ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().UseUrls("http://*:5000");
webBuilder.UseStartup<Startup>().
UseUrls("http://*:5000");
}).Build();
}
}