|
@@ -17,10 +17,12 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -30,6 +32,7 @@ public class AssetMintService {
|
|
|
private UserRepo userRepo;
|
|
private UserRepo userRepo;
|
|
|
private NFTService nftService;
|
|
private NFTService nftService;
|
|
|
private ApplicationContext applicationContext;
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
+ private Environment env;
|
|
|
|
|
|
|
|
@Async
|
|
@Async
|
|
|
public void mint(Long assetId) {
|
|
public void mint(Long assetId) {
|
|
@@ -92,7 +95,15 @@ public class AssetMintService {
|
|
|
|
|
|
|
|
public String ipfsUpload(String url) {
|
|
public String ipfsUpload(String url) {
|
|
|
try {
|
|
try {
|
|
|
- IPFS ipfs = new IPFS("112.74.34.84", 5001);
|
|
|
|
|
|
|
+ url = url.replace("raex-meta.oss-cn-shenzhen.aliyuncs.com",
|
|
|
|
|
+ "raex-meta.oss-cn-shenzhen-internal.aliyuncs.com")
|
|
|
|
|
+ .replace("cdn.raex.vip",
|
|
|
|
|
+ "raex-meta.oss-cn-shenzhen-internal.aliyuncs.com");
|
|
|
|
|
+ String host = "112.74.34.84";
|
|
|
|
|
+ if (Arrays.asList(env.getActiveProfiles()).contains("prod")) {
|
|
|
|
|
+ host = "172.31.167.5";
|
|
|
|
|
+ }
|
|
|
|
|
+ IPFS ipfs = new IPFS(host, 5001);
|
|
|
HttpRequest request = HttpRequest.get(url);
|
|
HttpRequest request = HttpRequest.get(url);
|
|
|
File file = File.createTempFile("ipfs", ".tmp");
|
|
File file = File.createTempFile("ipfs", ".tmp");
|
|
|
request.receive(file);
|
|
request.receive(file);
|
|
@@ -100,6 +111,7 @@ public class AssetMintService {
|
|
|
MerkleNode put = ipfs.add(file1).get(0);
|
|
MerkleNode put = ipfs.add(file1).get(0);
|
|
|
Multihash multihash = ipfs.pin.add(put.hash).get(0);
|
|
Multihash multihash = ipfs.pin.add(put.hash).get(0);
|
|
|
log.info("上传ipfs成功 {}", multihash.toBase58());
|
|
log.info("上传ipfs成功 {}", multihash.toBase58());
|
|
|
|
|
+ file.delete();
|
|
|
return multihash.toBase58();
|
|
return multihash.toBase58();
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
}
|
|
}
|