Skip to content

Commit f6ee732

Browse files
RC 1.3.0 - IPFS Setting (#12)
1 parent 24bc3c9 commit f6ee732

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

UniversalNFT.dev.API/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Reflection;
22
using AspNetCoreRateLimit;
3+
using Microsoft.Extensions.Options;
34
using UniversalNFT.dev.API.Facades;
45
using UniversalNFT.dev.API.Middleware;
56
using UniversalNFT.dev.API.Services.AppSettings;
@@ -9,6 +10,7 @@
910
using UniversalNFT.dev.API.Services.Providers;
1011
using UniversalNFT.dev.API.Services.Rules;
1112
using UniversalNFT.dev.API.Services.XRPL;
13+
using UniversalNFT.dev.API.Services.IPFS;
1214
using UniversalNFT.dev.API.SwaggerConfig;
1315

1416
var builder = WebApplication.CreateBuilder(args);
@@ -29,6 +31,7 @@
2931
// DI
3032
builder.Services.Configure<XRPLSettings>(builder.Configuration.GetSection("XRPLSettings"));
3133
builder.Services.Configure<ServerSettings>(builder.Configuration.GetSection("ServerSettings"));
34+
builder.Services.Configure<IPFSSettings>(builder.Configuration.GetSection("IPFSSettings"));
3235
builder.Services.AddSingleton<IHttpFacade, HttpFacade>();
3336
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
3437
builder.Services.AddSingleton<IXRPLService, XRPLService>();
@@ -52,6 +55,10 @@
5255

5356
var app = builder.Build();
5457

58+
// Initialize static services
59+
var ipfsSettings = app.Services.GetRequiredService<IOptions<IPFSSettings>>().Value;
60+
IPFSService.Initialize(ipfsSettings);
61+
5562
app.UseIpRateLimiting();
5663

5764
app.UseSwagger();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace UniversalNFT.dev.API.Services.AppSettings;
2+
3+
public class IPFSSettings
4+
{
5+
public string IPFSServerAddress { get; set; } = "https://ipfs.io/";
6+
}
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
using System.Text.RegularExpressions;
2-
3-
namespace UniversalNFT.dev.API.Services.IPFS;
4-
5-
public static class IPFSService
1+
using System.Text.RegularExpressions;
2+
using UniversalNFT.dev.API.Services.AppSettings;
3+
4+
namespace UniversalNFT.dev.API.Services.IPFS;
5+
6+
public static class IPFSService
67
{
8+
private static string _ipfsServerAddress = "https://ipfs.io/";
9+
10+
public static void Initialize(IPFSSettings settings)
11+
{
12+
_ipfsServerAddress = settings.IPFSServerAddress;
13+
}
14+
715
public static string NormaliseUrl(string url)
816
{
917
// Is it well formed
1018
if (url.StartsWith("http"))
1119
return url;
1220

1321
// Add ipfs to the start if it doesn't have it
14-
if (!url.StartsWith("ipfs://"))
22+
if (!url.StartsWith("ipfs://"))
1523
url = "ipfs://" + url;
1624

1725
// Add /ipfs if it doesn't have it
18-
if (url.IndexOf("/ipfs/") == -1)
19-
{
20-
url = url.Replace("ipfs://", "ipfs://ipfs/");
21-
}
22-
23-
// TODO: Ideally we could set the ipfs server the backend uses in appsettings
24-
url = url.Replace("ipfs://", "https://ipfs.io/");
25-
26-
return url;
27-
}
28-
26+
if (url.IndexOf("/ipfs/") == -1)
27+
{
28+
url = url.Replace("ipfs://", "ipfs://ipfs/");
29+
}
30+
31+
url = url.Replace("ipfs://", _ipfsServerAddress);
32+
33+
return url;
34+
}
35+
2936
public static int CountIpfsUrls(string input)
3037
{
3138
string pattern = @"ipfs://";
3239
return Regex.Matches(input, pattern)?.Count ?? 0;
33-
}
34-
}
40+
}
41+
}

UniversalNFT.dev.API/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"ServerSettings": {
1414
"ServerExternalDomain": "https://api.universalnft.dev" // Where the service can be accessed e.g. https://api.universalnft.dev
1515
},
16+
"IPFSSettings": {
17+
"IPFSServerAddress": "https://gateway.pinata.cloud/" // IPFS gateway URL
18+
},
1619
"CacheFolderWatcher": {
1720
"MaxFolderSizeInBytes": 1073741824, // Example for 1GB
1821
"PollingIntervalInMinutes": 15

0 commit comments

Comments
 (0)