Make sure to save assets before sending them to the backpack

This prevents assets from existing in the backpack server without also existing in the asset server.
This commit is contained in:
Paul Kaplan committed 2019-04-11 08:29:46 -04:00
1 parent 7fcbae60bc
commit 17e28b2a24
1 file changed
+11
+11
View File
@@ -83,12 +83,15 @@ class Backpack extends React.Component {
}
handleDrop (dragInfo) {
let payloader = null;
let presaveAsset = null;
switch (dragInfo.dragType) {
case DragConstants.COSTUME:
payloader = costumePayload;
presaveAsset = dragInfo.asset;
break;
case DragConstants.SOUND:
payloader = soundPayload;
presaveAsset = dragInfo.asset;
break;
case DragConstants.SPRITE:
payloader = spritePayload;
@@ -102,6 +105,14 @@ class Backpack extends React.Component {
// Creating the payload is async, so set loading before starting
this.setState({loading: true}, () => {
payloader(dragInfo.payload, this.props.vm)
.then(payload => {
// Force the asset to save to the asset server before storing in backpack
// Ensures any asset present in the backpack is also on the asset server
if (presaveAsset && !presaveAsset.clean) {
return storage.store(presaveAsset).then(() => payload);
}
return payload;
})
.then(payload => saveBackpackObject({
host: this.props.host,
token: this.props.token,