vorstcavry commited on
Commit
bbeb4d1
·
verified ·
1 Parent(s): 0b9c2e1

Add 1 files

Browse files
Files changed (1) hide show
  1. index.html +79 -53
index.html CHANGED
@@ -5,6 +5,9 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Simple Image Gallery</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
 
 
 
8
  <style>
9
  .gallery-item {
10
  transition: all 0.3s ease;
@@ -48,23 +51,25 @@
48
 
49
  <!-- Gallery Grid -->
50
  <div id="gallery-grid" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
51
- <!-- Sample images (would be loaded from storage in real implementation) -->
52
- <div class="gallery-item bg-white rounded-lg overflow-hidden shadow">
53
- <img src="https://source.unsplash.com/random/300x300/?nature" alt="Gallery image" class="w-full h-48 object-cover">
54
- <div class="p-3">
55
- <p class="text-sm text-gray-600">Uploaded: Just now</p>
56
- </div>
57
- </div>
58
- <div class="gallery-item bg-white rounded-lg overflow-hidden shadow">
59
- <img src="https://source.unsplash.com/random/300x300/?city" alt="Gallery image" class="w-full h-48 object-cover">
60
- <div class="p-3">
61
- <p class="text-sm text-gray-600">Uploaded: Just now</p>
62
- </div>
63
- </div>
64
  </div>
65
  </div>
66
 
67
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  // DOM elements
69
  const dropArea = document.getElementById('drop-area');
70
  const fileElem = document.getElementById('fileElem');
@@ -74,6 +79,9 @@
74
  const progressBar = document.getElementById('progress-bar');
75
  const progressText = document.getElementById('progress-text');
76
 
 
 
 
77
  // Prevent default drag behaviors
78
  ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
79
  dropArea.addEventListener(eventName, preventDefaults, false);
@@ -120,56 +128,74 @@
120
  handleFiles(this.files);
121
  });
122
 
123
- // Process files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  function handleFiles(files) {
125
  if (files.length === 0) return;
126
 
127
  progressContainer.classList.remove('hidden');
128
 
129
- // Simulate upload progress (in a real app, this would be an actual upload)
130
- let progress = 0;
131
- const interval = setInterval(() => {
132
- progress += 5;
133
- progressBar.style.width = `${progress}%`;
134
- progressText.textContent = `Uploading: ${progress}%`;
135
 
136
- if (progress >= 100) {
137
- clearInterval(interval);
138
- setTimeout(() => {
 
 
 
 
 
 
 
 
 
 
 
139
  progressContainer.classList.add('hidden');
140
- progressBar.style.width = '0%';
141
- progressText.textContent = 'Uploading: 0%';
142
-
143
- // Add uploaded images to gallery
144
- for (let i = 0; i < files.length; i++) {
145
- const file = files[i];
146
- if (!file.type.match('image.*')) continue;
147
 
148
- const reader = new FileReader();
149
- reader.onload = (function(theFile) {
150
- return function(e) {
151
- const galleryItem = document.createElement('div');
152
- galleryItem.className = 'gallery-item bg-white rounded-lg overflow-hidden shadow';
153
- galleryItem.innerHTML = `
154
- <img src="${e.target.result}" alt="Gallery image" class="w-full h-48 object-cover">
155
- <div class="p-3">
156
- <p class="text-sm text-gray-600">Uploaded: Just now</p>
157
- </div>
158
- `;
159
- galleryGrid.insertBefore(galleryItem, galleryGrid.firstChild);
160
- };
161
- })(file);
162
- reader.readAsDataURL(file);
163
- }
164
- }, 500);
165
- }
166
- }, 100);
167
  }
168
 
169
- // In a real implementation, you would need server-side code to:
170
- // 1. Actually save the uploaded files to storage
171
- // 2. Retrieve the list of images to display in the gallery
172
- // 3. Handle potential security concerns with anonymous uploads
 
 
 
 
 
 
 
 
173
  </script>
174
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=vorstcavry/simple-galery" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
175
  </html>
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Simple Image Gallery</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
+ <!-- Firebase SDK -->
9
+ <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-app-compat.js"></script>
10
+ <script src="https://www.gstatic.com/firebasejs/9.6.0/firebase-storage-compat.js"></script>
11
  <style>
