Add files via upload

This commit is contained in:
Cola-Echo
2025-12-31 14:11:05 +08:00
committed by GitHub
parent 40526f614d
commit 5068b46702
3 changed files with 264 additions and 1 deletions

View File

@@ -275,3 +275,51 @@ export async function getStorageStats() {
};
});
}
/**
* 获取所有语音记录,按联系人分组
* @returns {Promise<Object>} { contactIndex: { count, totalDuration } }
*/
export async function getAllVoiceRecordingsGroupedByContact() {
await initAudioDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction([STORE_NAME], 'readonly');
const store = transaction.objectStore(STORE_NAME);
const request = store.getAll();
request.onsuccess = () => {
const records = request.result;
const grouped = {};
records.forEach(record => {
const idx = record.contactIndex;
if (!grouped[idx]) {
grouped[idx] = { count: 0, totalDuration: 0 };
}
grouped[idx].count++;
grouped[idx].totalDuration += record.duration || 0;
});
resolve(grouped);
};
request.onerror = () => {
reject(request.error);
};
});
}
/**
* 删除指定联系人的所有语音记录
* @param {number} contactIndex - 联系人索引
* @returns {Promise<number>} 删除的记录数量
*/
export async function deleteVoiceRecordingsByContact(contactIndex) {
const records = await getVoiceRecordingsByContact(contactIndex);
for (const record of records) {
await deleteVoiceRecording(record.id);
}
console.log(`[可乐] 已删除联系人 ${contactIndex}${records.length} 条语音记录`);
return records.length;
}