Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
40 changes: 37 additions & 3 deletions src/commands/previewAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ function registerPreview(context: vscode.ExtensionContext) {
a:hover {
text-decoration: underline;
}

.copy-btn {
background-color: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 0.25rem 0.5rem;
border-radius: 4px;
cursor: pointer;
font-size: 0.85rem;
margin-left: 0.5rem;
}

.copy-btn:hover {
background-color: var(--vscode-button-hoverBackground);
}

.copy-btn:active {
background-color: var(--vscode-button-activeBackground);
}
</style>
</head>
<body>
Expand All @@ -125,7 +144,7 @@ function registerPreview(context: vscode.ExtensionContext) {
</nav>

<div class="tab-content active" id="tab-info">
<p><strong>Public ID:</strong> ${asset.public_id}</p>
<p><strong>Public ID:</strong> ${asset.public_id} <button class="copy-btn" data-copy="${asset.public_id}">Copy</button></p>
<p><strong>Original filename:</strong> ${asset.filename}</p>
<p><strong>Dimensions:</strong> ${asset.width} x ${asset.height}</p>
<p><strong>Size:</strong> ${(asset.bytes / 1024).toFixed(2)} KB</p>
Expand Down Expand Up @@ -156,8 +175,8 @@ function registerPreview(context: vscode.ExtensionContext) {
</div>

<div class="tab-content" id="tab-urls">
<p><strong>Original URL:</strong> <a href="${asset.secure_url}" target="_blank">${asset.secure_url}</a></p>
<p><strong>Optimized URL:</strong> <a href="${asset.optimized_url}" target="_blank">${asset.optimized_url}</a></p>
<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>
<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>
</div>
</div>

Expand All @@ -175,6 +194,21 @@ function registerPreview(context: vscode.ExtensionContext) {
if (target) target.classList.add("active");
});
});

// Copy button functionality
const copyButtons = document.querySelectorAll(".copy-btn");
copyButtons.forEach((btn) => {
btn.addEventListener("click", () => {
const textToCopy = btn.getAttribute("data-copy");
navigator.clipboard.writeText(textToCopy).then(() => {
const originalText = btn.textContent;
btn.textContent = "Copied!";
setTimeout(() => {
btn.textContent = originalText;
}, 2000);
});
});
});
</script>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import registerLoadMore from "./loadMoreAssets";
import registerUpload from "./uploadWidget";
import registerClipboard from "./copyCommands";
import registerSwitchEnv from "./switchEnvironment";
import registerClearSearch from "./clearSeach";
import registerClearSearch from "./clearSearch";
import registerWelcomeScreen from "./welcomeScreen";
import { CloudinaryTreeDataProvider } from "../tree/treeDataProvider";

Expand Down
9 changes: 6 additions & 3 deletions src/tree/cloudinaryItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class CloudinaryItem extends vscode.TreeItem {
: cloudinary.url(data.public_id, {
resource_type: assetType,
type: data.type,
transformation: [{ fetch_format: 'auto' }, { quality: 'auto' }],
transformation: [
{ fetch_format: assetType === 'video' ? 'auto:video' : 'auto' },
{ quality: 'auto' }
],
});

data.optimized_url = optimizedUrl;
Expand Down Expand Up @@ -130,15 +133,15 @@ class CloudinaryItem extends vscode.TreeItem {
}

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

function formatFileSize(bytes: number): string {
if (bytes === 0) {return '0 B';}
if (bytes === 0) { return '0 B'; }
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
Expand Down