From 91db6ec1a6ffe1a81ae9f5c0ba01f03bd5029a0c 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 ac90e771e8..13e4caac77 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -46,9 +46,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, @@ -511,8 +510,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 02a7a92e71..54eb760d20 100644 --- a/src/app/tabs/settings-tab.js +++ b/src/app/tabs/settings-tab.js @@ -100,7 +100,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}