AdityaAdaki commited on
Commit
9870f48
·
1 Parent(s): 650a109
Files changed (3) hide show
  1. static/css/style.css +0 -30
  2. static/js/main.js +101 -90
  3. templates/index.html +4 -3
static/css/style.css CHANGED
@@ -1143,34 +1143,4 @@ canvas {
1143
  [data-theme="dark"] .playlist-item.active .track-artwork {
1144
  border-color: var(--primary-color);
1145
  background: rgba(76, 175, 80, 0.1);
1146
- }
1147
-
1148
- /* Add these styles */
1149
- .upload-progress-container {
1150
- width: 100%;
1151
- max-width: 600px;
1152
- margin: 20px auto;
1153
- display: none; /* Will be shown when upload starts */
1154
- }
1155
-
1156
- .progress {
1157
- width: 100%;
1158
- height: 20px;
1159
- background-color: #f5f5f5;
1160
- border-radius: 4px;
1161
- overflow: hidden;
1162
- }
1163
-
1164
- .progress-bar {
1165
- height: 100%;
1166
- background-color: #4CAF50;
1167
- color: white;
1168
- text-align: center;
1169
- line-height: 20px;
1170
- transition: width 0.3s ease;
1171
- }
1172
-
1173
- /* Show progress container during upload */
1174
- .uploading .upload-progress-container {
1175
- display: block;
1176
  }
 
1143
  [data-theme="dark"] .playlist-item.active .track-artwork {
1144
  border-color: var(--primary-color);
1145
  background: rgba(76, 175, 80, 0.1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1146
  }
static/js/main.js CHANGED
@@ -1263,53 +1263,116 @@ function setupPlaylistControls() {
1263
  });
1264
  }
1265
 
1266
- // Add this function to handle file size validation
1267
- function validateFiles(files) {
1268
- const maxFileSize = 200 * 1024 * 1024; // 200MB
1269
- const maxTotalSize = 500 * 1024 * 1024; // 500MB total
1270
- let totalSize = 0;
1271
-
1272
- for (const file of files) {
1273
- if (file.size > maxFileSize) {
1274
- throw new Error(`File ${file.name} is too large. Maximum size is 200MB`);
 
 
 
 
 
 
 
 
 
1275
  }
1276
- totalSize += file.size;
1277
  }
1278
 
1279
- if (totalSize > maxTotalSize) {
1280
- throw new Error(`Total file size (${Math.round(totalSize/1024/1024)}MB) exceeds maximum allowed (500MB)`);
1281
- }
1282
- }
 
1283
 
1284
- // Modify your file handling function
1285
- async function handleFiles(files) {
 
 
 
 
 
 
 
 
 
1286
  try {
1287
- // Show upload container
1288
- document.body.classList.add('uploading');
1289
-
1290
- // Validate files
1291
- validateFiles(files);
1292
-
1293
- // Update progress bar to 0
1294
- updateProgressBar(0);
1295
-
1296
- // Upload files
1297
- const results = await uploadFiles(files);
 
1298
 
1299
- // Process results
1300
- for (const result of results) {
1301
- if (result.success) {
1302
- // Handle successful upload
1303
- addTrackToPlaylist(result);
1304
- } else {
1305
- console.error(`Failed to upload ${result.filename}: ${result.error}`);
 
 
 
 
1306
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1307
  }
1308
  } catch (error) {
1309
- alert(error.message || 'Upload failed');
 
1310
  } finally {
1311
- // Hide upload container
1312
- document.body.classList.remove('uploading');
 
1313
  }
1314
  }
1315
 
@@ -1382,56 +1445,4 @@ function setupVolumeControl() {
1382
  document.addEventListener('DOMContentLoaded', () => {
1383
  // ... other initialization code ...
1384
  setupVolumeControl();
1385
- });
1386
-
1387
- function updateProgressBar(percent) {
1388
- const progressBar = document.querySelector('.progress-bar');
1389
- if (progressBar) {
1390
- progressBar.style.width = `${percent}%`;
1391
- progressBar.textContent = `${Math.round(percent)}%`;
1392
- }
1393
- }
1394
-
1395
- async function uploadFiles(files) {
1396
- const formData = new FormData();
1397
- let totalSize = 0;
1398
- let uploadedSize = 0;
1399
-
1400
- // Calculate total size
1401
- for (const file of files) {
1402
- totalSize += file.size;
1403
- formData.append('files[]', file);
1404
- }
1405
-
1406
- try {
1407
- const response = await fetch('/upload', {
1408
- method: 'POST',
1409
- body: formData,
1410
- headers: {
1411
- 'Accept': 'application/json',
1412
- },
1413
- onUploadProgress: (progressEvent) => {
1414
- const percent = (progressEvent.loaded / totalSize) * 100;
1415
- updateProgressBar(percent);
1416
- }
1417
- });
1418
-
1419
- if (!response.ok) {
1420
- throw new Error(`HTTP error! status: ${response.status}`);
1421
- }
1422
-
1423
- const result = await response.json();
1424
- updateProgressBar(100);
1425
-
1426
- // Handle the upload response
1427
- if (result.success) {
1428
- return result.files;
1429
- } else {
1430
- throw new Error(result.error || 'Upload failed');
1431
- }
1432
- } catch (error) {
1433
- console.error('Upload error:', error);
1434
- updateProgressBar(0);
1435
- throw error;
1436
- }
1437
- }
 
1263
  });
