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')
module.exports = class CompilerImports {
constructor () {
constructor (githubAccessToken) {
this.githubAccessToken = githubAccessToken || (() => {})
this.previouslyHandled = {} // cache import so we don't make the request at each compilation.
}
handleGithubCall (root, path, cb) {
var accessToken = this.githubAccessToken() ? '?access_token=' + this.githubAccessToken() : ''
return request.get(
{
url: 'https://api.github.com/repos/' + root + '/contents/' + path,
url: 'https://api.github.com/repos/' + root + '/contents/' + path + accessToken,
json: true
},
(err, r, data) => {

@ -44,9 +44,8 @@ module.exports = class CompileTab {
self._components = {}
self._components.registry = localRegistry || globalRegistry
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))
// dependencies
self._deps = {
editor: self._components.registry.get('editor').api,
@ -504,8 +503,8 @@ module.exports = class CompileTab {
},
(error, content, cleanUrl, type, url) => {
if (!error) {
if (self._deps.filesProviders[type]) {
self._deps.filesProviders[type].addReadOnly(cleanUrl, content, url)
if (self._deps.fileProviders[type]) {
self._deps.fileProviders[type].addReadOnly(cleanUrl, content, url)
}
cb(null, content)
} else {

@ -92,7 +92,7 @@ module.exports = class SettingsTab {
self._view.gistToken = yo`
<div class="${css.info}">
<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}"><a target="_blank" href="https://github.com/settings/tokens">https://github.com/settings/tokens</a></div>
<div class="${css.crowNoFlex}">${self._view.gistToken}</div>

Loading…
Cancel
Save