Skip to content

Commit 893f749

Browse files
committed
scratch project remix support
1 parent 4319be1 commit 893f749

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

src/lib/project-fetcher-hoc.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
5050
'fetchProject'
5151
]);
5252
storage.setProjectHost(props.projectHost);
53+
storage.setCTProjectHost(props.projectHost);
5354
storage.setProjectToken(props.projectToken);
5455
storage.setAssetHost(props.assetHost);
5556
storage.setAssetLoadHost(props.assetLoadHost);

src/lib/project-saver-hoc.jsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,24 @@ const ProjectSaverHOC = function (WrappedComponent) {
196196
}
197197
createRemixToStorage () {
198198
this.props.onShowCreatingRemixAlert();
199-
return this.storeProject(null, {
199+
const requestParams = {
200200
originalId: this.props.reduxProjectId,
201201
isRemix: 1,
202202
title: this.props.reduxProjectTitle
203-
})
203+
};
204+
if (this.props.isScratchProject) {
205+
requestParams.source = 'scratch';
206+
207+
// Mark all assets as dirty so storeProject() will upload them
208+
// to the CodeTorch S3/Backend instead of relying on Scratch CDNs
209+
// originally we were going to optimize and load from Scratch CDN until user modifies
210+
// but with how bad Scratch has been this is safer
211+
this.props.vm.assets.forEach(asset => {
212+
asset.clean = false;
213+
});
214+
}
215+
216+
return this.storeProject(null, requestParams)
204217
.then(response => {
205218
this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
206219
this.props.onShowRemixSuccessAlert();
@@ -367,6 +380,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
367380
isRemixing: PropTypes.bool,
368381
isShared: PropTypes.bool,
369382
isShowingSaveable: PropTypes.bool,
383+
isScratchProject: PropTypes.bool,
370384
isShowingWithId: PropTypes.bool,
371385
isShowingWithoutId: PropTypes.bool,
372386
isUpdating: PropTypes.bool,
@@ -424,7 +438,8 @@ const ProjectSaverHOC = function (WrappedComponent) {
424438
projectChanged: state.scratchGui.projectChanged,
425439
reduxProjectId: state.scratchGui.projectState.projectId,
426440
reduxProjectTitle: state.scratchGui.projectTitle,
427-
vm: state.scratchGui.vm
441+
vm: state.scratchGui.vm,
442+
isScratchProject: state.scratchGui.projectState.isScratchProject
428443
};
429444
};
430445
const mapDispatchToProps = dispatch => ({

src/lib/save-project-to-server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default function (projectId, vmState, params) {
2929
if (Object.prototype.hasOwnProperty.call(params, 'isCopy')) queryParams.is_copy = params.isCopy;
3030
if (Object.prototype.hasOwnProperty.call(params, 'isRemix')) queryParams.is_remix = params.isRemix;
3131
if (Object.prototype.hasOwnProperty.call(params, 'title')) queryParams.title = params.title;
32+
if (Object.prototype.hasOwnProperty.call(params, 'source')) queryParams.source = params.source;
33+
3234
let qs = queryString.stringify(queryParams);
3335
if (qs) qs = `?${qs}`;
3436

@@ -42,12 +44,12 @@ export default function (projectId, vmState, params) {
4244
if (creatingProject) {
4345
Object.assign(opts, {
4446
method: 'post',
45-
url: `${storage.projectHost}/${qs}`
47+
url: `${storage.CTprojectHost}/${qs}`
4648
});
4749
} else {
4850
Object.assign(opts, {
4951
method: 'put',
50-
url: `${storage.projectHost}/${projectId}${qs}`
52+
url: `${storage.CTprojectHost}/${projectId}${qs}`
5153
});
5254
}
5355

src/lib/storage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Storage extends ScratchStorage {
4040
setProjectHost (projectHost) {
4141
this.projectHost = projectHost;
4242
}
43+
setCTProjectHost (projectHost) { // this is the same regardless of wether scratch project or not
44+
this.CTprojectHost = projectHost;
45+
}
4346
setProjectToken (projectToken) {
4447
this.projectToken = projectToken;
4548
}

src/lib/tw-project-meta-fetcher-hoc.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export const fetchProjectMeta = async (projectId, isScratch) => {
4343
if (res.ok) {
4444
if (isScratch){
4545
storage.setScratchProjectToken(data.project_token); // so we can load actual project JSON file
46+
47+
const canRemix = (authToken && authToken !== 'anonymous') ? 'true' : 'false';
4648
return {
4749
title: data.title,
4850
author: {
@@ -52,7 +54,7 @@ export const fetchProjectMeta = async (projectId, isScratch) => {
5254
instructions: data.instructions,
5355
description: data.description,
5456
canSave: 'false',
55-
canRemix: 'false'
57+
canRemix: canRemix
5658
};
5759
}
5860
return data;

0 commit comments

Comments
 (0)