记得上下班打卡 | git大法好,push需谨慎

Commit d5fcc85c authored by anjiabin's avatar anjiabin

实现xuper图片类型上传特殊处理

parent 5693a044
package com.liquidnet.service.galaxy.biz;
import com.liquidnet.commons.lang.util.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
......@@ -94,4 +99,43 @@ public class GalaxyCommonBiz {
bos.close();
}
}
public static HashMap<String,Integer> getImageWidthAndHeight(String imgLocalFilePath){
HashMap rsHashMap = CollectionUtil.mapStringInteger();
// String imgLocalFilePath = "/Users/anjiabin/Downloads/zxl_image_test_001.jpg";
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(new FileInputStream(imgLocalFilePath));
} catch (IOException e) {
e.printStackTrace();
log.error("xuper getImageWidthAndHeight error:"+e.getMessage(),e);
}
int height = bufferedImage.getHeight();
int width = bufferedImage.getWidth();
rsHashMap.put("width",width);
rsHashMap.put("height",height);
log.info("getImageWidthAndHeight width=={} height=={}",width,height);
return rsHashMap;
}
public static boolean isImageType(String imageUrl){
// ”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”
String[] imageArray = {"jpg","jpeg","png","bmp","webp","hejc"};
String imageType = null;
if(imageUrl.lastIndexOf("?")!=-1){
String tempUrl = imageUrl.substring(0,imageUrl.lastIndexOf("?"));
imageType = tempUrl.substring(tempUrl.lastIndexOf(".")+1,tempUrl.length());
}else{
imageType = imageUrl.substring(imageUrl.lastIndexOf(".")+1,imageUrl.length());
}
System.out.println("imageType====="+imageType);
if(Arrays.asList(imageArray).contains(imageType.toLowerCase())){
return true;
}
return false;
}
}
......@@ -9,10 +9,7 @@ import com.liquidnet.common.third.xuper.constant.XuperEnum;
import com.liquidnet.common.third.xuper.dto.*;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.xuper.util.XuperSdkUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.biz.GalaxyCommonBiz;
import com.liquidnet.service.galaxy.biz.GalaxyEnumBiz;
......@@ -32,6 +29,7 @@ import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
......@@ -158,12 +156,26 @@ public class XuperArtworkBiz {
String nftUrl = reqDto.getNftUrl();
//该文件只为了生成hash值
String originalNftUrl = seriesNftUploadBo.getOriginalNftUrl();
String nftHashStr = this.getNftHashByNftUrl(originalNftUrl);
//设置nft的hash值
seriesNftUploadBo.setNftHashStr(nftHashStr);
String displlayUrl = reqDto.getDisplayUrl();
try {
//原始显示图片地址,该地址是为了获取图片宽高
String originalDisplayUrl = seriesNftUploadBo.getOriginalDisplayUrl();
HashMap<String,Integer> displayWidthAndHeight = CollectionUtil.mapStringInteger();
//判断类型是否为图片
boolean displayIsImageType = GalaxyCommonBiz.isImageType(originalDisplayUrl);
if(displayIsImageType){//如果是图片则获取原始宽高
File nftUrlFile= galaxyCommonBiz.inputStreamToFile(originalDisplayUrl,IDGenerator.getXuperNftImageCosCode());
displayWidthAndHeight = GalaxyCommonBiz.getImageWidthAndHeight(nftUrlFile.getAbsolutePath());
}else{
displayWidthAndHeight.put("width",290);
displayWidthAndHeight.put("height",290);
}
xuper002CreateAssetReqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
//资产碎片数量,小于1和大于200000代表不做库存限制
xuper002CreateAssetReqDto.setAmount(totalCount.intValue());
......@@ -174,13 +186,23 @@ public class XuperArtworkBiz {
//资产名称,小于30个字节
xuper002CreateAssetReqDto.setTitle(reqDto.getNftName());
//资产缩略图。bos上传的图片,格式支持:”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”。参数格式bos_v1://{bucket}/{object}/{width}_{height}
xuper002CreateAssetReqDto.setThumb(displlayUrl.concat("1000_500"));
xuper002CreateAssetReqDto.setThumb(displlayUrl.concat(displayWidthAndHeight.get("width").intValue()+"_"+displayWidthAndHeight.get("height").intValue()));
//短文字描述,小于300个字节
xuper002CreateAssetReqDto.setShortDesc(reqDto.getNftDesc());
//(可选)资产详情介绍长图。bos上传的图片,格式支持:”jpg”, “jpeg”, “png”, “bmp”, “webp”, “heic”。参数格式bos_v1://{bucket}/{object}/{width}_{height}
xuper002CreateAssetReqDto.setImgDesc(displlayUrl.concat("1000_500"));
xuper002CreateAssetReqDto.setImgDesc(displlayUrl.concat(displayWidthAndHeight.get("width").intValue()+"_"+displayWidthAndHeight.get("height").intValue()));
//资产原始文件。比如图片,图片本身就是资产。格式bos_v1://{bucket}/{object} ,文件大小<10M。文件名采用文件md5值,为了正常展现,需要正确携带文件后缀
xuper002CreateAssetReqDto.setAssetUrl(nftUrl.concat("900_1200"));
//判断类型是否为图片
boolean isImageType = GalaxyCommonBiz.isImageType(originalNftUrl);
if(isImageType){//如果是图片则获取原始宽高
File nftUrlFile= galaxyCommonBiz.inputStreamToFile(originalNftUrl,IDGenerator.getXuperNftImageCosCode());
HashMap<String,Integer> widthAndHeight = GalaxyCommonBiz.getImageWidthAndHeight(nftUrlFile.getAbsolutePath());
int width = widthAndHeight.get("width").intValue();
int height = widthAndHeight.get("height").intValue();
xuper002CreateAssetReqDto.setAssetUrl(nftUrl.concat(width+"_"+height));
}else{
xuper002CreateAssetReqDto.setAssetUrl(nftUrl);
}
//(可选)长文字描述,小于1200个字节
xuper002CreateAssetReqDto.setLongDesc(reqDto.getNftDesc());
//(可选)资产额外描述信息json字符串。比如标签
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment