Skip to content

Commit a6953d1

Browse files
authored
Merge pull request #2 from cloudinary-devs/fix/preview-and-video-enhancements
Fix/preview and video enhancements
2 parents 7c7bcbd + 2fda825 commit a6953d1

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/commands/previewAsset.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ function registerPreview(context: vscode.ExtensionContext) {
111111
a:hover {
112112
text-decoration: underline;
113113
}
114+
115+
.copy-btn {
116+
background-color: var(--vscode-button-background);
117+
color: var(--vscode-button-foreground);
118+
border: none;
119+
padding: 0.25rem 0.5rem;
120+
border-radius: 4px;
121+
cursor: pointer;
122+
font-size: 0.85rem;
123+
margin-left: 0.5rem;
124+
}
125+
126+
.copy-btn:hover {
127+
background-color: var(--vscode-button-hoverBackground);
128+
}
129+
130+
.copy-btn:active {
131+
background-color: var(--vscode-button-activeBackground);
132+
}
114133
</style>
115134
</head>
116135
<body>
@@ -125,7 +144,7 @@ function registerPreview(context: vscode.ExtensionContext) {
125144
</nav>
126145
127146
<div class="tab-content active" id="tab-info">
128-
<p><strong>Public ID:</strong> ${asset.public_id}</p>
147+
<p><strong>Public ID:</strong> ${asset.public_id} <button class="copy-btn" data-copy="${asset.public_id}">Copy</button></p>
129148
<p><strong>Original filename:</strong> ${asset.filename}</p>
130149
<p><strong>Dimensions:</strong> ${asset.width} x ${asset.height}</p>
131150
<p><strong>Size:</strong> ${(asset.bytes / 1024).toFixed(2)} KB</p>
@@ -156,8 +175,8 @@ function registerPreview(context: vscode.ExtensionContext) {
156175
</div>
157176
158177
<div class="tab-content" id="tab-urls">
159-
<p><strong>Original URL:</strong> <a href="${asset.secure_url}" target="_blank">${asset.secure_url}</a></p>
160-
<p><strong>Optimized URL:</strong> <a href="${asset.optimized_url}" target="_blank">${asset.optimized_url}</a></p>
178+
<p><strong>Original URL:</strong> <a href="${asset.secure_url}" target="_blank">${asset.secure_url}</a> <button class="copy-btn" data-copy="${asset.secure_url}">Copy</button></p>
179+
<p><strong>Optimized URL:</strong> <a href="${asset.optimized_url}" target="_blank">${asset.optimized_url}</a> <button class="copy-btn" data-copy="${asset.optimized_url}">Copy</button></p>
161180
</div>
162181
</div>
163182
@@ -175,6 +194,21 @@ function registerPreview(context: vscode.ExtensionContext) {
175194
if (target) target.classList.add("active");
176195
});
177196
});
197+
198+
// Copy button functionality
199+
const copyButtons = document.querySelectorAll(".copy-btn");
200+
copyButtons.forEach((btn) => {
201+
btn.addEventListener("click", () => {
202+
const textToCopy = btn.getAttribute("data-copy");
203+
navigator.clipboard.writeText(textToCopy).then(() => {
204+
const originalText = btn.textContent;
205+
btn.textContent = "Copied!";
206+
setTimeout(() => {
207+
btn.textContent = originalText;
208+
}, 2000);
209+
});
210+
});
211+
});
178212
</script>
179213
</body>
180214
</html>

src/commands/registerCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import registerLoadMore from "./loadMoreAssets";
66
import registerUpload from "./uploadWidget";
77
import registerClipboard from "./copyCommands";
88
import registerSwitchEnv from "./switchEnvironment";
9-
import registerClearSearch from "./clearSeach";
9+
import registerClearSearch from "./clearSearch";
1010
import registerWelcomeScreen from "./welcomeScreen";
1111
import { CloudinaryTreeDataProvider } from "../tree/treeDataProvider";
1212

src/tree/cloudinaryItem.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ class CloudinaryItem extends vscode.TreeItem {
6666
: cloudinary.url(data.public_id, {
6767
resource_type: assetType,
6868
type: data.type,
69-
transformation: [{ fetch_format: 'auto' }, { quality: 'auto' }],
69+
transformation: [
70+
{ fetch_format: assetType === 'video' ? 'auto:video' : 'auto' },
71+
{ quality: 'auto' }
72+
],
7073
});
7174

7275
data.optimized_url = optimizedUrl;
@@ -130,15 +133,15 @@ class CloudinaryItem extends vscode.TreeItem {
130133
}
131134

132135
function truncateLabel(label: string, maxLength: number = 20): string {
133-
if (label.length <= maxLength) {return label;}
136+
if (label.length <= maxLength) { return label; }
134137
const extension = label.includes('.') ? label.split('.').pop() : '';
135138
const nameWithoutExt = extension ? label.slice(0, -(extension.length + 1)) : label;
136139
const truncatedName = nameWithoutExt.slice(0, maxLength - 3) + '...';
137140
return extension ? `${truncatedName}.${extension}` : truncatedName;
138141
}
139142

140143
function formatFileSize(bytes: number): string {
141-
if (bytes === 0) {return '0 B';}
144+
if (bytes === 0) { return '0 B'; }
142145
const k = 1024;
143146
const sizes = ['B', 'KB', 'MB', 'GB'];
144147
const i = Math.floor(Math.log(bytes) / Math.log(k));

0 commit comments

Comments
 (0)