|
| 1 | +@using TelegramDownloader.Data |
| 2 | +@using TelegramDownloader.Models |
| 3 | +@using TelegramDownloader.Shared |
| 4 | + |
| 5 | +@inject IFileService fs |
| 6 | +@inject NavigationManager MyNavigationManager |
| 7 | + |
| 8 | +<div class="modal @ModalClass" tabindex="-1" role="dialog" style="display:@ModalDisplay"> |
| 9 | + <div class="modal-dialog modal-dialog-centered" role="document"> |
| 10 | + <div class="modal-content download-modal"> |
| 11 | + <!-- Header --> |
| 12 | + <div class="modal-header download-modal-header"> |
| 13 | + <div class="modal-title-wrapper"> |
| 14 | + <div class="modal-icon"> |
| 15 | + <i class="bi bi-file-earmark-play"></i> |
| 16 | + </div> |
| 17 | + <div> |
| 18 | + <h5 class="modal-title">Export STRM Files</h5> |
| 19 | + <p class="modal-subtitle">Choose export method for @folderName</p> |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + <button type="button" class="btn-close-modal" @onclick="() => Close()" aria-label="Close"> |
| 23 | + <i class="bi bi-x-lg"></i> |
| 24 | + </button> |
| 25 | + </div> |
| 26 | + |
| 27 | + <!-- Body --> |
| 28 | + <div class="modal-body download-modal-body"> |
| 29 | + @if (ShowBackdrop) |
| 30 | + { |
| 31 | + <div class="export-options"> |
| 32 | + <!-- Option 1: Download ZIP --> |
| 33 | + <div class="export-option-card @(selectedOption == ExportOption.DownloadZip ? "selected" : "")" |
| 34 | + @onclick="() => SelectOption(ExportOption.DownloadZip)"> |
| 35 | + <div class="option-icon"> |
| 36 | + <i class="bi bi-file-earmark-zip"></i> |
| 37 | + </div> |
| 38 | + <div class="option-content"> |
| 39 | + <h6 class="option-title">Download as ZIP</h6> |
| 40 | + <p class="option-description">Download all STRM files compressed in a ZIP file</p> |
| 41 | + </div> |
| 42 | + <div class="option-check"> |
| 43 | + @if (selectedOption == ExportOption.DownloadZip) |
| 44 | + { |
| 45 | + <i class="bi bi-check-circle-fill"></i> |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + <i class="bi bi-circle"></i> |
| 50 | + } |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + |
| 54 | + <!-- Option 2: Export to Local Folder --> |
| 55 | + <div class="export-option-card @(selectedOption == ExportOption.ExportToLocal ? "selected" : "")" |
| 56 | + @onclick="() => SelectOption(ExportOption.ExportToLocal)"> |
| 57 | + <div class="option-icon"> |
| 58 | + <i class="bi bi-folder2-open"></i> |
| 59 | + </div> |
| 60 | + <div class="option-content"> |
| 61 | + <h6 class="option-title">Export to Local Folder</h6> |
| 62 | + <p class="option-description">Generate STRM files directly in a local directory</p> |
| 63 | + </div> |
| 64 | + <div class="option-check"> |
| 65 | + @if (selectedOption == ExportOption.ExportToLocal) |
| 66 | + { |
| 67 | + <i class="bi bi-check-circle-fill"></i> |
| 68 | + } |
| 69 | + else |
| 70 | + { |
| 71 | + <i class="bi bi-circle"></i> |
| 72 | + } |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + |
| 76 | + <!-- Folder Selection (only visible when ExportToLocal is selected) --> |
| 77 | + @if (selectedOption == ExportOption.ExportToLocal) |
| 78 | + { |
| 79 | + <div class="form-section folder-section mt-3"> |
| 80 | + <label class="section-label"> |
| 81 | + <i class="bi bi-folder"></i> |
| 82 | + Destination Folder |
| 83 | + </label> |
| 84 | + <TelegramDownloader.Shared.Ddtree idTree="strmtree" @ref="ddtree" /> |
| 85 | + </div> |
| 86 | + } |
| 87 | + </div> |
| 88 | + } |
| 89 | + </div> |
| 90 | + |
| 91 | + <!-- Footer --> |
| 92 | + <div class="modal-footer download-modal-footer"> |
| 93 | + <button type="button" class="btn btn-cancel" @onclick="() => Close()"> |
| 94 | + <i class="bi bi-x"></i> |
| 95 | + Cancel |
| 96 | + </button> |
| 97 | + <button type="button" class="btn btn-download" @onclick="() => Submit()" disabled="@isExporting"> |
| 98 | + @if (isExporting) |
| 99 | + { |
| 100 | + <span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span> |
| 101 | + <span>Exporting...</span> |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + <i class="bi @(selectedOption == ExportOption.DownloadZip ? "bi-download" : "bi-folder-check")"></i> |
| 106 | + <span>@(selectedOption == ExportOption.DownloadZip ? "Download" : "Export")</span> |
| 107 | + } |
| 108 | + </button> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | +</div> |
| 113 | + |
| 114 | +@if (ShowBackdrop) |
| 115 | +{ |
| 116 | + <div class="modal-backdrop fade show"></div> |
| 117 | +} |
| 118 | + |
| 119 | +<style> |
| 120 | + .export-options { |
| 121 | + display: flex; |
| 122 | + flex-direction: column; |
| 123 | + gap: 12px; |
| 124 | + } |
| 125 | +
|
| 126 | + .export-option-card { |
| 127 | + display: flex; |
| 128 | + align-items: center; |
| 129 | + padding: 16px; |
| 130 | + border: 2px solid var(--border-color, #e0e0e0); |
| 131 | + border-radius: 12px; |
| 132 | + cursor: pointer; |
| 133 | + transition: all 0.2s ease; |
| 134 | + background: var(--card-bg, #fff); |
| 135 | + } |
| 136 | +
|
| 137 | + .export-option-card:hover { |
| 138 | + border-color: var(--primary-color, #0d6efd); |
| 139 | + background: var(--hover-bg, #f8f9fa); |
| 140 | + } |
| 141 | +
|
| 142 | + .export-option-card.selected { |
| 143 | + border-color: var(--primary-color, #0d6efd); |
| 144 | + background: var(--selected-bg, #e7f1ff); |
| 145 | + } |
| 146 | +
|
| 147 | + .option-icon { |
| 148 | + width: 48px; |
| 149 | + height: 48px; |
| 150 | + display: flex; |
| 151 | + align-items: center; |
| 152 | + justify-content: center; |
| 153 | + background: var(--icon-bg, #f0f0f0); |
| 154 | + border-radius: 10px; |
| 155 | + margin-right: 16px; |
| 156 | + } |
| 157 | +
|
| 158 | + .option-icon i { |
| 159 | + font-size: 24px; |
| 160 | + color: var(--primary-color, #0d6efd); |
| 161 | + } |
| 162 | +
|
| 163 | + .option-content { |
| 164 | + flex: 1; |
| 165 | + } |
| 166 | +
|
| 167 | + .option-title { |
| 168 | + margin: 0 0 4px 0; |
| 169 | + font-weight: 600; |
| 170 | + color: var(--text-primary, #212529); |
| 171 | + } |
| 172 | +
|
| 173 | + .option-description { |
| 174 | + margin: 0; |
| 175 | + font-size: 13px; |
| 176 | + color: var(--text-secondary, #6c757d); |
| 177 | + } |
| 178 | +
|
| 179 | + .option-check i { |
| 180 | + font-size: 20px; |
| 181 | + color: var(--primary-color, #0d6efd); |
| 182 | + } |
| 183 | +
|
| 184 | + .folder-section { |
| 185 | + padding-top: 12px; |
| 186 | + border-top: 1px solid var(--border-color, #e0e0e0); |
| 187 | + } |
| 188 | +
|
| 189 | + .section-label { |
| 190 | + display: flex; |
| 191 | + align-items: center; |
| 192 | + gap: 8px; |
| 193 | + font-weight: 500; |
| 194 | + margin-bottom: 8px; |
| 195 | + color: var(--text-primary, #212529); |
| 196 | + } |
| 197 | +</style> |
| 198 | + |
| 199 | +@code { |
| 200 | + public enum ExportOption |
| 201 | + { |
| 202 | + DownloadZip, |
| 203 | + ExportToLocal |
| 204 | + } |
| 205 | + |
| 206 | + public Ddtree? ddtree { get; set; } |
| 207 | + private ExportOption selectedOption = ExportOption.DownloadZip; |
| 208 | + private bool isExporting = false; |
| 209 | + |
| 210 | + public string ModalDisplay = "none;"; |
| 211 | + public string ModalClass = ""; |
| 212 | + public bool ShowBackdrop = false; |
| 213 | + |
| 214 | + private string channelId = ""; |
| 215 | + private string path = ""; |
| 216 | + private string folderName = ""; |
| 217 | + private string host = ""; |
| 218 | + |
| 219 | + [Parameter] |
| 220 | + public EventCallback<string> OnExportCompleted { get; set; } |
| 221 | + |
| 222 | + public void Open(string channelId, string path, string host) |
| 223 | + { |
| 224 | + this.channelId = channelId; |
| 225 | + this.path = path; |
| 226 | + this.host = host; |
| 227 | + this.folderName = Path.GetFileName(path.TrimEnd('/')); |
| 228 | + this.selectedOption = ExportOption.DownloadZip; |
| 229 | + this.isExporting = false; |
| 230 | + |
| 231 | + ModalDisplay = "block;"; |
| 232 | + ModalClass = "Show"; |
| 233 | + ShowBackdrop = true; |
| 234 | + StateHasChanged(); |
| 235 | + } |
| 236 | + |
| 237 | + public void Close() |
| 238 | + { |
| 239 | + ModalDisplay = "none"; |
| 240 | + ModalClass = ""; |
| 241 | + ShowBackdrop = false; |
| 242 | + StateHasChanged(); |
| 243 | + } |
| 244 | + |
| 245 | + private void SelectOption(ExportOption option) |
| 246 | + { |
| 247 | + selectedOption = option; |
| 248 | + StateHasChanged(); |
| 249 | + } |
| 250 | + |
| 251 | + private async Task Submit() |
| 252 | + { |
| 253 | + if (selectedOption == ExportOption.DownloadZip) |
| 254 | + { |
| 255 | + // Navigate to download ZIP (existing behavior) |
| 256 | + MyNavigationManager.NavigateTo($"/api/file/strm?idChannel={channelId}&path={path}&host={host}", true); |
| 257 | + Close(); |
| 258 | + } |
| 259 | + else |
| 260 | + { |
| 261 | + // Export to local folder |
| 262 | + var selectedFolder = ddtree?.selectedNode?.FirstOrDefault(); |
| 263 | + if (string.IsNullOrEmpty(selectedFolder)) |
| 264 | + { |
| 265 | + return; |
| 266 | + } |
| 267 | + |
| 268 | + isExporting = true; |
| 269 | + StateHasChanged(); |
| 270 | + |
| 271 | + try |
| 272 | + { |
| 273 | + await fs.CreateStrmFilesToLocal(path, channelId, host, selectedFolder); |
| 274 | + await OnExportCompleted.InvokeAsync($"STRM files exported successfully to {selectedFolder}"); |
| 275 | + } |
| 276 | + catch (Exception ex) |
| 277 | + { |
| 278 | + await OnExportCompleted.InvokeAsync($"Error exporting STRM files: {ex.Message}"); |
| 279 | + } |
| 280 | + finally |
| 281 | + { |
| 282 | + isExporting = false; |
| 283 | + Close(); |
| 284 | + } |
| 285 | + } |
| 286 | + } |
| 287 | +} |
0 commit comments