use registry for getting the access token

pull/1/head
yann300 5 years ago
parent 93ca4d653a
commit c61de7167b
  1. 11
      src/app/compiler/compiler-imports.js

@ -1,4 +1,5 @@
'use strict' 'use strict'
const globalRegistry = require('../../global/registry')
var base64 = require('js-base64').Base64 var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw')() var swarmgw = require('swarmgw')()
var resolver = require('@resolver-engine/imports').ImportsEngine() var resolver = require('@resolver-engine/imports').ImportsEngine()
@ -14,22 +15,22 @@ const profile = {
} }
module.exports = class CompilerImports extends Plugin { module.exports = class CompilerImports extends Plugin {
constructor (githubAccessToken) { constructor () {
super(profile) super(profile)
this.githubAccessToken = githubAccessToken || (() => {})
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.
} }
handleGithubCall (root, path, cb) { handleGithubCall (root, path, cb) {
let param = '?' let param = '?'
// const token = await this.call('settings', 'getGithubAccessToken')
param += this.githubAccessToken() ? 'access_token=' + this.githubAccessToken() : '' 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
param += token ? 'access_token=' + token : ''
const regex = path.match(/blob\/([^/]+)\/(.*)/) const regex = path.match(/blob\/([^/]+)\/(.*)/)
if (regex) { if (regex) {
// if we have /blob/master/+path we extract the branch name "master" and add it as a parameter to the github api // if we have /blob/master/+path we extract the branch name "master" and add it as a parameter to the github api
// the ref can be branch name, tag, commit id // the ref can be branch name, tag, commit id
const reference = regex[1] const reference = regex[1]
param += 'ref=' + reference param += '&ref=' + reference
path = path.replace(`blob/${reference}/`, '') path = path.replace(`blob/${reference}/`, '')
} }
return request.get( return request.get(

Loading…
Cancel
Save