Remove Infura IPFS usage because Infura closed public IPFS gateway

This commit is contained in:
Ivan Yaremenchuk 2022-08-14 21:29:59 -05:00
parent 6564e9ec9d
commit dae28fc04c
8 changed files with 22 additions and 22 deletions

View File

@ -4,7 +4,7 @@ using RestEase;
namespace NftFaucet.ApiClients;
[BaseAddress("https://pin.crustcode.com")]
public interface ICrustApiClient
public interface ICrustPinApiClient
{
[Header("Authorization")]
public string Auth { get; set; }

View File

@ -0,0 +1,14 @@
using NftFaucet.ApiClients.Models;
using RestEase;
namespace NftFaucet.ApiClients;
[BaseAddress("https://gw.crustapps.net")]
public interface ICrustUploadApiClient
{
[Header("Authorization")]
public string Auth { get; set; }
[Post("api/v0/add")]
Task<UploadResponse> UploadFile([Body] MultipartContent content, [Query("pin")] bool pin = true);
}

View File

@ -1,11 +0,0 @@
using NftFaucet.ApiClients.Models;
using RestEase;
namespace NftFaucet.ApiClients;
[BaseAddress("https://ipfs.infura.io:5001")]
public interface IInfuraIpfsApiClient
{
[Post("api/v0/add")]
Task<UploadResponse> UploadFile([Body] MultipartContent content, [Query("stream-channels")] bool streamChannels = true);
}

View File

@ -4,7 +4,6 @@ public enum IpfsGatewayType : byte
{
None = 0,
IpfsOfficial = 1,
Infura = 2,
NftStorage = 3,
Crust = 4,
}

View File

@ -6,7 +6,7 @@ public class StateStorage
{
public string TokenName { get; set; }
public string TokenDescription { get; set; }
public IpfsGatewayType IpfsGatewayType { get; set; } = IpfsGatewayType.Infura;
public IpfsGatewayType IpfsGatewayType { get; set; } = IpfsGatewayType.Crust;
public TokenType TokenType { get; set; } = TokenType.ERC721;
public double TokenAmount { get; set; } = 1;
public Uri LocalImageUrl { get; set; }

View File

@ -86,7 +86,7 @@
</SpaceItem>
<SpaceItem>
<Select DataSource="@IpfsGateways"
DefaultValue="@(nameof(IpfsGatewayType.Infura))"
DefaultValue="@(nameof(IpfsGatewayType.Crust))"
ValueName="@nameof(EnumWrapper<IpfsGatewayType>.ValueString)"
LabelName="@nameof(EnumWrapper<IpfsGatewayType>.Description)"
OnSelectedItemChanged="OnIpfsGatewayChange">

View File

@ -49,11 +49,13 @@ public class IpfsService : IIpfsService
public async Task<Uri> Upload(string fileName, string fileType, byte[] fileBytes)
{
var fileUploadRequest = ToMultipartContent(fileName, fileType, fileBytes);
var uploadClient = RestClient.For<IInfuraIpfsApiClient>();
var uploadClient = RestClient.For<ICrustUploadApiClient>();
var authHeader = GenerateAuthHeader();
uploadClient.Auth = authHeader;
var response = await uploadClient.UploadFile(fileUploadRequest);
var pinningClient = RestClient.For<ICrustApiClient>();
pinningClient.Auth = GenerateAuthHeader();
var pinningClient = RestClient.For<ICrustPinApiClient>();
pinningClient.Auth = authHeader;
var pinRequest = new PinRequest
{
cid = response.Hash,

View File

@ -61,10 +61,6 @@
"Id": "IpfsOfficial",
"BaseUrl": "https://ipfs.io/ipfs"
},
{
"Id": "Infura",
"BaseUrl": "https://ipfs.infura.io/ipfs"
},
{
"Id": "NftStorage",
"BaseUrl": "https://nftstorage.link/ipfs"