Add ScratchStorage subclass for getting project JSON

This commit is contained in:
Connor Hudson 2018-06-19 11:24:54 -04:00
parent df0db1b2c3
commit ca91294b31

26
src/lib/storage.js Normal file
View file

@ -0,0 +1,26 @@
import ScratchStorage from 'scratch-storage';
const PROJECT_SERVER = 'https://projects.scratch.mit.edu';
/**
* Wrapper for ScratchStorage which adds default web sources.
* @todo make this more configurable
*/
class Storage extends ScratchStorage {
constructor () {
super();
this.addWebSource( // https://github.com/babel/babel/issues/7022
[this.AssetType.Project],
projectAsset => {
const [projectId, revision] = projectAsset.assetId.split('.');
return revision ?
`${PROJECT_SERVER}/internalapi/project/${projectId}/get/${revision}` :
`${PROJECT_SERVER}/internalapi/project/${projectId}/get/`;
}
);
}
}
const storage = new Storage();
export default storage;