mirror of
https://github.com/SaphireLattice/quest-reader.git
synced 2026-11-12 18:40:36 -07:00
Implement lazy image loading (copied from freefall reader)
This commit is contained in:
7 files changed
+123
-5
No files matched your search
@@ -4,6 +4,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using QuestReader.Models;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
public class PostsSource
|
||||
{
|
||||
@@ -61,6 +62,20 @@ public class PostsSource
|
||||
Accepted.UnionWith(Posts.Where(p => referenced.Contains(p.Id)));
|
||||
Accepted = Accepted.OrderBy(p => p.Id).ToHashSet();
|
||||
|
||||
FileDownloader.DownloadList(BasePath, Metadata.AssetsBaseUrl, Accepted.Where(p => p.File is not null).Select(p => p.File!)).Wait();
|
||||
|
||||
foreach (var post in Accepted.Where(f => f.File is not null))
|
||||
{
|
||||
using var imageStream = File.OpenRead(Path.Combine(BasePath, "assets", post.File!));
|
||||
IImageInfo imageInfo = Image.Identify(imageStream);
|
||||
if (imageInfo is null) {
|
||||
Console.Out.WriteLine($"Not a valid image: {post.File!}");
|
||||
continue;
|
||||
}
|
||||
post.FileHeight = imageInfo.Height;
|
||||
post.FileWidth = imageInfo.Width;
|
||||
}
|
||||
|
||||
Console.Out.WriteLine($"Done loading with {Accepted.Count} posts, referencing {Accepted.Where(a => a.File is not null).Count()} files");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user