Spaces:
Running
Running
File size: 849 Bytes
f2bee8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import blockToImage from './block-to-image';
import createThumbnail from './thumbnail';
import {Base64} from 'js-base64';
const codePayload = ({blockObjects, topBlockId}) => {
const payload = {
type: 'script', // Needs to match backpack-server type name
name: 'code', // All code currently gets the same name
mime: 'application/json',
// Backpack expects a base64 encoded string to store. Cannot use btoa because
// the code can contain characters outside the 0-255 code-point range supported by btoa
body: Base64.encode(JSON.stringify(blockObjects)) // Base64 encode the json
};
return blockToImage(topBlockId)
.then(createThumbnail)
.then(thumbnail => {
payload.thumbnail = thumbnail;
return payload;
});
};
export default codePayload;
|