☁️ CloudShare
Secure file sharing made simple
📤 Upload Files
📂 My Files
Shared File Link Accessed
File: ${decodeURIComponent(fileName)}
This is a demo environment. Files are stored locally per session.
The original file owner needs to share it from their active session.
`;
} else {
fileGrid.innerHTML = `
`;
}
return;
}
fileGrid.innerHTML = filteredFiles.map(file => `
Downloads: ${file.downloads}
`).join(”);
}
function getFileIcon(mimeType) {
if (mimeType.startsWith(‘image/’)) return ‘🖼️’;
if (mimeType.startsWith(‘video/’)) return ‘🎥’;
if (mimeType.startsWith(‘audio/’)) return ‘🎵’;
if (mimeType.includes(‘pdf’)) return ‘📄’;
if (mimeType.includes(‘word’) || mimeType.includes(‘document’)) return ‘📝’;
if (mimeType.includes(‘spreadsheet’) || mimeType.includes(‘excel’)) return ‘📊’;
if (mimeType.includes(‘presentation’) || mimeType.includes(‘powerpoint’)) return ‘📈’;
if (mimeType.includes(‘zip’) || mimeType.includes(‘rar’)) return ‘🗜️’;
return ‘📎’;
}
function formatFileSize(bytes) {
if (bytes === 0) return ‘0 Bytes’;
const k = 1024;
const sizes = [‘Bytes’, ‘KB’, ‘MB’, ‘GB’];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ‘ ‘ + sizes[i];
}
function formatDate(date) {
return date.toLocaleDateString(‘en-US’, {
year: ‘numeric’,
month: ‘short’,
day: ‘numeric’
});
}
function downloadFile(fileId) {
const file = files.find(f => f.id === fileId);
if (file) {
// Create a blob with sample content for demonstration
const content = `This is a demo file: ${file.name}\nFile Type: ${file.type}\nUpload Date: ${file.uploadDate}\nFile Size: ${formatFileSize(file.size)}`;
const blob = new Blob([content], { type: ‘text/plain’ });
const url = URL.createObjectURL(blob);
// Create download link and trigger download
const a = document.createElement(‘a’);
a.href = url;
a.download = file.name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
file.downloads++;
renderFiles();
showNotification(`${file.name} downloaded successfully!`, ‘success’);
}
}
function shareFile(fileId) {
const file = files.find(f => f.id === fileId);
if (file) {
// Create a shareable link with file info in the current page
const shareLink = `${window.location.href.split(‘?’)[0]}?shared=${file.shareId}&name=${encodeURIComponent(file.name)}`;
document.getElementById(‘shareLink’).textContent = shareLink;
document.getElementById(‘shareModal’).style.display = ‘flex’;
}
}
function deleteFile(fileId) {
if (confirm(‘Are you sure you want to delete this file?’)) {
files = files.filter(f => f.id !== fileId);
renderFiles();
showNotification(‘File deleted successfully!’, ‘success’);
}
}
function copyShareLink() {
const shareLink = document.getElementById(‘shareLink’).textContent;
navigator.clipboard.writeText(shareLink).then(() => {
showNotification(‘Share link copied to clipboard!’, ‘success’);
closeModal(‘shareModal’);
}).catch(() => {
showNotification(‘Failed to copy link. Please copy manually.’, ‘error’);
});
}
function closeModal(modalId) {
document.getElementById(modalId).style.display = ‘none’;
}
function showNotification(message, type) {
const notification = document.getElementById(‘notification’);
notification.textContent = message;
notification.className = `notification ${type}`;
notification.classList.add(‘show’);
setTimeout(() => {
notification.classList.remove(‘show’);
}, 3000);
}
function generateShareId() {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
function checkSharedFile() {
// Check if accessing a shared file
const urlParams = new URLSearchParams(window.location.search);
const sharedId = urlParams.get(‘shared’);
const fileName = urlParams.get(‘name’);
if (sharedId && fileName) {
// Show shared file information without requiring the file to exist locally
showNotification(`Shared file: ${decodeURIComponent(fileName)} – Note: File must be uploaded to this instance to download`, ‘success’);
// Add a note about shared files
const fileGrid = document.getElementById(‘fileGrid’);
if (files.length === 0) {
fileGrid.innerHTML = `
Shared File Link Accessed
File: ${decodeURIComponent(fileName)}
This is a demo environment. Files are stored locally per session.
The original file owner needs to share it from their active session.
`;
}
}
}
// Close modal when clicking outside
window.addEventListener(‘click’, function(e) {
const modals = document.querySelectorAll(‘.modal’);
modals.forEach(modal => {
if (e.target === modal) {
modal.style.display = ‘none’;
}
});
});



Leave a Reply