From b9ae2b42a6d7a65b70bc05756c0dff60ed94d53d Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 7 Jan 2019 16:41:33 +0100 Subject: [PATCH] use access token while resolving github content --- src/app/compiler/compiler-imports.js | 6 ++++-- src/app/tabs/compile-tab.js | 7 +++---- src/app/tabs/settings-tab.js | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index adb09338eb..386a3c2957 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.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) => { diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index f5b9aa5365..15730c2a75 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -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 { diff --git a/src/app/tabs/settings-tab.js b/src/app/tabs/settings-tab.js index b8f38ed79c..2b8297df26 100644 --- a/src/app/tabs/settings-tab.js +++ b/src/app/tabs/settings-tab.js @@ -92,7 +92,7 @@ module.exports = class SettingsTab { self._view.gistToken = yo`
Gist Access Token
-
Manage the access token used to publish to Gist.
+
Manage the access token used to publish to Gist and retrieve Github contents.
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.
${self._view.gistToken}