|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.nineth.service;
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
|
|
|
|
+import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.izouma.nineth.domain.*;
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.NFT;
|
|
import com.izouma.nineth.dto.NFT;
|
|
|
import com.izouma.nineth.dto.NFTAccount;
|
|
import com.izouma.nineth.dto.NFTAccount;
|
|
@@ -13,6 +14,10 @@ import com.izouma.nineth.repo.AssetRepo;
|
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
|
|
+import io.ipfs.api.IPFS;
|
|
|
|
|
+import io.ipfs.api.MerkleNode;
|
|
|
|
|
+import io.ipfs.api.NamedStreamable;
|
|
|
|
|
+import io.ipfs.multihash.Multihash;
|
|
|
import lombok.AllArgsConstructor;
|
|
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;
|
|
@@ -21,6 +26,7 @@ import org.springframework.data.domain.Page;
|
|
|
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.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -70,6 +76,7 @@ public class AssetService {
|
|
|
.gasUsed(nft.getGasUsed())
|
|
.gasUsed(nft.getGasUsed())
|
|
|
.price(order.getPrice())
|
|
.price(order.getPrice())
|
|
|
.status(AssetStatus.NORMAL)
|
|
.status(AssetStatus.NORMAL)
|
|
|
|
|
+ .ipfsUrl(ipfsUpload(order.getPic().get(0)))
|
|
|
.build();
|
|
.build();
|
|
|
assetRepo.save(asset);
|
|
assetRepo.save(asset);
|
|
|
applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
|
|
applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
|
|
@@ -113,6 +120,7 @@ public class AssetService {
|
|
|
.gasUsed(nft.getGasUsed())
|
|
.gasUsed(nft.getGasUsed())
|
|
|
.price(order.getPrice())
|
|
.price(order.getPrice())
|
|
|
.status(AssetStatus.NORMAL)
|
|
.status(AssetStatus.NORMAL)
|
|
|
|
|
+ .ipfsUrl(ipfsUpload(winItem.getPics().get(0)))
|
|
|
.build();
|
|
.build();
|
|
|
assetRepo.save(asset);
|
|
assetRepo.save(asset);
|
|
|
applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
|
|
applicationContext.publishEvent(new CreateAssetEvent(this, true, order, asset));
|
|
@@ -124,6 +132,22 @@ public class AssetService {
|
|
|
applicationContext.publishEvent(new CreateAssetEvent(this, false, order, null));
|
|
applicationContext.publishEvent(new CreateAssetEvent(this, false, order, null));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public String ipfsUpload(String url) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ IPFS ipfs = new IPFS("121.40.132.44", 5001);
|
|
|
|
|
+ HttpRequest request = HttpRequest.get(url);
|
|
|
|
|
+ File file = File.createTempFile("ipfs", ".tmp");
|
|
|
|
|
+ request.receive(file);
|
|
|
|
|
+ NamedStreamable.FileWrapper file1 = new NamedStreamable.FileWrapper(file);
|
|
|
|
|
+ MerkleNode put = ipfs.add(file1).get(0);
|
|
|
|
|
+ Multihash multihash = ipfs.pin.add(put.hash).get(0);
|
|
|
|
|
+ log.info("上传ipfs成功 {}", multihash.toBase58());
|
|
|
|
|
+ return multihash.toBase58();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void publicShow(Long id) {
|
|
public void publicShow(Long id) {
|
|
|
Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
if (asset.isPublicShow()) {
|
|
if (asset.isPublicShow()) {
|