Implement Duplicate Upload Prevention

- Server: /upload rejects existing files with 409 Conflict
- Web: handleFileUpload skips duplicates with toast feedback
- Qt: upload_track blocks duplicate imports and uploads with dialog alert
This commit is contained in:
ComputerTech 2026-03-12 19:12:07 +00:00
parent 44b36bf08d
commit eb3e66ba61
3 changed files with 28 additions and 2 deletions

View File

@ -1520,14 +1520,24 @@ async function handleFileUpload(event) {
progressContainer.innerHTML = '<h3>UPLOADING TRACKS...</h3>';
progressContainer.classList.add('active');
const existingFilenames = allSongs.map(s => s.file.split('/').pop().toLowerCase());
const uploadPromises = files.map(async (file) => {
const allowedExts = ['.mp3', '.m4a', '.wav', '.flac', '.ogg'];
const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
if (!allowedExts.includes(ext)) {
console.warn(`${file.name} is not a supported audio file`);
return;
}
// Check for duplicates
if (existingFilenames.includes(file.name.toLowerCase())) {
console.log(`[UPLOAD] Skipping duplicate: ${file.name}`);
showToast(`Skipped duplicate: ${file.name}`, 'info');
return;
}
const formData = new FormData();
formData.append('file', file);

View File

@ -409,6 +409,9 @@ def setup_shared_routes(app, index_file='index.html'):
filepath = os.path.join(MUSIC_FOLDER, filename)
if os.path.exists(filepath):
return jsonify({"success": False, "error": "File already exists in library"}), 409
try:
file.save(filepath)
print(f"UPLOADED: {filename}")

View File

@ -2110,16 +2110,29 @@ class DJApp(QMainWindow):
return
if self.library_mode == "local":
filename = os.path.basename(file_path)
# Check for duplicates in local_library
if any(Path(track['path']).name.lower() == filename.lower() for track in self.local_library):
QMessageBox.information(self, "Import Skipped", f"'{filename}' is already in your local library.")
return
# Copy to local music folder
dest = self.lib_path / os.path.basename(file_path)
dest = self.lib_path / filename
try:
shutil.copy2(file_path, dest)
self.status_label.setText(f"Imported: {os.path.basename(file_path)}")
self.status_label.setText(f"Imported: {filename}")
self.load_library()
except Exception as e:
QMessageBox.warning(self, "Import Error", f"Failed to import file: {e}")
else:
# Upload to server
filename = os.path.basename(file_path)
# Check for duplicates in server_library
if hasattr(self, 'server_library'):
if any(track['file'].split('/')[-1].lower() == filename.lower() for track in self.server_library):
QMessageBox.information(self, "Upload Skipped", f"'{filename}' already exists on the server.")
return
try:
self.status_label.setText("Uploading to server...")
base_url = self.get_server_base_url()