diff --git a/src/containers/record-modal.jsx b/src/containers/record-modal.jsx index 8a57c03d7..ee0007ab4 100644 --- a/src/containers/record-modal.jsx +++ b/src/containers/record-modal.jsx @@ -80,17 +80,19 @@ class RecordModal extends React.Component { sampleCount: clippedSamples.length }; - // Load the encoded .wav into the storage cache and get resulting - // md5 from storage - const storage = this.props.vm.runtime.storage; - const md5 = storage.builtinHelper.cache( + // Create an asset from the encoded .wav and get resulting md5 + const storage = this.props.vm.storage; + vmSound.asset = storage.createAsset( storage.AssetType.Sound, storage.DataFormat.WAV, new Uint8Array(wavBuffer), + null, + true // generate md5 ); + vmSound.assetId = vmSound.asset.assetId; // update vmSound object with md5 property - vmSound.md5 = `${md5}.${vmSound.dataFormat}`; + vmSound.md5 = `${vmSound.assetId}.${vmSound.dataFormat}`; // The VM will update the sound name to a fresh name // if the following is already taken vmSound.name = 'recording1'; diff --git a/src/lib/file-uploader.js b/src/lib/file-uploader.js index afa4371dd..481685684 100644 --- a/src/lib/file-uploader.js +++ b/src/lib/file-uploader.js @@ -63,17 +63,20 @@ const handleFileUpload = function (fileInput, onload) { * which can be used to look up the data in storage */ const cacheAsset = function (storage, fileName, assetType, dataFormat, data) { - const md5 = storage.builtinHelper.cache( + const asset = storage.createAsset( assetType, dataFormat, - data + data, + null, + true // generate md5 ); return { name: fileName, dataFormat: dataFormat, - md5: `${md5}.${dataFormat}`, - assetId: md5 + asset: asset, + md5: `${asset.assetId}.${dataFormat}`, + assetId: asset.assetId }; }; diff --git a/src/lib/storage.js b/src/lib/storage.js index b0634d9c3..7dc057e39 100644 --- a/src/lib/storage.js +++ b/src/lib/storage.js @@ -55,7 +55,7 @@ class Storage extends ScratchStorage { } cacheDefaultProject () { const defaultProjectAssets = defaultProject(this.translator); - defaultProjectAssets.forEach(asset => this.cache( + defaultProjectAssets.forEach(asset => this.builtinHelper._store( this.AssetType[asset.assetType], this.DataFormat[asset.dataFormat], asset.data,