Commit 01ecf2e3 authored by aniket-engg's avatar aniket-engg Committed by Aniket

protocol based swarm gateway

parent 1d6ae33b
...@@ -21,7 +21,8 @@ module.exports = class CompilerImports extends Plugin { ...@@ -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 { ...@@ -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 { ...@@ -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 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment