xiongzhu před 4 roky
rodič
revize
196b8ee3ba

+ 13 - 1
src/main/java/com/izouma/nineth/service/AssetMintService.java

@@ -17,10 +17,12 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.util.Arrays;
 
 @Service
 @Slf4j
@@ -30,6 +32,7 @@ public class AssetMintService {
     private UserRepo           userRepo;
     private NFTService         nftService;
     private ApplicationContext applicationContext;
+    private Environment        env;
 
     @Async
     public void mint(Long assetId) {
@@ -92,7 +95,15 @@ public class AssetMintService {
 
     public String ipfsUpload(String url) {
         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);
             File file = File.createTempFile("ipfs", ".tmp");
             request.receive(file);
@@ -100,6 +111,7 @@ public class AssetMintService {
             MerkleNode put = ipfs.add(file1).get(0);
             Multihash multihash = ipfs.pin.add(put.hash).get(0);
             log.info("上传ipfs成功 {}", multihash.toBase58());
+            file.delete();
             return multihash.toBase58();
         } catch (Exception e) {
         }