Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Add server-side duplicate detection indicators with clickable copies modal

Murtaza Nasir861c519bbfe8
diff --git a/src/api/api_v1.py b/src/api/api_v1.py
index 81272efe..4359870e 100644
--- a/src/api/api_v1.py
+++ b/src/api/api_v1.py
@@ -735,7 +735,8 @@ def get_recording(recording_id):
'audio_available': recording.audio_deleted_at is None,
'processing_time_seconds': recording.processing_time_seconds,
'error_message': recording.error_message if recording.status == 'FAILED' else None,
- 'tags': [{'id': t.id, 'name': t.name, 'color': t.color} for t in recording.tags]
+ 'tags': [{'id': t.id, 'name': t.name, 'color': t.color} for t in recording.tags],
+ 'duplicate_info': recording.get_duplicate_info()
}
# Include large text fields based on params
diff --git a/src/models/recording.py b/src/models/recording.py
index 8ddb5a2f..ec3ece57 100644
--- a/src/models/recording.py
+++ b/src/models/recording.py
@@ -155,6 +155,35 @@ class Recording(db.Model):
logger.warning(f"Failed to get duration for recording {self.id}: {e}")
return None
+ def get_duplicate_info(self):
+ """Check if other recordings share the same file_hash for this user.
+
+ Returns:
+ Dict with total copy count and list of copies, or None.
+ """
+ if not self.file_hash:
+ return None
+ dupes = Recording.query.filter(
+ Recording.user_id == self.user_id,
+ Recording.file_hash == self.file_hash,
+ ).with_entities(
+ Recording.id, Recording.title, Recording.created_at
+ ).order_by(Recording.created_at).all()
+ if len(dupes) > 1:
+ return {
+ 'total_copies': len(dupes),
+ 'copies': [
+ {
+ 'id': d.id,
+ 'title': d.title or f'#{d.id}',
+ 'created_at': local_datetime_filter(d.created_at),
+ 'is_self': d.id == self.id
+ }
+ for d in dupes
+ ]
+ }
+ return None
+
def to_list_dict(self, viewer_user=None):
"""
Lightweight dict for list views - excludes expensive HTML conversions.
@@ -196,6 +225,7 @@ class Recording(db.Model):
'folder_id': self.folder_id,
'folder': self.folder.to_dict() if self.folder else None,
'tags': [tag.to_dict() for tag in visible_tags] if visible_tags else [],
+ 'duplicate_info': self.get_duplicate_info(),
'shared_with_count': shared_with_count,
'public_share_count': public_share_count
}
@@ -255,6 +285,7 @@ class Recording(db.Model):
'folder': self.folder.to_dict() if self.folder else None,
'tags': [tag.to_dict() for tag in visible_tags] if visible_tags else [],
'events': [event.to_dict() for event in self.events] if self.events else [],
+ 'duplicate_info': self.get_duplicate_info(),
'shared_with_count': shared_with_count,
'public_share_count': public_share_count
}
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index b7016b4e..20f1b198 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -535,6 +535,8 @@ document.addEventListener('DOMContentLoaded', async () => {
const speedMenuPosition = ref({});
const showVolumeSlider = ref(false);
const showModalVolumeSlider = ref(false);
+ const showDuplicatesModal = ref(false);
+ const duplicatesModalData = ref(null);
// --- Modal Audio Player State (Independent from main) ---
const modalAudioCurrentTime = ref(0);
@@ -2003,7 +2005,18 @@ document.addEventListener('DOMContentLoaded', async () => {
return '';
};
- // Tag functions from composable (using composable's implementations)
+ // Duplicates modal
+ const openDuplicatesModal = (duplicateInfo) => {
+ duplicatesModalData.value = duplicateInfo;
+ showDuplicatesModal.value = true;
+ };
+
+ const navigateToDuplicate = (id) => {
+ showDuplicatesModal.value = false;
+ const rec = recordings.value.find(r => r.id === id);
+ // selectRecording always re-fetches full data from the API
+ recordingsComposable.selectRecording(rec || { id });
+ };
// =========================================================================
// WATCHERS
@@ -2417,6 +2430,10 @@ document.addEventListener('DOMContentLoaded', async () => {
removeProgressItem,
retryProgressItem,
hasSpeakerNames,
+ showDuplicatesModal,
+ duplicatesModalData,
+ openDuplicatesModal,
+ navigateToDuplicate,
tagsWithCustomPrompts,
recordingDisclaimerHtml,
getTagPromptPreview,
diff --git a/static/locales/de.json b/static/locales/de.json
index d3d1bd06..301e511a 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -1145,7 +1145,9 @@
"untitled": "Unbenannte Aufnahme",
"uploadProgress": "Upload-Fortschritt",
"willAutoSummarize": "Wird nach der Transkription automatisch zusammengefasst",
- "duplicateDetected": "Diese Datei scheint ein Duplikat von \"{{existingName}}\" zu sein (hochgeladen am {{existingDate}})"
+ "duplicateDetected": "Diese Datei scheint ein Duplikat von \"{{existingName}}\" zu sein (hochgeladen am {{existingDate}})",
+ "duplicateFile": "Doppelte Datei",
+ "copies": "Kopien dieser Datei"
},
"uploadProgress": {
"title": "Upload-Fortschritt"
diff --git a/static/locales/en.json b/static/locales/en.json
index 8ea7c22d..7fe9b036 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -1196,7 +1196,9 @@
"untitled": "Untitled Recording",
"uploadProgress": "Upload Progress",
"willAutoSummarize": "Will auto-summarize after transcription",
- "duplicateDetected": "This file appears to be a duplicate of \"{{existingName}}\" (uploaded {{existingDate}})"
+ "duplicateDetected": "This file appears to be a duplicate of \"{{existingName}}\" (uploaded {{existingDate}})",
+ "duplicateFile": "Duplicate file",
+ "copies": "copies of this file"
},
"uploadProgress": {
"title": "Upload Progress"
diff --git a/static/locales/es.json b/static/locales/es.json
index 2977513c..17e8f5f2 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -1145,7 +1145,9 @@
"untitled": "Grabación Sin Título",
"uploadProgress": "Progreso de Carga",
"willAutoSummarize": "Se resumirá automáticamente después de la transcripción",
- "duplicateDetected": "Este archivo parece ser un duplicado de \"{{existingName}}\" (subido el {{existingDate}})"
+ "duplicateDetected": "Este archivo parece ser un duplicado de \"{{existingName}}\" (subido el {{existingDate}})",
+ "duplicateFile": "Archivo duplicado",
+ "copies": "copias de este archivo"
},
"uploadProgress": {
"title": "Progreso de Carga"
diff --git a/static/locales/fr.json b/static/locales/fr.json
index fc885340..7f8467b4 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -1139,7 +1139,9 @@
"untitled": "Enregistrement Sans Titre",
"uploadProgress": "Progression du Téléchargement",
"willAutoSummarize": "Résumé automatique après la transcription",
- "duplicateDetected": "Ce fichier semble être un doublon de \"{{existingName}}\" (importé le {{existingDate}})"
+ "duplicateDetected": "Ce fichier semble être un doublon de \"{{existingName}}\" (importé le {{existingDate}})",
+ "duplicateFile": "Fichier en double",
+ "copies": "copies de ce fichier"
},
"uploadProgress": {
"title": "Progression du Téléchargement"
diff --git a/static/locales/ru.json b/static/locales/ru.json
index 57e1996c..33cd6714 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -1161,7 +1161,9 @@
"untitled": "Запись без названия",
"uploadProgress": "Прогресс загрузки",
"willAutoSummarize": "Автоматически создаст резюме после транскрибирования",
- "duplicateDetected": "Этот файл является дубликатом \"{{existingName}}\" (загружен {{existingDate}})"
+ "duplicateDetected": "Этот файл является дубликатом \"{{existingName}}\" (загружен {{existingDate}})",
+ "duplicateFile": "Дубликат файла",
+ "copies": "копий этого файла"
},
"uploadProgress": {
"title": "Прогресс загрузки"
diff --git a/static/locales/zh.json b/static/locales/zh.json
index b2b13e20..437647e6 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -1274,7 +1274,9 @@
"untitled": "无标题录音",
"uploadProgress": "上传进度",
"willAutoSummarize": "转录后将自动生成摘要",
- "duplicateDetected": "此文件似乎与 \"{{existingName}}\" 重复(上传于 {{existingDate}})"
+ "duplicateDetected": "此文件似乎与 \"{{existingName}}\" 重复(上传于 {{existingDate}})",
+ "duplicateFile": "重复文件",
+ "copies": "份此文件的副本"
},
"uploadProgress": {
"title": "上传进度"
diff --git a/templates/components/detail/desktop-header.html b/templates/components/detail/desktop-header.html
index af00857c..991669d8 100644
--- a/templates/components/detail/desktop-header.html
+++ b/templates/components/detail/desktop-header.html
@@ -207,6 +207,14 @@
<span :title="item.fullText || item.text">${item.text}</span>
</span>
</div>
+
+ <!-- Duplicate Indicator -->
+ <button v-if="selectedRecording.duplicate_info"
+ @click="openDuplicatesModal(selectedRecording.duplicate_info)"
+ class="flex items-center gap-1.5 text-amber-500 hover:text-amber-400 transition-colors cursor-pointer">
+ <i class="fas fa-copy"></i>
+ <span>${ selectedRecording.duplicate_info.total_copies } ${ t('upload.copies') || 'copies' }</span>
+ </button>
</div>
</div>
</div>
diff --git a/templates/components/detail/mobile-header.html b/templates/components/detail/mobile-header.html
index cc3ee18d..0a21c39d 100644
--- a/templates/components/detail/mobile-header.html
+++ b/templates/components/detail/mobile-header.html
@@ -98,6 +98,13 @@
</span>
</template>
</div>
+ <!-- Duplicate Indicator -->
+ <button v-if="selectedRecording.duplicate_info"
+ @click.stop="openDuplicatesModal(selectedRecording.duplicate_info)"
+ class="flex items-center gap-1.5 text-sm text-amber-500 hover:text-amber-400 transition-colors cursor-pointer mt-2">
+ <i class="fas fa-copy"></i>
+ <span>${ selectedRecording.duplicate_info.total_copies } ${ t('upload.copies') || 'copies' }</span>
+ </button>
</div>
<!-- Action Buttons -->
<div class="flex items-center gap-2 overflow-x-auto pb-2">
diff --git a/templates/components/sidebar.html b/templates/components/sidebar.html
index ebe54e87..7ba3fe35 100644
--- a/templates/components/sidebar.html
+++ b/templates/components/sidebar.html
@@ -447,7 +447,7 @@
</div>
<!-- Tags -->
- <div v-if="getRecordingTags(recording).length > 0" class="flex flex-wrap gap-1 mt-1">
+ <div v-if="getRecordingTags(recording).length > 0 || recording.duplicate_info" class="flex flex-wrap items-center gap-1 mt-1">
<button v-for="tag in getRecordingTags(recording).slice(0, 4)" :key="tag.id"
@click.stop="filterByTag(tag)"
class="inline-flex items-center px-1.5 py-0.5 rounded-md text-xs font-medium hover:opacity-80 transition-all cursor-pointer"
@@ -461,6 +461,12 @@
:title="'More tags...'">
+${getRecordingTags(recording).length - 4}
</span>
+ <button v-if="recording.duplicate_info"
+ @click.stop="openDuplicatesModal(recording.duplicate_info)"
+ class="text-amber-500 hover:text-amber-400 transition-colors"
+ :title="recording.duplicate_info.total_copies + ' ' + (t('upload.copies') || 'copies')">
+ <i class="fas fa-copy text-xs"></i>
+ </button>
</div>
</div>
</div>
diff --git a/templates/index.html b/templates/index.html
index 69afb5ed..f0ecb2b8 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -104,6 +104,7 @@
{% include 'modals/recording-recovery-modal.html' %}
{% include 'modals/unified-share-modal.html' %}
{% include 'modals/share-delete-modal.html' %}
+ {% include 'modals/duplicates-modal.html' %}
{% include 'modals/global-error.html' %}
{% include 'modals/toast-container.html' %}
diff --git a/templates/modals/duplicates-modal.html b/templates/modals/duplicates-modal.html
new file mode 100644
index 00000000..fb035a1f
--- /dev/null
+++ b/templates/modals/duplicates-modal.html
@@ -0,0 +1,40 @@
+<!-- Duplicates List Modal -->
+<div v-if="showDuplicatesModal && duplicatesModalData" @click.self="showDuplicatesModal = false" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 p-4 backdrop-blur-sm">
+ <div class="bg-[var(--bg-secondary)] rounded-xl shadow-2xl w-full max-w-sm">
+ <div class="p-5">
+ <div class="flex items-center justify-between mb-4">
+ <div class="flex items-center gap-2.5">
+ <div class="flex items-center justify-center h-9 w-9 rounded-full bg-amber-100 dark:bg-amber-900/50">
+ <i class="fas fa-copy text-amber-500 dark:text-amber-400"></i>
+ </div>
+ <h3 class="text-base font-semibold text-[var(--text-primary)]">
+ ${ duplicatesModalData.total_copies } ${ t('upload.copies') || 'copies' }
+ </h3>
+ </div>
+ <button @click="showDuplicatesModal = false" class="text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors">
+ <i class="fas fa-times"></i>
+ </button>
+ </div>
+ <div class="space-y-1">
+ <button v-for="copy in duplicatesModalData.copies" :key="copy.id"
+ @click="navigateToDuplicate(copy.id)"
+ class="w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-left transition-colors"
+ :class="copy.is_self
+ ? 'bg-[var(--bg-accent-light)] border border-[var(--border-focus)]'
+ : 'hover:bg-[var(--bg-tertiary)]'">
+ <i class="fas fa-file-audio text-sm flex-shrink-0"
+ :class="copy.is_self ? 'text-[var(--text-accent)]' : 'text-[var(--text-muted)]'"></i>
+ <div class="min-w-0 flex-1">
+ <div class="text-sm font-medium truncate"
+ :class="copy.is_self ? 'text-[var(--text-accent)]' : 'text-[var(--text-primary)]'">
+ ${ copy.title }
+ <span v-if="copy.is_self" class="text-xs font-normal text-[var(--text-muted)] ml-1">(current)</span>
+ </div>
+ <div class="text-xs text-[var(--text-muted)]">${ copy.created_at }</div>
+ </div>
+ <i v-if="!copy.is_self" class="fas fa-chevron-right text-xs text-[var(--text-muted)]"></i>
+ </button>
+ </div>
+ </div>
+ </div>
+</div>