1264
  }
1265
 
1266
+ // Update handleFiles to append new tracks
1267
+ async function handleFiles(files) {
1268
+ console.log('Handling files:', files.length, 'files');
1269
+
1270
+ if (!files || files.length === 0) {
1271
+ console.warn('No files selected');
1272
+ showError('No files selected');
1273
+ return;
1274
+ }
1275
+
1276
+ if (!audioContext) {
1277
+ try {
1278
+ console.log('Initializing audio context...');
1279
+ initAudio();
1280
+ } catch (error) {
1281
+ console.error('Failed to initialize audio:', error);
1282
+ showError('Failed to initialize audio system');
1283
+ return;
1284
  }
 
1285
  }
1286
 
1287
+ const formData = new FormData();
1288
+ Array.from(files).forEach(file => {
1289
+ console.log('Adding file to upload:', file.name);
1290
+ formData.append('files[]', file);
1291
+ });
1292
 
1293
+ // Show upload progress
1294
+ const uploadProgress = document.querySelector('.upload-progress');
1295
+ const progressFill = uploadProgress?.querySelector('.progress-fill');
1296
+ const progressText = uploadProgress?.querySelector('.progress-text');
1297
+
1298
+ if (uploadProgress && progressFill && progressText) {
1299
+ uploadProgress.classList.add('visible');
1300
+ progressFill.style.width = '0%';
1301
+ progressText.textContent = '0%';
1302
+ }
1303
+
1304
  try {
1305
+ console.log('Starting file upload...');
1306
+ const response = await fetch('/upload', {
1307
+ method: 'POST',
1308
+ body: formData
1309
+ });
1310
+
1311
+ if (!response.ok) {
1312
+ throw new Error(`HTTP error! status: ${response.status}`);
1313
+ }
1314
+
1315
+ const data = await response.json();
1316
+ console.log('Upload response:', data);
1317
 
1318
+ if (data.success) {
1319
+ console.log('Files uploaded successfully');
1320
+ showSuccess('Files uploaded successfully');
1321
+
1322
+ const successfulFiles = data.files.filter(file => file.success);
1323
+ console.log('Successful uploads:', successfulFiles.length, 'files');
1324
+
1325
+ if (successfulFiles.length === 0) {
1326
+ console.warn('No files were uploaded successfully');
1327
+ showError('No files were uploaded successfully');
1328
+ return;
1329
  }
1330
+
1331
+ // Get the next index for new tracks
1332
+ const startIndex = playlist.length;
1333
+
1334
+ // Create new track objects
1335
+ const newTracks = successfulFiles.map((file, index) => ({
1336
+ name: file.filename,
1337
+ url: file.filepath,
1338
+ metadata: file.metadata,
1339
+ originalIndex: startIndex + index
1340
+ }));
1341
+
1342
+ // Append new tracks to existing playlist
1343
+ playlist = [...playlist, ...newTracks];
1344
+
1345
+ console.log('Updated playlist:', playlist);
1346
+ createPlaylist();
1347
+
1348
+ // Only start playing if nothing is currently playing
1349
+ if (playlist.length > 0 && !isPlaying) {
1350
+ console.log('Playing first track...');
1351
+ playTrack(0);
1352
+ }
1353
+
1354
+ // Enable player controls
1355
+ document.querySelectorAll('.control-btn').forEach(btn => {
1356
+ btn.disabled = false;
1357
+ });
1358
+
1359
+ // Highlight currently playing track if any
1360
+ if (currentTrackIndex >= 0) {
1361
+ document.querySelectorAll('.playlist-item').forEach((item, i) => {
1362
+ item.classList.toggle('active', i === currentTrackIndex);
1363
+ });
1364
+ }
1365
+ } else {
1366
+ console.error('Upload failed:', data.error);
1367
+ showError(data.error || 'Upload failed');
1368
  }
1369
  } catch (error) {
1370
+ console.error('Upload error:', error);
1371
+ showError('Error uploading files');
1372
  } finally {
1373
+ if (uploadProgress) {
1374
+ uploadProgress.classList.remove('visible');
1375
+ }
1376
  }
1377
  }
1378
 
 
1445
  document.addEventListener('DOMContentLoaded', () => {
1446
  // ... other initialization code ...
1447
  setupVolumeControl();
1448
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/index.html CHANGED
@@ -54,10 +54,11 @@
54
  <p>or click to browse</p>
55
  <span class="file-types">Supports MP3, WAV, OGG, FLAC</span>
56
  </div>
57
- <div class="upload-progress-container">
58
- <div class="progress">
59
- <div class="progress-bar" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
60
  </div>
 
61
  </div>
62
  <div id="file-name"></div>
63
  </div>
 
54
  <p>or click to browse</p>
55
  <span class="file-types">Supports MP3, WAV, OGG, FLAC</span>
56
  </div>
57
+ <div class="upload-progress">
58
+ <div class="progress-bar">
59
+ <div class="progress-fill"></div>
60
  </div>
61
+ <div class="progress-text">0%</div>
62
  </div>
63
  <div id="file-name"></div>
64
  </div>