12
  .gallery-item {
13
  transition: all 0.3s ease;
 
51
 
52
  <!-- Gallery Grid -->
53
  <div id="gallery-grid" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
54
+ <!-- Images will be loaded here -->
 
 
 
 
 
 
 
 
 
 
 
 
55
  </div>
56
  </div>
57
 
58
  <script>
59
+ // Firebase configuration
60
+ const firebaseConfig = {
61
+ apiKey: "AIzaSyD3JgJvV8X9X9X9X9X9X9X9X9X9X9X9X9X9X9",
62
+ authDomain: "your-project-id.firebaseapp.com",
63
+ projectId: "your-project-id",
64
+ storageBucket: "your-project-id.appspot.com",
65
+ messagingSenderId: "123456789012",
66
+ appId: "1:123456789012:web:9X9X9X9X9X9X9X9X9X9X9"
67
+ };
68
+
69
+ // Initialize Firebase
70
+ firebase.initializeApp(firebaseConfig);
71
+ const storage = firebase.storage();
72
+
73
  // DOM elements
74
  const dropArea = document.getElementById('drop-area');
75
  const fileElem = document.getElementById('fileElem');
 
79
  const progressBar = document.getElementById('progress-bar');
80
  const progressText = document.getElementById('progress-text');
81
 
82
+ // Load existing images when page loads
83
+ window.addEventListener('load', loadImages);
84
+
85
  // Prevent default drag behaviors
86
  ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
87
  dropArea.addEventListener(eventName, preventDefaults, false);
 
128
  handleFiles(this.files);
129
  });
130
 
131
+ // Load existing images from Firebase Storage
132
+ async function loadImages() {
133
+ try {
134
+ const storageRef = storage.ref();
135
+ const result = await storageRef.listAll();
136
+
137
+ result.items.forEach(async (itemRef) => {
138
+ const url = await itemRef.getDownloadURL();
139
+ addImageToGallery(url, new Date().toLocaleString());
140
+ });
141
+ } catch (error) {
142
+ console.error("Error loading images:", error);
143
+ }
144
+ }
145
+
146
+ // Process files and upload to Firebase
147
  function handleFiles(files) {
148
  if (files.length === 0) return;
149
 
150
  progressContainer.classList.remove('hidden');
151
 
152
+ for (let i = 0; i < files.length; i++) {
153
+ const file = files[i];
154
+ if (!file.type.match('image.*')) continue;
 
 
 
155
 
156
+ // Create unique filename
157
+ const filename = Date.now() + '_' + file.name;
158
+ const storageRef = storage.ref().child(filename);
159
+ const uploadTask = storageRef.put(file);
160
+
161
+ uploadTask.on('state_changed',
162
+ (snapshot) => {
163
+ // Progress tracking
164
+ const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
165
+ progressBar.style.width = `${progress}%`;
166
+ progressText.textContent = `Uploading: ${Math.round(progress)}%`;
167
+ },
168
+ (error) => {
169
+ console.error("Upload error:", error);
170
  progressContainer.classList.add('hidden');
171
+ },
172
+ () => {
173
+ // Upload complete
174
+ uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => {
175
+ progressContainer.classList.add('hidden');
176
+ progressBar.style.width = '0%';
177
+ progressText.textContent = 'Uploading: 0%';
178
 
179
+ // Add to gallery
180
+ addImageToGallery(downloadURL, new Date().toLocaleString());
181
+ });
182
+ }
183
+ );
184
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
 
187
+ // Add image to gallery
188
+ function addImageToGallery(url, timestamp) {
189
+ const galleryItem = document.createElement('div');
190
+ galleryItem.className = 'gallery-item bg-white rounded-lg overflow-hidden shadow';
191
+ galleryItem.innerHTML = `
192
+ <img src="${url}" alt="Gallery image" class="w-full h-48 object-cover">
193
+ <div class="p-3">
194
+ <p class="text-sm text-gray-600">Uploaded: ${timestamp}</p>
195
+ </div>
196
+ `;
197
+ galleryGrid.insertBefore(galleryItem, galleryGrid.firstChild);
198
+ }
199
  </script>
200
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=vorstcavry/simple-galery" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
201
  </html>