From 7ea295df486f6a7b8f798e782c4f52a7a31c246b Mon Sep 17 00:00:00 2001
From: Karishma Chadha <kchadha@scratch.mit.edu>
Date: Thu, 22 Mar 2018 16:11:43 -0400
Subject: [PATCH] Recorded sounds should have actual md5s.

---
 src/containers/record-modal.jsx | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/containers/record-modal.jsx b/src/containers/record-modal.jsx
index ee05f298b..45f847807 100644
--- a/src/containers/record-modal.jsx
+++ b/src/containers/record-modal.jsx
@@ -73,22 +73,24 @@ class RecordModal extends React.Component {
                 sampleRate: this.state.sampleRate,
                 channelData: [clippedSamples]
             }).then(wavBuffer => {
-                const md5 = String(Math.floor(100000 * Math.random()));
                 const vmSound = {
                     format: '',
-                    md5: `${md5}.wav`,
+                    dataFormat: 'wav',
                     name: `recording ${this.props.vm.editingTarget.sprite.sounds.length}`
                 };
 
-                // Load the encoded .wav into the storage cache
+                // Load the encoded .wav into the storage cache and get resulting
+                // md5 from storage
                 const storage = this.props.vm.runtime.storage;
-                storage.builtinHelper.cache(
+                const md5 = storage.builtinHelper.cache(
                     storage.AssetType.Sound,
                     storage.DataFormat.WAV,
                     new Uint8Array(wavBuffer),
-                    md5
                 );
 
+                // update vmSound object with md5 property
+                vmSound.md5 = `${md5}.${vmSound.dataFormat}`;
+
                 this.props.vm.addSound(vmSound).then(() => {
                     this.props.onClose();
                     this.props.onNewSound();
-- 
GitLab