Merge pull request #6865 from LLK/hotfix/project-token

Hotfix/project token
This commit is contained in:
Tom Lum 2022-06-08 10:05:38 -04:00 committed by GitHub
commit 44700e6cde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 55 deletions

View file

@ -11,9 +11,19 @@ class Storage extends ScratchStorage {
super(); super();
this.addWebSource( this.addWebSource(
[this.AssetType.Project], [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(); const storage = new Storage();

View file

@ -40,19 +40,23 @@ class EmbedView extends React.Component {
); );
} }
return ( if (this.props.projectInfo && this.props.projectInfo.project_token){
<React.Fragment> return (
<Meta projectInfo={this.props.projectInfo} /> <React.Fragment>
<IntlGUI <Meta projectInfo={this.props.projectInfo} />
assetHost={this.props.assetHost} <IntlGUI
basePath="/" assetHost={this.props.assetHost}
className="gui" basePath="/"
projectHost={this.props.projectHost} className="gui"
projectId={this.state.projectId} projectHost={this.props.projectHost}
projectTitle={this.props.projectInfo.title} projectId={this.state.projectId}
/> projectTitle={this.props.projectInfo.title}
</React.Fragment> projectToken={this.props.projectInfo.project_token}
); />
</React.Fragment>
);
}
return null;
} }
} }

View file

@ -359,6 +359,7 @@ const PreviewPresentation = ({
isFullScreen={isFullScreen} isFullScreen={isFullScreen}
previewInfoVisible="false" previewInfoVisible="false"
projectHost={projectHost} projectHost={projectHost}
projectToken={projectInfo.project_token}
projectId={projectId} projectId={projectId}
onGreenFlag={onGreenFlag} onGreenFlag={onGreenFlag}
onProjectLoaded={onProjectLoaded} onProjectLoaded={onProjectLoaded}

View file

@ -142,7 +142,6 @@ class Preview extends React.Component {
this.props.sessionStatus === sessionActions.Status.FETCHED) || this.props.sessionStatus === sessionActions.Status.FETCHED) ||
(this.state.projectId !== prevState.projectId))) { (this.state.projectId !== prevState.projectId))) {
this.fetchCommunityData(); this.fetchCommunityData();
this.getProjectData(this.state.projectId, true /* Show cloud/username alerts */);
if (this.state.justShared) { if (this.state.justShared) {
this.setState({ // eslint-disable-line react/no-did-update-set-state this.setState({ // eslint-disable-line react/no-did-update-set-state
justShared: false 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 (this.props.projectInfo.id !== prevProps.projectInfo.id) {
if (typeof this.props.projectInfo.id === 'undefined') { if (typeof this.props.projectInfo.id === 'undefined') {
this.initCounts(0, 0); 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 // Switching out of editor mode, refresh data that comes from project json
if (this.props.playerMode && !prevProps.playerMode) { if (this.props.playerMode && !prevProps.playerMode) {
this.getProjectData( storage.setProjectToken(this.props.projectInfo.project_token);
this.loadProjectData(
this.state.projectId, this.state.projectId,
false // Do not show cloud/username alerts again 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; if (projectId <= 0) return 0;
storage storage
.load(storage.AssetType.Project, projectId, storage.DataFormat.JSON) .load(storage.AssetType.Project, projectId, storage.DataFormat.JSON)
@ -713,6 +717,11 @@ class Preview extends React.Component {
); );
} }
render () { 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) { if (this.props.projectNotAvailable || this.state.invalidProject) {
return ( return (
<Page> <Page>
@ -829,43 +838,46 @@ class Preview extends React.Component {
/> />
</Page> : </Page> :
<React.Fragment> <React.Fragment>
<IntlGUI {showGUI && (
assetHost={this.props.assetHost} <IntlGUI
authorId={this.props.authorId} assetHost={this.props.assetHost}
authorThumbnailUrl={this.props.authorThumbnailUrl} authorId={this.props.authorId}
authorUsername={this.props.authorUsername} authorThumbnailUrl={this.props.authorThumbnailUrl}
backpackHost={this.props.backpackHost} authorUsername={this.props.authorUsername}
backpackVisible={this.props.canUseBackpack} backpackHost={this.props.backpackHost}
basePath="/" backpackVisible={this.props.canUseBackpack}
canCreateCopy={this.props.canCreateCopy} basePath="/"
canCreateNew={this.props.canCreateNew} canCreateCopy={this.props.canCreateCopy}
canEditTitle={this.props.canEditTitleInEditor} canCreateNew={this.props.canCreateNew}
canRemix={this.props.canRemix} canEditTitle={this.props.canEditTitleInEditor}
canSave={this.props.canSave} canRemix={this.props.canRemix}
canShare={this.props.canShare} canSave={this.props.canSave}
className="gui" canShare={this.props.canShare}
cloudHost={this.props.cloudHost} className="gui"
enableCommunity={this.props.enableCommunity} cloudHost={this.props.cloudHost}
hasCloudPermission={this.props.isScratcher} enableCommunity={this.props.enableCommunity}
isShared={this.props.isShared} hasCloudPermission={this.props.isScratcher}
projectHost={this.props.projectHost} isShared={this.props.isShared}
projectId={this.state.projectId} projectHost={this.props.projectHost}
projectTitle={this.props.projectInfo.title} projectToken={this.props.projectInfo.project_token}
renderLogin={this.renderLogin} projectId={this.state.projectId}
onClickLogo={this.handleClickLogo} projectTitle={this.props.projectInfo.title}
onGreenFlag={this.handleGreenFlag} renderLogin={this.renderLogin}
onLogOut={this.props.handleLogOut} onClickLogo={this.handleClickLogo}
onOpenRegistration={this.props.handleOpenRegistration} onGreenFlag={this.handleGreenFlag}
onProjectLoaded={this.handleProjectLoaded} onLogOut={this.props.handleLogOut}
onRemixing={this.handleIsRemixing} onOpenRegistration={this.props.handleOpenRegistration}
onSetLanguage={this.handleSetLanguage} onProjectLoaded={this.handleProjectLoaded}
onShare={this.handleShare} onRemixing={this.handleIsRemixing}
onToggleLoginOpen={this.props.handleToggleLoginOpen} onSetLanguage={this.handleSetLanguage}
onUpdateProjectData={this.handleUpdateProjectData} onShare={this.handleShare}
onUpdateProjectId={this.handleUpdateProjectId} onToggleLoginOpen={this.props.handleToggleLoginOpen}
onUpdateProjectThumbnail={this.props.handleUpdateProjectThumbnail} onUpdateProjectData={this.handleUpdateProjectData}
onUpdateProjectTitle={this.handleUpdateProjectTitle} onUpdateProjectId={this.handleUpdateProjectId}
/> onUpdateProjectThumbnail={this.props.handleUpdateProjectThumbnail}
onUpdateProjectTitle={this.handleUpdateProjectTitle}
/>
)}
{this.props.registrationOpen && ( {this.props.registrationOpen && (
this.props.useScratch3Registration ? ( this.props.useScratch3Registration ? (
<Scratch3Registration <Scratch3Registration

View file

@ -31,5 +31,6 @@ export const projectShape = shape({
remix: shape({ remix: shape({
parent: number, parent: number,
root: number root: number
}) }),
project_token: string
}); });