|
1 | 1 | // Shared function to handle WARC file detection and viewing |
2 | | -async function handleWarcFileAction(node) { |
| 2 | +function handleWarcFileAction(node) { |
3 | 3 | console.log("Checking node for WARC compatibility:", node); |
4 | 4 |
|
5 | | - // Check if it's a WARC-compatible file |
| 5 | + // Check if it's a WARC-compatible file FIRST |
6 | 6 | const fileName = node.getLabel(); |
7 | 7 | const isWarcCompatible = fileName.match(/\.(warc|warc\.gz|wacz)$/i); |
8 | 8 |
|
9 | 9 | if (!isWarcCompatible) { |
10 | 10 | console.log("Not a WARC-compatible file, ignoring"); |
11 | | - return false; // Return false to indicate we didn't handle it |
| 11 | + return false; // Return false immediately - don't block anything |
12 | 12 | } |
13 | 13 |
|
14 | 14 | console.log("WARC-compatible file detected, launching viewer"); |
15 | 15 |
|
16 | | - // Get the file URL using your existing logic |
17 | | - const fileUrl = await PydioApi._PydioClient.buildPresignedGetUrl(node); |
| 16 | + // Check if it's a WACZ file (skip options) or WARC file (show options) |
| 17 | + const isWaczFile = fileName.match(/\.wacz$/i); |
18 | 18 |
|
19 | | - // Create and show the WARC options modal |
20 | | - const optionsModal = Curate.ui.modals.curatePopup( |
21 | | - { |
22 | | - title: "Preview Web Archive", |
23 | | - }, |
24 | | - { |
25 | | - afterLoaded: (container) => { |
26 | | - const mainContent = container.querySelector( |
27 | | - ".config-main-options-container" |
| 19 | + // Handle the async URL generation |
| 20 | + (async () => { |
| 21 | + try { |
| 22 | + const fileUrl = await PydioApi._PydioClient.buildPresignedGetUrl(node); |
| 23 | + |
| 24 | + if (isWaczFile) { |
| 25 | + // Skip options for WACZ files - go straight to viewer |
| 26 | + const viewerModal = Curate.ui.modals.curatePopup( |
| 27 | + { |
| 28 | + title: "Preview Web-Archive", |
| 29 | + }, |
| 30 | + { |
| 31 | + afterLoaded: (container) => { |
| 32 | + // Style the popup for maximum size |
| 33 | + const modalContent = container.querySelector( |
| 34 | + ".config-modal-content" |
| 35 | + ); |
| 36 | + if (modalContent) { |
| 37 | + modalContent.style.width = "95vw"; |
| 38 | + modalContent.style.height = "90vh"; |
| 39 | + modalContent.style.maxWidth = "1400px"; |
| 40 | + modalContent.style.maxHeight = "900px"; |
| 41 | + modalContent.style.padding = "16px"; |
| 42 | + } |
| 43 | + // Find the main content container and update it |
| 44 | + const mainContent = container.querySelector( |
| 45 | + ".config-main-options-container" |
| 46 | + ); |
| 47 | + if (mainContent) { |
| 48 | + // Style the main content to take full space |
| 49 | + mainContent.style.height = "100%"; |
| 50 | + mainContent.style.display = "flex"; |
| 51 | + mainContent.style.flexDirection = "column"; |
| 52 | + // Create wrapper with border radius |
| 53 | + const viewerWrapper = document.createElement("div"); |
| 54 | + viewerWrapper.style.cssText = ` |
| 55 | + flex: 1; |
| 56 | + border-radius: 12px; |
| 57 | + overflow: hidden; |
| 58 | + border: 1px solid var(--md-sys-color-outline-variant); |
| 59 | + background: var(--md-sys-color-surface); |
| 60 | + `; |
| 61 | + // Clear existing content and add the replay component inside wrapper |
| 62 | + mainContent.innerHTML = ""; |
| 63 | + viewerWrapper.innerHTML = `<replay-web-page |
| 64 | + source="${fileUrl}" |
| 65 | + url="" |
| 66 | + replayBase="/workers/" |
| 67 | + embed="default" |
| 68 | + style="width: 100%; height: 100%; display: block; border-radius: inherit;"> |
| 69 | + </replay-web-page>`; |
| 70 | + mainContent.appendChild(viewerWrapper); |
| 71 | + } |
| 72 | + }, |
| 73 | + } |
28 | 74 | ); |
29 | | - if (mainContent) { |
30 | | - const warcOptions = document.createElement("warc-options-modal"); |
31 | | - warcOptions.setFileInfo(fileUrl, fileName); |
32 | | - warcOptions.closeSelf = optionsModal.close; |
33 | | - mainContent.appendChild(warcOptions); |
34 | | - } |
35 | | - }, |
| 75 | + // Fire the viewer modal |
| 76 | + viewerModal.fire(); |
| 77 | + } else { |
| 78 | + // Show options modal for WARC files |
| 79 | + const optionsModal = Curate.ui.modals.curatePopup( |
| 80 | + { |
| 81 | + title: "Preview Web Archive", |
| 82 | + }, |
| 83 | + { |
| 84 | + afterLoaded: (container) => { |
| 85 | + const mainContent = container.querySelector( |
| 86 | + ".config-main-options-container" |
| 87 | + ); |
| 88 | + if (mainContent) { |
| 89 | + const warcOptions = |
| 90 | + document.createElement("warc-options-modal"); |
| 91 | + warcOptions.setFileInfo(fileUrl, fileName); |
| 92 | + warcOptions.closeSelf = optionsModal.close; |
| 93 | + mainContent.appendChild(warcOptions); |
| 94 | + } |
| 95 | + }, |
| 96 | + } |
| 97 | + ); |
| 98 | + |
| 99 | + optionsModal.fire(); |
| 100 | + } |
| 101 | + } catch (error) { |
| 102 | + console.error("Error building presigned URL:", error); |
36 | 103 | } |
37 | | - ); |
| 104 | + })(); |
38 | 105 |
|
39 | | - optionsModal.fire(); |
40 | | - return true; // Return true to indicate we handled it |
| 106 | + return true; // Block propagation immediately for WARC files |
41 | 107 | } |
42 | 108 |
|
43 | 109 | // Event handler for "open" button clicks (your original working code) |
|
0 commit comments