diff --git a/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs b/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs index 155d1dc..addb71b 100644 --- a/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs +++ b/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs @@ -1490,6 +1490,10 @@ public static class UnifiedHtmlRenderer
+ + + サムネイル一覧 + 元サイトを開く ↗ @@ -2032,8 +2036,14 @@ public static class UnifiedHtmlRenderer } }); - // 初期化:1ページ目を設定し、順次バックグラウンドダウンロードを開始 - setPage(1, false); + // 初期化:URLパラメータやハッシュで指定されたページ、または1ページ目を設定 + const urlParams = new URLSearchParams(window.location.search); + let startPage = parseInt(urlParams.get('page')) || 1; + if (window.location.hash.startsWith('#page-')) { + const hashPage = parseInt(window.location.hash.replace('#page-', '')); + if (!isNaN(hashPage)) startPage = hashPage; + } + setPage(startPage, false); downloader.start(); @@ -2043,6 +2053,424 @@ public static class UnifiedHtmlRenderer #endregion + #region サムネイル一覧画面生成 (RenderThumbnailGridPage) + + /// + /// ギャラリー全ページのサムネイルを一覧表示するグリッド画面を生成します。 + /// + /// ギャラリー詳細情報 + /// サムネイル一覧画面の完全なHTML + public static string RenderThumbnailGridPage(UnifiedGalleryItem gallery) + { + var safeTitle = Encoder.Encode(gallery.Title); + var safeCategory = !string.IsNullOrEmpty(gallery.Category) ? Encoder.Encode(gallery.Category) : null; + var safeCircle = !string.IsNullOrEmpty(gallery.Circle) ? Encoder.Encode(gallery.Circle) : null; + var safeAuthor = !string.IsNullOrEmpty(gallery.Author) ? Encoder.Encode(gallery.Author) : null; + var safeSite = Encoder.Encode(gallery.SourceSite); + var safeUrl = Encoder.Encode(gallery.SourceUrl); + var encodedSourceUrl = Uri.EscapeDataString(gallery.SourceUrl); + var totalPages = gallery.TotalPages; + + var metaBadges = new List + { + $"全 {totalPages} ページ" + }; + if (!string.IsNullOrEmpty(safeCategory)) metaBadges.Add($"{safeCategory}"); + if (!string.IsNullOrEmpty(safeAuthor)) metaBadges.Add($"👤 {safeAuthor}"); + if (!string.IsNullOrEmpty(safeCircle)) metaBadges.Add($"🏛️ {safeCircle}"); + if (!string.IsNullOrEmpty(safeSite)) metaBadges.Add($"🌐 {safeSite}"); + var metaBadgesHtml = string.Join("\n ", metaBadges); + + var tagsHtml = string.Empty; + if (gallery.Tags.Count > 0) + { + var tagItems = string.Join("\n", gallery.Tags.Select(t => $"#{Encoder.Encode(t)}")); + tagsHtml = $"
{tagItems}
"; + } + + var gridItemsHtml = string.Join("\n", gallery.Images.Select(img => + { + var thumbUrl = Encoder.Encode(img.ThumbnailUrl ?? img.ImageUrl); + var pageNum = img.PageNumber; + return $$""" + +
+ ページ {{pageNum}} + {{pageNum}} +
+
+ P. {{pageNum}} + 開く ↗ +
+
+ """; + })); + + return $$""" + + + + + + サムネイル一覧: {{safeTitle}} (全{{totalPages}}ページ) - WebImageViewer + + + + + + +
+ + + WebImageViewer + + + + + + +
+ +
+
+ + + {{tagsHtml}} + + +
+
+ +
+
+ ページをクリックすると、ビューアーでそのページが開きます + 全 {{totalPages}} 枚 +
+ +
+ {{gridItemsHtml}} +
+
+ + + + + + +"""; + } + + #endregion + #region エラー画面生成 (RenderErrorPage) public static string RenderErrorPage(string message, int statusCode = 404) diff --git a/WebImageViewer/Program.cs b/WebImageViewer/Program.cs index 5428294..8fcfd30 100644 --- a/WebImageViewer/Program.cs +++ b/WebImageViewer/Program.cs @@ -46,7 +46,7 @@ app.UseForwardedHeaders(); // ========================================== // 統一アクセス方式 (/?url=[各ページURL]) // ========================================== -app.MapGet("/", async (string? url, string? play, string? stream, UnifiedViewerService viewerService, CancellationToken ct) => +app.MapGet("/", async (string? url, string? play, string? stream, string? view, UnifiedViewerService viewerService, CancellationToken ct) => { // URLパラメータが未指定(かつplay/streamも未指定)の場合は統一トップページを表示 if (string.IsNullOrWhiteSpace(url) && string.IsNullOrWhiteSpace(play) && string.IsNullOrWhiteSpace(stream)) @@ -71,9 +71,13 @@ app.MapGet("/", async (string? url, string? play, string? stream, UnifiedViewerS return Results.Content(UnifiedHtmlRenderer.RenderVideoViewer(result.Video), "text/html; charset=utf-8"); } - // 画像の場合はギャラリービューアー画面を同一URLのままレンダリング + // 画像の場合はギャラリービューアー画面またはサムネイル一覧画面をレンダリング if (result.Type == MediaType.Gallery && result.Gallery != null) { + if (string.Equals(view, "thumbnails", StringComparison.OrdinalIgnoreCase)) + { + return Results.Content(UnifiedHtmlRenderer.RenderThumbnailGridPage(result.Gallery), "text/html; charset=utf-8"); + } return Results.Content(UnifiedHtmlRenderer.RenderGalleryViewer(result.Gallery), "text/html; charset=utf-8"); } @@ -83,6 +87,28 @@ app.MapGet("/", async (string? url, string? play, string? stream, UnifiedViewerS statusCode: 404); }); +// ========================================== +// 全ページサムネイル一覧画面エンドポイント +// ========================================== +app.MapGet("/thumbnails", async (string? url, UnifiedViewerService viewerService, CancellationToken ct) => +{ + if (string.IsNullOrWhiteSpace(url)) + { + return Results.Redirect("/"); + } + + var result = await viewerService.ResolveAsync(url, null, null, ct); + if (!result.IsSuccess || result.Gallery == null) + { + return Results.Content( + UnifiedHtmlRenderer.RenderErrorPage(result.ErrorMessage ?? "ギャラリーを読み込めませんでした。", result.StatusCode), + "text/html; charset=utf-8", + statusCode: result.StatusCode); + } + + return Results.Content(UnifiedHtmlRenderer.RenderThumbnailGridPage(result.Gallery), "text/html; charset=utf-8"); +}); + // ========================================== // 画像プロキシAPI (Referer制限回避・高速キャッシュ配信) // ========================================== @@ -139,4 +165,4 @@ app.MapMethods("/api/proxy-embed-req", new[] { "GET", "POST", "HEAD" }, async (s // ========================================== app.MapLegacyEndpoints(); -app.Run(); \ No newline at end of file +app.Run();