Commit c61de716 authored by yann300's avatar yann300

use registry for getting the access token

parent 93ca4d65
'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 = { ...@@ -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(
......
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