mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 16:41:34 -05:00
Merge pull request #6865 from LLK/hotfix/project-token
Hotfix/project token
This commit is contained in:
commit
44700e6cde
5 changed files with 83 additions and 55 deletions
|
@ -11,9 +11,19 @@ class Storage extends ScratchStorage {
|
|||
super();
|
||||
this.addWebSource(
|
||||
[this.AssetType.Project],
|
||||
projectAsset => `${PROJECT_HOST}/${projectAsset.assetId}`
|
||||
this.getProjectGetConfig.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
setProjectToken (projectToken) {
|
||||
this.projectToken = projectToken;
|
||||
}
|
||||
|
||||
getProjectGetConfig (projectAsset) {
|
||||
const path = `${PROJECT_HOST}/${projectAsset.assetId}`;
|
||||
const qs = this.projectToken ? `?token=${this.projectToken}` : '';
|
||||
return path + qs;
|
||||
}
|
||||
}
|
||||
|
||||
const storage = new Storage();
|
||||
|
|
|
@ -40,6 +40,7 @@ class EmbedView extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
if (this.props.projectInfo && this.props.projectInfo.project_token){
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Meta projectInfo={this.props.projectInfo} />
|
||||
|
@ -50,10 +51,13 @@ class EmbedView extends React.Component {
|
|||
projectHost={this.props.projectHost}
|
||||
projectId={this.state.projectId}
|
||||
projectTitle={this.props.projectInfo.title}
|
||||
projectToken={this.props.projectInfo.project_token}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
EmbedView.propTypes = {
|
||||
|
|
|
@ -359,6 +359,7 @@ const PreviewPresentation = ({
|
|||
isFullScreen={isFullScreen}
|
||||
previewInfoVisible="false"
|
||||
projectHost={projectHost}
|
||||
projectToken={projectInfo.project_token}
|
||||
projectId={projectId}
|
||||
onGreenFlag={onGreenFlag}
|
||||
onProjectLoaded={onProjectLoaded}
|
||||
|
|
|
@ -142,7 +142,6 @@ class Preview extends React.Component {
|
|||
this.props.sessionStatus === sessionActions.Status.FETCHED) ||
|
||||
(this.state.projectId !== prevState.projectId))) {
|
||||
this.fetchCommunityData();
|
||||
this.getProjectData(this.state.projectId, true /* Show cloud/username alerts */);
|
||||
if (this.state.justShared) {
|
||||
this.setState({ // eslint-disable-line react/no-did-update-set-state
|
||||
justShared: false
|
||||
|
@ -158,6 +157,10 @@ class Preview extends React.Component {
|
|||
});
|
||||
}
|
||||
}
|
||||
if (this.props.projectInfo.id !== prevProps.projectInfo.id) {
|
||||
storage.setProjectToken(this.props.projectInfo.project_token);
|
||||
this.loadProjectData(this.state.projectId, true /* Show cloud/username alerts */);
|
||||
}
|
||||
if (this.props.projectInfo.id !== prevProps.projectInfo.id) {
|
||||
if (typeof this.props.projectInfo.id === 'undefined') {
|
||||
this.initCounts(0, 0);
|
||||
|
@ -196,7 +199,8 @@ class Preview extends React.Component {
|
|||
|
||||
// Switching out of editor mode, refresh data that comes from project json
|
||||
if (this.props.playerMode && !prevProps.playerMode) {
|
||||
this.getProjectData(
|
||||
storage.setProjectToken(this.props.projectInfo.project_token);
|
||||
this.loadProjectData(
|
||||
this.state.projectId,
|
||||
false // Do not show cloud/username alerts again
|
||||
);
|
||||
|
@ -323,7 +327,7 @@ class Preview extends React.Component {
|
|||
}
|
||||
}
|
||||
}
|
||||
getProjectData (projectId, showAlerts) {
|
||||
loadProjectData (projectId, showAlerts) {
|
||||
if (projectId <= 0) return 0;
|
||||
storage
|
||||
.load(storage.AssetType.Project, projectId, storage.DataFormat.JSON)
|
||||
|
@ -713,6 +717,11 @@ class Preview extends React.Component {
|
|||
);
|
||||
}
|
||||
render () {
|
||||
|
||||
// Only show GUI if the project has no id, is a loaded local project, or has the project token loaded
|
||||
const showGUI = (!this.state.projectId || this.state.projectId === '0' || this.state.isProjectLoaded ||
|
||||
(this.props.projectInfo && this.props.projectInfo.project_token));
|
||||
|
||||
if (this.props.projectNotAvailable || this.state.invalidProject) {
|
||||
return (
|
||||
<Page>
|
||||
|
@ -829,6 +838,7 @@ class Preview extends React.Component {
|
|||
/>
|
||||
</Page> :
|
||||
<React.Fragment>
|
||||
{showGUI && (
|
||||
<IntlGUI
|
||||
assetHost={this.props.assetHost}
|
||||
authorId={this.props.authorId}
|
||||
|
@ -849,6 +859,7 @@ class Preview extends React.Component {
|
|||
hasCloudPermission={this.props.isScratcher}
|
||||
isShared={this.props.isShared}
|
||||
projectHost={this.props.projectHost}
|
||||
projectToken={this.props.projectInfo.project_token}
|
||||
projectId={this.state.projectId}
|
||||
projectTitle={this.props.projectInfo.title}
|
||||
renderLogin={this.renderLogin}
|
||||
|
@ -866,6 +877,7 @@ class Preview extends React.Component {
|
|||
onUpdateProjectThumbnail={this.props.handleUpdateProjectThumbnail}
|
||||
onUpdateProjectTitle={this.handleUpdateProjectTitle}
|
||||
/>
|
||||
)}
|
||||
{this.props.registrationOpen && (
|
||||
this.props.useScratch3Registration ? (
|
||||
<Scratch3Registration
|
||||
|
|
|
@ -31,5 +31,6 @@ export const projectShape = shape({
|
|||
remix: shape({
|
||||
parent: number,
|
||||
root: number
|
||||
})
|
||||
}),
|
||||
project_token: string
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue