This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Implement CustomIpfsHttpHandler for metadata retrieval
- Loading branch information
Philip Diaz
committed
Feb 17, 2021
1 parent
d06cf5c
commit f097583
Showing
3 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Handler, Tzip16Uri } from '@taquito/tzip16'; | ||
import { HttpBackend } from '@taquito/http-utils'; | ||
import { | ||
ContractAbstraction, | ||
ContractProvider, | ||
Wallet, | ||
Context | ||
} from '@taquito/taquito'; | ||
|
||
export default class CustomIpfsHttpHandler implements Handler { | ||
private _ipfsGateway: string; | ||
private _gatewayProtocol: string; | ||
private _httpBackend = new HttpBackend(); | ||
|
||
constructor(ipfsGatheway?: string, gatewayProtocol?: string) { | ||
this._ipfsGateway = ipfsGatheway ? ipfsGatheway : 'ipfs.io'; | ||
this._gatewayProtocol = gatewayProtocol ? gatewayProtocol : 'https'; | ||
} | ||
|
||
async getMetadata( | ||
_contractAbstraction: ContractAbstraction<ContractProvider | Wallet>, | ||
{ location }: Tzip16Uri, | ||
_context: Context | ||
): Promise<string> { | ||
return this._httpBackend.createRequest<string>({ | ||
url: `${this._gatewayProtocol}://${ | ||
this._ipfsGateway | ||
}/ipfs/${location.substring(2)}/`, | ||
method: 'GET', | ||
headers: { 'Content-Type': 'text/plain' }, | ||
mimeType: 'text; charset=utf-8', | ||
json: false | ||
}); | ||
} | ||
} |