raw github instead of github api

pull/706/head^2
aniket-engg 4 years ago committed by Aniket
parent 7363f0c311
commit 7fbd47de8f
  1. 7
      libs/remix-url-resolver/src/resolve.ts

@ -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
} }

Loading…
Cancel
Save