diff --git a/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs b/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs index 3eceea3..cd732a0 100644 --- a/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs +++ b/WebImageViewer/Class/Unified/Renderers/UnifiedHtmlRenderer.cs @@ -190,6 +190,161 @@ public static class UnifiedHtmlRenderer .header-search { display: none; } .unified-header { padding: 0 16px; } } + + /* ZIP進捗モーダルスタイル */ + .zip-modal-overlay { + display: none; + position: fixed; + inset: 0; + background: rgba(0, 0, 0, 0.75); + backdrop-filter: blur(8px); + -webkit-backdrop-filter: blur(8px); + z-index: 10000; + align-items: center; + justify-content: center; + padding: 20px; + opacity: 0; + transition: opacity 0.25s ease; + } + + .zip-modal-overlay.active { + display: flex; + opacity: 1; + } + + .zip-modal-card { + background: var(--bg-surface-elevated); + border: 1px solid var(--border-glow); + border-radius: 16px; + width: 100%; + max-width: 480px; + box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(99, 102, 241, 0.2); + overflow: hidden; + display: flex; + flex-direction: column; + animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1); + } + + @keyframes modalPop { + from { transform: scale(0.92) translateY(10px); opacity: 0; } + to { transform: scale(1) translateY(0); opacity: 1; } + } + + .zip-modal-header { + padding: 18px 24px; + background: rgba(0, 0, 0, 0.3); + border-bottom: 1px solid var(--border-subtle); + } + + .zip-modal-title { + font-size: 1.1rem; + font-weight: 700; + color: #fff; + display: flex; + align-items: center; + gap: 10px; + } + + .zip-spinner { + width: 18px; + height: 18px; + border: 2px solid rgba(255, 255, 255, 0.2); + border-top-color: var(--accent-primary); + border-radius: 50%; + animation: spin 0.8s linear infinite; + } + + .zip-spinner.done { + display: none; + } + + .zip-modal-body { + padding: 24px; + display: flex; + flex-direction: column; + gap: 12px; + } + + .zip-progress-track { + width: 100%; + height: 10px; + background: rgba(255, 255, 255, 0.08); + border-radius: 5px; + overflow: hidden; + position: relative; + } + + .zip-progress-bar { + height: 100%; + width: 0%; + background: var(--accent-gradient); + border-radius: 5px; + transition: width 0.2s ease; + } + + .zip-status-row { + display: flex; + justify-content: space-between; + align-items: center; + font-size: 0.85rem; + } + + .zip-status-text { + color: var(--text-muted); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 320px; + } + + .zip-percent-text { + font-weight: 700; + color: var(--accent-primary); + font-family: 'Outfit', monospace; + font-size: 0.95rem; + } + + .zip-counter-text { + font-size: 0.85rem; + color: var(--text-subtle); + font-family: 'Outfit', monospace; + } + + .zip-warning-text { + font-size: 0.8rem; + color: #f59e0b; + background: rgba(245, 158, 11, 0.1); + border: 1px solid rgba(245, 158, 11, 0.25); + padding: 6px 12px; + border-radius: 6px; + } + + .zip-modal-footer { + padding: 14px 24px; + background: rgba(0, 0, 0, 0.2); + border-top: 1px solid var(--border-subtle); + display: flex; + justify-content: flex-end; + } + + .zip-cancel-btn { + background: rgba(255, 255, 255, 0.08); + border: 1px solid var(--border-subtle); + color: var(--text-muted); + padding: 8px 18px; + border-radius: 8px; + font-size: 0.85rem; + font-weight: 600; + cursor: pointer; + transition: all 0.2s; + } + + .zip-cancel-btn:hover { + background: rgba(239, 68, 68, 0.2); + border-color: rgba(239, 68, 68, 0.4); + color: #ef4444; + } + """; #endregion @@ -1490,7 +1645,7 @@ public static class UnifiedHtmlRenderer
- + ZIP保存 @@ -2049,7 +2204,361 @@ public static class UnifiedHtmlRenderer } setPage(startPage, false); downloader.start(); + + // ZIPダウンロードボタン連携(保存先事前選択 & 進捗モーダル) + const headerZipBtn = document.getElementById('headerZipBtn'); + if (headerZipBtn) { + headerZipBtn.addEventListener('click', (e) => { + e.preventDefault(); + startZipDownloadWithProgress(galleryData); + }); + } + + +
+
+
+
+ + 📦 ZIP一括保存中... +
+
+
+
+
+
+
+ 画像を順次取得しています... + 0% +
+
0 / {{totalPages}} ページ
+ +
+ +
+
+ + + """; @@ -2075,6 +2584,12 @@ public static class UnifiedHtmlRenderer var encodedSourceUrl = Uri.EscapeDataString(gallery.SourceUrl); var totalPages = gallery.TotalPages; + var galleryJson = JsonSerializer.Serialize(gallery, new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }); + var metaBadges = new List { $"全 {totalPages} ページ" @@ -2407,7 +2922,7 @@ public static class UnifiedHtmlRenderer
- + ZIP保存 @@ -2439,7 +2954,7 @@ public static class UnifiedHtmlRenderer 📖 ビューアーで閲覧を開始する - + 📦 ZIP一括ダウンロード
@@ -2460,6 +2975,7 @@ public static class UnifiedHtmlRenderer + + +
+
+
+
+ + 📦 ZIP一括保存中... +
+
+
+
+
+
+
+ 画像を順次取得しています... + 0% +
+
0 / {{totalPages}} ページ
+ +
+ +
+
+ + + """; diff --git a/WebImageViewer/Program.cs b/WebImageViewer/Program.cs index 2aa4796..f5cda62 100644 --- a/WebImageViewer/Program.cs +++ b/WebImageViewer/Program.cs @@ -278,36 +278,57 @@ static async Task<(byte[]? Data, string? ContentType)> FetchImageBytesForZipAsyn UnifiedHttpHelper httpHelper, CancellationToken ct) { - try - { - string targetUrl = imageUrl; - string? targetReferer = defaultReferer; + string targetUrl = imageUrl; + string? targetReferer = defaultReferer; - // /api/proxy-image?... 形式の場合は内部パラメータを展開して直接取得 - if (imageUrl.StartsWith("/api/proxy-image", StringComparison.OrdinalIgnoreCase)) + // /api/proxy-image?... 形式の場合は内部パラメータを展開して直接取得 + if (imageUrl.StartsWith("/api/proxy-image", StringComparison.OrdinalIgnoreCase)) + { + var qIndex = imageUrl.IndexOf('?'); + if (qIndex >= 0) { - var qIndex = imageUrl.IndexOf('?'); - if (qIndex >= 0) + var qs = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(imageUrl.Substring(qIndex)); + if (qs.TryGetValue("url", out var u) && !string.IsNullOrEmpty(u)) { - var qs = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(imageUrl.Substring(qIndex)); - if (qs.TryGetValue("url", out var u) && !string.IsNullOrEmpty(u)) - { - targetUrl = u.ToString(); - } - if (qs.TryGetValue("referer", out var r) && !string.IsNullOrEmpty(r)) - { - targetReferer = r.ToString(); - } + targetUrl = u.ToString(); + } + if (qs.TryGetValue("referer", out var r) && !string.IsNullOrEmpty(r)) + { + targetReferer = r.ToString(); } } + } - var (data, contentType) = await httpHelper.GetBinaryAsync(targetUrl, targetReferer, ct); - return (data, contentType); - } - catch + // 最大3回リトライを行い、一時的なネットワーク揺らぎによるページ抜けを徹底防止 + for (int attempt = 1; attempt <= 3; attempt++) { - return (null, null); + try + { + var (data, contentType) = await httpHelper.GetBinaryAsync(targetUrl, targetReferer, ct); + if (data != null && data.Length > 0) + { + return (data, contentType); + } + } + catch (OperationCanceledException) + { + throw; + } + catch + { + if (attempt == 3) break; + try + { + await Task.Delay(attempt * 1000, ct); + } + catch (OperationCanceledException) + { + throw; + } + } } + + return (null, null); } static string DetermineImageExtensionForZip(string? contentType, string imageUrl)