handler response type

pull/713/head
aniket-engg 4 years ago committed by Aniket
parent dfcd03c3f0
commit edef2892bd
  1. 19
      libs/remix-url-resolver/src/resolve.ts

@ -16,6 +16,11 @@ interface Handler {
handle(match: any): any; handle(match: any): any;
} }
interface HandlerResponse {
content: any;
cleanUrl: string
}
export class RemixURLResolver { export class RemixURLResolver {
private previouslyHandled: PreviouslyHandledImports private previouslyHandled: PreviouslyHandledImports
gistAccessToken: string gistAccessToken: string
@ -30,7 +35,7 @@ export class RemixURLResolver {
* @param root The root of the github import statement * @param root The root of the github import statement
* @param filePath path of the file in github * @param filePath path of the file in github
*/ */
async handleGithubCall(root: string, filePath: string) { async handleGithubCall(root: string, filePath: string): Promise<HandlerResponse> {
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\/([^/]+)\/(.*)/)
@ -56,7 +61,7 @@ export class RemixURLResolver {
* @param url The url of the import statement * @param url The url of the import statement
* @param cleanUrl * @param cleanUrl
*/ */
async handleHttp(url: string, cleanUrl: string) { async handleHttp(url: string, cleanUrl: string): Promise<HandlerResponse> {
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
try { try {
const response: AxiosResponse = await axios.get(url) const response: AxiosResponse = await axios.get(url)
@ -71,17 +76,17 @@ export class RemixURLResolver {
* @param url The url of the import statement * @param url The url of the import statement
* @param cleanUrl * @param cleanUrl
*/ */
async handleHttps(url: string, cleanUrl: string) { async handleHttps(url: string, cleanUrl: string): Promise<HandlerResponse> {
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
try { try {
const response: AxiosResponse = await axios.get(url) const response: AxiosResponse = await axios.get(url)
return { content: response.data, cleanUrl} return { content: response.data, cleanUrl }
} catch(e) { } catch(e) {
throw e throw e
} }
} }
handleSwarm(url: string, cleanURL: string) { handleSwarm(url: string, cleanUrl: string) {
return return
} }
@ -89,7 +94,7 @@ export class RemixURLResolver {
* Handle an import statement based on IPFS * Handle an import statement based on IPFS
* @param url The url of the IPFS import statement * @param url The url of the IPFS import statement
*/ */
async handleIPFS(url: string) { async handleIPFS(url: string): Promise<HandlerResponse> {
// replace ipfs:// with /ipfs/ // replace ipfs:// with /ipfs/
url = url.replace(/^ipfs:\/\/?/, 'ipfs/') url = url.replace(/^ipfs:\/\/?/, 'ipfs/')
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
@ -98,7 +103,7 @@ export class RemixURLResolver {
// If you don't find greeter.sol on ipfs gateway use local // If you don't find greeter.sol on ipfs gateway use local
// const req = 'http://localhost:8080/' + url // const req = 'http://localhost:8080/' + url
const response: AxiosResponse = await axios.get(req) const response: AxiosResponse = await axios.get(req)
return response.data return { content: response.data, cleanUrl: url }
} catch (e) { } catch (e) {
throw e throw e
} }

Loading…
Cancel
Save