<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Free Cloud Storage - 100TB Storage, 100GB/file</title>
<style>
/* General Styles */
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f4f7fc;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background-color: #2d74f7;
color: white;
padding: 1rem 2rem;
text-align: center;
font-size: 1.5rem;
font-weight: 700;
user-select: none;
box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
main {
flex: 1;
padding: 1rem 2rem 3rem 2rem;
max-width: 960px;
margin: 0 auto;
width: 100%;
}
.storage-info {
margin-bottom: 1rem;
font-weight: 600;
color: #333;
user-select: none;
}
/* Upload Section */
#upload-section {
background: white;
padding: 1rem 1.5rem;
border-radius: 8px;
box-shadow: 0 1px 8px rgba(0,0,0,0.1);
margin-bottom: 1.5rem;
display: flex;
flex-wrap: wrap;
gap: 1rem;
align-items: center;
justify-content: space-between;
}
#file-input-label {
cursor: pointer;
background-color: #2d74f7;
color: white;
padding: 0.7rem 1.2rem;
border-radius: 6px;
font-size: 1rem;
user-select: none;
transition: background-color 0.2s ease-in-out;
}
#file-input-label:hover {
background-color: #1a4fcc;
}
#file-input {
display: none;
}
#category-input {
flex-grow: 1;
max-width: 250px;
padding: 0.5rem 0.75rem;
border-radius: 6px;
border: 1px solid #ccc;
font-size: 1rem;
}
#upload-btn {
background-color: #28a745;
border: none;
padding: 0.7rem 1.4rem;
border-radius: 6px;
color: white;
font-weight: 700;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.2s ease-in-out;
}
#upload-btn:disabled {
background-color: #94d3a2;
cursor: not-allowed;
}
#upload-btn:hover:not(:disabled) {
background-color: #1e7e34;
}
/* Files List */
#categories-container {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.category-section {
background: white;
padding: 1rem 1.5rem;
border-radius: 8px;
box-shadow: 0 1px 8px rgba(0,0,0,0.1);
}
.category-title {
font-weight: 700;
margin-bottom: 0.75rem;
font-size: 1.2rem;
border-bottom: 2px solid #2d74f7;
padding-bottom: 0.25rem;
user-select: none;
}
.files-list {
list-style: none;
padding-left: 0;
max-height: 300px;
overflow-y: auto;
margin: 0;
}
.file-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem;
border-radius: 5px;
transition: background-color 0.2s ease-in-out;
user-select: none;
}
.file-item:nth-child(odd) {
background-color: #f9f9f9;
}
.file-item:hover {
background-color: #e7f0ff;
}
.file-name {
flex-grow: 1;
margin-right: 1rem;
word-break: break-all;
font-size: 0.95rem;
color: #222;
}
.file-size {
color: #666;
font-size: 0.85rem;
min-width: 70px;
text-align: right;
margin-right: 1rem;
font-family: monospace;
user-select: text;
}
.file-actions button {
background-color: #2d74f7;
border: none;
color: white;
padding: 0.3rem 0.7rem;
border-radius: 5px;
cursor: pointer;
font-size: 0.85rem;
margin-left: 0.5rem;
transition: background-color 0.2s ease-in-out;
}
.file-actions button:hover {
background-color: #154eaf;
}
.file-actions button.delete-btn {
background-color: #dc3545;
}
.file-actions button.delete-btn:hover {
background-color: #a71d2a;
}
/* Loading Screen */
#loading-screen {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background-color: rgba(0, 0, 0, 0.4);
display: flex;
justify-content: center;
align-items: center;
font-size: 1.2rem;
color: white;
user-select: none;
z-index: 9999;
flex-direction: column;
visibility: hidden;
opacity: 0;
transition: opacity 0.3s ease;
}
#loading-screen.active {
visibility: visible;
opacity: 1;
}
/* Spinner */
.spinner {
margin-bottom: 1rem;
border: 6px solid #f3f3f3;
border-top: 6px solid #2d74f7;
border-radius: 50%;
width: 48px;
height: 48px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
/* No files message */
#no-files {
text-align: center;
color: #777;
font-style: italic;
margin-top: 3rem;
user-select: none;
}
/* Footer */
footer {
text-align: center;
padding: 1rem;
font-size: 0.85rem;
color: #555;
user-select: none;
background-color: #f0f0f0;
}
/* Responsive */
@media (max-width: 600px) {
#upload-section {
flex-direction: column;
align-items: stretch;
}
#category-input {
max-width: 100%;
margin-bottom: 0.5rem;
}
#upload-btn, #file-input-label {
width: 100%;
}
.file-actions button {
padding: 0.4rem 0.8rem;
font-size: 0.9rem;
}
}
</style>
</head>
<body>
<header>Free Cloud Storage - 100TB Total, 100GB Per File</header>
<main>
<div class="storage-info" id="storage-info">Used 0 GB / 100,000 GB (100 TB)</div>
<section id="upload-section" aria-label="File Upload">
<label for="file-input" id="file-input-label" tabindex="0" role="button" aria-describedby="upload-desc">Choose File(s)</label>
<input type="file" id="file-input" aria-describedby="upload-desc" />
<input type="text" id="category-input" placeholder="Category (optional)" aria-label="Category for the files" />
<button id="upload-btn" disabled>Upload</button>
<div id="upload-desc" class="sr-only">Select files to upload. Each file max size: 100 GB. Enter a custom category if desired. Click upload.</div>
</section>
<div id="categories-container" aria-live="polite" aria-relevant="additions removals"></div>
<div id="no-files" style="display:none;">No files uploaded yet.</div>
</main>
<div id="loading-screen" role="alert" aria-live="assertive" aria-busy="true" aria-label="Uploading file">
<div class="spinner" aria-hidden="true"></div>
<div>Uploading file, please wait...</div>
</div>
<footer>
© 2024 Free Cloud Storage - All files stored locally in this browser only.
</footer>
<script>
(() => {
"use strict";
// Constants
const MAX_FILE_SIZE_BYTES = 100 * 1024 ** 3; // 100 GB
const MAX_TOTAL_STORAGE_BYTES = 100 * 1024 ** 4; // 100 TB = 100 * 1024^4 bytes
// For easier usage, store sizes in bytes.
// Storage Keys
const STORAGE_KEY = 'freeCloudStorageFiles';
// DOM Elements
const fileInput = document.getElementById('file-input');
const uploadButton = document.getElementById('upload-btn');
const categoryInput = document.getElementById('category-input');
const categoriesContainer = document.getElementById('categories-container');
const storageInfo = document.getElementById('storage-info');
const loadingScreen = document.getElementById('loading-screen');
const noFilesMessage = document.getElementById('no-files');
const fileInputLabel = document.getElementById('file-input-label');
// File structure example:
// {
// id: string, // unique id
// name: string,
// size: number (bytes),
// type: string,
// category: string (optional),
// data: base64 string of file,
// uploadedAt: ISO string,
// }
// In-memory files list
let files = [];
// Generate unique id for files
function generateId() {
// Use crypto.randomUUID if available
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
return crypto.randomUUID();
} else {
// Fallback: simple random string
return 'f-' + Math.random().toString(36).substr(2, 9);
}
}
// Format bytes to human readable
function formatBytes(bytes) {
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return '0 B';
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), sizes.length - 1);
const value = bytes / (1024 ** i);
return value.toFixed(2).replace(/\.00$/,'') + ' ' + sizes[i];
}
// Save files array to localStorage
function saveFiles() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(files));
} catch (e) {
alert('Error saving files to localStorage. You may be out of browser storage space.');
console.error(e);
}
}
// Load files array from localStorage
function loadFiles() {
try {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored) {
files = JSON.parse(stored);
}
} catch (e) {
console.error('Error loading files from localStorage', e);
files = [];
}
}
// Calculate total used storage bytes
function getUsedBytes() {
return files.reduce((sum, f) => sum + f.size, 0);
}
// Update storage info text
function updateStorageInfo() {
const usedGB = (getUsedBytes() / (1024 ** 3));
const usedGBDisplay = usedGB.toFixed(2).replace(/\.00$/, '');
const totalGB = MAX_TOTAL_STORAGE_BYTES / (1024 ** 3);
storageInfo.textContent = `Used ${usedGBDisplay} GB / ${totalGB.toLocaleString()} GB (100 TB)`;
}
// Render files grouped by category
function renderFiles() {
categoriesContainer.innerHTML = '';
if (files.length === 0) {
noFilesMessage.style.display = 'block';
return;
} else {
noFilesMessage.style.display = 'none';
}
// Group files by category (empty string for no category)
const categoriesMap = files.reduce((acc, file) => {
const cat = file.category?.trim() || 'Uncategorized';
if (!acc.has(cat)) acc.set(cat, []);
acc.get(cat).push(file);
return acc;
}, new Map());
// Sort categories alphabetically with "Uncategorized" always last
const categories = Array.from(categoriesMap.keys()).sort((a, b) => {
if (a === 'Uncategorized') return 1;
if (b === 'Uncategorized') return -1;
return a.localeCompare(b);
});
for (const category of categories) {
const catFiles = categoriesMap.get(category);
const categorySection = document.createElement('section');
categorySection.className = 'category-section';
const categoryTitle = document.createElement('h2');
categoryTitle.className = 'category-title';
categoryTitle.textContent = category;
categorySection.appendChild(categoryTitle);
const ul = document.createElement('ul');
ul.className = 'files-list';
ul.setAttribute('role', 'list');
for (const file of catFiles) {
const li = document.createElement('li');
li.className = 'file-item';
li.setAttribute('tabindex', '0');
const nameSpan = document.createElement('span');
nameSpan.className = 'file-name';
nameSpan.textContent = file.name;
nameSpan.title = file.name;
const sizeSpan = document.createElement('span');
sizeSpan.className = 'file-size';
sizeSpan.textContent = formatBytes(file.size);
const actionsDiv = document.createElement('div');
actionsDiv.className = 'file-actions';
const downloadBtn = document.createElement('button');
downloadBtn.textContent = 'Download';
downloadBtn.title = 'Download this file';
downloadBtn.addEventListener('click', () => {
downloadFile(file);
});
const deleteBtn = document.createElement('button');
deleteBtn.textContent = 'Delete';
deleteBtn.className = 'delete-btn';
deleteBtn.title = 'Delete this file';
deleteBtn.addEventListener('click', () => {
if (confirm(`Are you sure you want to delete "${file.name}"? This action cannot be undone.`)) {
deleteFile(file.id);
}
});
actionsDiv.appendChild(downloadBtn);
actionsDiv.appendChild(deleteBtn);
li.appendChild(nameSpan);
li.appendChild(sizeSpan);
li.appendChild(actionsDiv);
ul.appendChild(li);
}
categorySection.appendChild(ul);
categoriesContainer.appendChild(categorySection);
}
}
// Download file by creating a blob and a download link
function downloadFile(file) {
try {
const base64Data = file.data;
const byteString = atob(base64Data);
const arrayBuffer = new ArrayBuffer(byteString.length);
const uintArray = new Uint8Array(arrayBuffer);
for(let i =0; i < byteString.length; i++) {
uintArray[i] = byteString.charCodeAt(i);
}
const blob = new Blob([uintArray], { type: file.type || 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = file.name;
document.body.appendChild(a);
a.click();
setTimeout(() => {
URL.revokeObjectURL(url);
a.remove();
}, 100);
} catch (e) {
alert('Failed to download the file.');
console.error(e);
}
}
// Delete file by id
function deleteFile(id) {
files = files.filter(f => f.id !== id);
saveFiles();
updateStorageInfo();
renderFiles();
}
// Reads a File object and returns a Promise<string> of base64 content (without data: prefix)
function fileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = function(e) {
const base64String = e.target.result.split(',')[1]; // strip "data:*/*;base64,"
resolve(base64String);
};
reader.onerror = function() {
reject(new Error('Error reading file'));
};
reader.readAsDataURL(file);
});
}
// Show loading screen
function showLoading() {
loadingScreen.classList.add('active');
loadingScreen.setAttribute('aria-hidden', 'false');
}
// Hide loading screen
function hideLoading() {
loadingScreen.classList.remove('active');
loadingScreen.setAttribute('aria-hidden', 'true');
}
// Validate files and enable/disable upload button
function validateFiles() {
if (fileInput.files.length < 1) {
uploadButton.disabled = true;
return;
}
// Check each file size and if total fits
const newFilesSize = Array.from(fileInput.files).reduce((sum, f) => sum + f.size, 0);
if (newFilesSize > MAX_FILE_SIZE_BYTES * fileInput.files.length) {
// But constraints say 100GB max per file, so better to check each one separately
uploadButton.disabled = true;
return;
}
for (const f of fileInput.files) {
if (f.size > MAX_FILE_SIZE_BYTES) {
uploadButton.disabled = true;
return;
}
}
const used = getUsedBytes();
if (used + newFilesSize > MAX_TOTAL_STORAGE_BYTES) {
uploadButton.disabled = true;
return;
}
uploadButton.disabled = false;
}
// Upload files handler - simulate 5 seconds upload per file total
async function handleUpload() {
if (fileInput.files.length === 0) return;
// Disable inputs during upload
uploadButton.disabled = true;
fileInput.disabled = true;
categoryInput.disabled = true;
fileInputLabel.setAttribute('aria-disabled', 'true');
showLoading();
// The requirement: It takes 5 seconds to upload a file (not per file, total)
// So total 5 seconds only (not 5 seconds per file)
// We'll do the base64 conversion async and after that wait whatever remains to reach total 5 seconds
try {
const filesList = Array.from(fileInput.files);
const category = categoryInput.value.trim();
const uploadStart = performance.now();
for (const file of filesList) {
// Check file size not exceeding 100 GB just in case
if (file.size > MAX_FILE_SIZE_BYTES) {
alert(`File "${file.name}" exceeds max size of 100 GB and was skipped.`);
continue;
}
// Check global storage limit
if (getUsedBytes() + file.size > MAX_TOTAL_STORAGE_BYTES) {
alert(`Not enough storage left to upload "${file.name}". Skipping.`);
continue;
}
// Read file and convert to base64 string
// Large files could be a problem in real usage but for this demo we do this
const base64data = await fileToBase64(file);
// Create file object and push
const fileObj = {
id: generateId(),
name: file.name,
size: file.size,
type: file.type,
category: category || '',
data: base64data,
uploadedAt: (new Date()).toISOString()
};
files.push(fileObj);
}
const uploadEnd = performance.now();
const elapsed = uploadEnd - uploadStart;
const waitTime = 5000 - elapsed;
if (waitTime > 0) {
await new Promise(r => setTimeout(r, waitTime));
}
saveFiles();
updateStorageInfo();
renderFiles();
fileInput.value = '';
categoryInput.value = '';
uploadButton.disabled = true;
fileInput.disabled = false;
categoryInput.disabled = false;
fileInputLabel.removeAttribute('aria-disabled');
} catch (err) {
alert('Error uploading files: ' + err.message);
console.error(err);
fileInput.disabled = false;
categoryInput.disabled = false;
fileInputLabel.removeAttribute('aria-disabled');
} finally {
hideLoading();
}
}
// Accessibility: simulate click on label on keyboard Enter/Space
fileInputLabel.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
fileInput.click();
}
});
// Event Listeners
fileInput.addEventListener('change', () => {
validateFiles();
});
uploadButton.addEventListener('click', handleUpload);
// On load
loadFiles();
updateStorageInfo();
renderFiles();
validateFiles();
// Warn user about localStorage quota, because big files can stress it
// Could add this if used size more than 90% (optional)
})();
</script>
<!-- Screen reader only styles for aria description -->
<style>
.sr-only {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0,0,0,0) !important;
white-space: nowrap !important;
border: 0 !important;
}
</style>
</body>
</html>