Skip to content

Commit

Permalink
Load project URL in hash
Browse files Browse the repository at this point in the history
  • Loading branch information
yokobond committed Apr 29, 2024
1 parent 22a846f commit 74e7afa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/hash-parser-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const HashParserHOC = function (WrappedComponent) {
window.removeEventListener('hashchange', this.handleHashChange);
}
handleHashChange () {
const hashValue = window.location.hash.substr(1);
const hashURLMatch = decodeURIComponent(hashValue).match(/^(http|https):\/\/(.*)/);
if (hashURLMatch) {
this.props.setProjectId(hashURLMatch[0]);
return;
}
const hashMatch = window.location.hash.match(/#(\d+)/);
const hashProjectId = hashMatch === null ? defaultProjectId : hashMatch[1];
this.props.setProjectId(hashProjectId.toString());
Expand Down
3 changes: 3 additions & 0 deletions src/lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Storage extends ScratchStorage {
this.projectToken = projectToken;
}
getProjectGetConfig (projectAsset) {
if (/^(http|https):\/\//.test(projectAsset.assetId)) {
return projectAsset.assetId;
}
const path = `${this.projectHost}/${projectAsset.assetId}`;
const qs = this.projectToken ? `?token=${this.projectToken}` : '';
return path + qs;
Expand Down

0 comments on commit 74e7afa

Please sign in to comment.