protocol based swarm gateway

pull/713/head
aniket-engg 4 years ago committed by Aniket
parent 1d6ae33be7
commit 01ecf2e385
  1. 3
      apps/remix-ide/src/app/compiler/compiler-imports.js
  2. 6
      libs/remix-url-resolver/src/resolve.ts

@ -21,7 +21,8 @@ module.exports = class CompilerImports extends Plugin {
this.fileManager = fileManager this.fileManager = fileManager
// const token = await this.call('settings', 'getGithubAccessToken') // const token = await this.call('settings', 'getGithubAccessToken')
const token = globalRegistry.get('config').api.get('settings/gist-access-token') // TODO replace with the plugin call above https://github.com/ethereum/remix-ide/issues/2288 const token = globalRegistry.get('config').api.get('settings/gist-access-token') // TODO replace with the plugin call above https://github.com/ethereum/remix-ide/issues/2288
this.urlResolver = new RemixURLResolver(token) const protocol = window.location.protocol
this.urlResolver = new RemixURLResolver(token, protocol)
this.previouslyHandled = {} // cache import so we don't make the request at each compilation. this.previouslyHandled = {} // cache import so we don't make the request at each compilation.
} }

@ -25,10 +25,12 @@ interface HandlerResponse {
export class RemixURLResolver { export class RemixURLResolver {
private previouslyHandled: PreviouslyHandledImports private previouslyHandled: PreviouslyHandledImports
gistAccessToken: string gistAccessToken: string
protocol: string
constructor(gistToken?: string) { constructor(gistToken?: string, protocol = 'http:') {
this.previouslyHandled = {} this.previouslyHandled = {}
this.gistAccessToken = gistToken ? gistToken : '' this.gistAccessToken = gistToken ? gistToken : ''
this.protocol = protocol
} }
/** /**
@ -90,7 +92,7 @@ export class RemixURLResolver {
async handleSwarm(url: string, cleanUrl: string): Promise<HandlerResponse> { async handleSwarm(url: string, cleanUrl: string): Promise<HandlerResponse> {
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
try { try {
const bzz = new Bzz({url: 'http://swarm-gateways.net'}); const bzz = new Bzz({url: this.protocol + '//swarm-gateways.net'});
const url = bzz.getDownloadURL(cleanUrl, {mode: 'raw'}) const url = bzz.getDownloadURL(cleanUrl, {mode: 'raw'})
const response: AxiosResponse = await axios.get(url) const response: AxiosResponse = await axios.get(url)
return { content: response.data, cleanUrl } return { content: response.data, cleanUrl }

Loading…
Cancel
Save