use access token while resolving github content

pull/1/head
yann300 6 years ago
parent 1fe0ede5de
commit b9ae2b42a6
  1. 6
      src/app/compiler/compiler-imports.js
  2. 7
      src/app/tabs/compile-tab.js
  3. 2
      src/app/tabs/settings-tab.js

@ -4,14 +4,16 @@ var swarmgw = require('swarmgw')()
var request = require('request') var request = require('request')
module.exports = class CompilerImports { module.exports = class CompilerImports {
constructor () { constructor (githubAccessToken) {
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) {
var accessToken = this.githubAccessToken() ? '?access_token=' + this.githubAccessToken() : ''
return request.get( return request.get(
{ {
url: 'https://api.github.com/repos/' + root + '/contents/' + path, url: 'https://api.github.com/repos/' + root + '/contents/' + path + accessToken,
json: true json: true
}, },
(err, r, data) => { (err, r, data) => {

@ -44,9 +44,8 @@ module.exports = class CompileTab {
self._components = {} self._components = {}
self._components.registry = localRegistry || globalRegistry self._components.registry = localRegistry || globalRegistry
self._components.queryParams = new QueryParams() self._components.queryParams = new QueryParams()
self._components.compilerImport = new CompilerImport() self._components.compilerImport = new CompilerImport(() => { return self._deps.config.get('settings/gist-access-token') })
self._components.compiler = new Compiler((url, cb) => self.importFileCb(url, cb)) self._components.compiler = new Compiler((url, cb) => self.importFileCb(url, cb))
// dependencies // dependencies
self._deps = { self._deps = {
editor: self._components.registry.get('editor').api, editor: self._components.registry.get('editor').api,
@ -504,8 +503,8 @@ module.exports = class CompileTab {
}, },
(error, content, cleanUrl, type, url) => { (error, content, cleanUrl, type, url) => {
if (!error) { if (!error) {
if (self._deps.filesProviders[type]) { if (self._deps.fileProviders[type]) {
self._deps.filesProviders[type].addReadOnly(cleanUrl, content, url) self._deps.fileProviders[type].addReadOnly(cleanUrl, content, url)
} }
cb(null, content) cb(null, content)
} else { } else {

@ -92,7 +92,7 @@ module.exports = class SettingsTab {
self._view.gistToken = yo` self._view.gistToken = yo`
<div class="${css.info}"> <div class="${css.info}">
<div class=${css.title}>Gist Access Token</div> <div class=${css.title}>Gist Access Token</div>
<div class="${css.crowNoFlex}">Manage the access token used to publish to Gist.</div> <div class="${css.crowNoFlex}">Manage the access token used to publish to Gist and retrieve Github contents.</div>
<div class="${css.crowNoFlex}">Go to github token page (link below) to create a new token and save it in Remix. Make sure this token has only 'create gist' permission.</div> <div class="${css.crowNoFlex}">Go to github token page (link below) to create a new token and save it in Remix. Make sure this token has only 'create gist' permission.</div>
<div class="${css.crowNoFlex}"><a target="_blank" href="https://github.com/settings/tokens">https://github.com/settings/tokens</a></div> <div class="${css.crowNoFlex}"><a target="_blank" href="https://github.com/settings/tokens">https://github.com/settings/tokens</a></div>
<div class="${css.crowNoFlex}">${self._view.gistToken}</div> <div class="${css.crowNoFlex}">${self._view.gistToken}</div>

Loading…
Cancel
Save