Commit 7fbd47de authored by aniket-engg's avatar aniket-engg Committed by Aniket

raw github instead of github api

parent 7363f0c3
...@@ -42,18 +42,19 @@ export class RemixURLResolver { ...@@ -42,18 +42,19 @@ export class RemixURLResolver {
let param = '?' let param = '?'
param += this.gistAccessToken ? 'access_token=' + this.gistAccessToken : '' param += this.gistAccessToken ? 'access_token=' + this.gistAccessToken : ''
const regex = filePath.match(/blob\/([^/]+)\/(.*)/) const regex = filePath.match(/blob\/([^/]+)\/(.*)/)
let reference = 'master'
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] reference = regex[1]
param += '&ref=' + reference param += '&ref=' + reference
filePath = filePath.replace(`blob/${reference}/`, '') filePath = filePath.replace(`blob/${reference}/`, '')
} }
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
try { try {
const req: string = 'https://api.github.com/repos/' + root + '/contents/' + filePath + param const req: string = `https://raw.githubusercontent.com/${root}/${reference}/${filePath}`
const response: AxiosResponse = await axios.get(req) const response: AxiosResponse = await axios.get(req)
return { content: Buffer.from(response.data.content, 'base64').toString(), cleanUrl: root + '/' + filePath } return { content: response.data, cleanUrl: root + '/' + filePath }
} catch(e) { } catch(e) {
throw e throw e
} }
......
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