Spaces:
Sleeping
Sleeping
AdityaAdaki
commited on
Commit
·
9870f48
1
Parent(s):
650a109
bug fixes
Browse files- static/css/style.css +0 -30
- static/js/main.js +101 -90
- 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 |
-
//
|
1267 |
-
function
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1275 |
}
|
1276 |
-
totalSize += file.size;
|
1277 |
}
|
1278 |
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
|
|
1283 |
|
1284 |
-
//
|
1285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1286 |
try {
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
const
|
|
|
1298 |
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
|
|
|
|
|
|
|
|
1306 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1307 |
}
|
1308 |
} catch (error) {
|
1309 |
-
|
|
|
1310 |
} finally {
|
1311 |
-
|
1312 |
-
|
|
|
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
|
58 |
-
<div class="progress">
|
59 |
-
<div class="progress-
|
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>
|