-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App Center: correctly use repo's latest version for baseUrl (#729)
- Loading branch information
Showing
5 changed files
with
67 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { appLocator, ipfsDefaultConf } from './environment' | ||
import { appendTrailingSlash } from './utils' | ||
|
||
/* | ||
* Supported locations: | ||
* ipfs:{IPFS_HASH} | ||
* http:{HOST} | ||
* http:{HOST}:{PORT} | ||
* http:{HOST}:{PORT}/{PATH} | ||
* http:http(s)://{HOST} | ||
* http:http(s)://{HOST}:{PORT} | ||
* http:http(s)://{HOST}:{PORT}/{PATH} | ||
*/ | ||
function contentBaseUrl(content, gateway) { | ||
if (!content) { | ||
return '' | ||
} | ||
|
||
const { provider, location } = content | ||
if (provider === 'ipfs') { | ||
return `${gateway}/${location}/` | ||
} | ||
if (provider === 'http') { | ||
return /^https?:\/\//.test(location) | ||
? appendTrailingSlash(location) | ||
: `http://${location}/` | ||
} | ||
return '' | ||
} | ||
|
||
export function appBaseUrl(app, gateway = ipfsDefaultConf.gateway) { | ||
// Support overriding app URLs, see network-config.js | ||
if (appLocator[app.appId]) { | ||
return appLocator[app.appId] | ||
} | ||
|
||
return contentBaseUrl(app.content, gateway) | ||
} | ||
|
||
export function repoBaseUrl(repo, gateway = ipfsDefaultConf.gateway) { | ||
const { appId, latestVersion = {} } = repo | ||
|
||
// Support overriding app URLs, see network-config.js | ||
if (appLocator[appId]) { | ||
return appLocator[appId] | ||
} | ||
|
||
return contentBaseUrl( | ||
// The latest version's content is the artifact.json and manifest.json, so we need to | ||
// look up content again for the actual content location | ||
latestVersion.content && latestVersion.content.content, | ||
gateway | ||
) | ||
} |