mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
:art:优化响应头和返回值判断逻辑
This commit is contained in:
@@ -47,14 +47,16 @@ public class COSImageupload {
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
} catch (CosServiceException serverException) {
|
||||
returnImage.setCode("400");
|
||||
serverException.printStackTrace();
|
||||
} catch (CosClientException clientException) {
|
||||
returnImage.setCode("400");
|
||||
clientException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
returnImage.setCode("200");
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ClientService {
|
||||
e.printStackTrace();
|
||||
System.out.println("未获取到图片的MD5,成成UUID");
|
||||
}
|
||||
Msg fileMiME = TypeDict.FileMiME(file, uploadConfig.getSuffix());
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
if (!fileMiME.getCode().equals("200")) {
|
||||
//非图像文本
|
||||
msg.setCode("4009");
|
||||
|
||||
@@ -53,7 +53,6 @@ public class KODOImageupload {
|
||||
try {
|
||||
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
|
||||
file = entry.getValue();
|
||||
try {
|
||||
Response response = uploadManager.put(file,username + "/" + ShortUID + "." + entry.getKey(),upToken);
|
||||
@@ -63,6 +62,7 @@ public class KODOImageupload {
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
} catch (QiniuException ex) {
|
||||
returnImage.setCode("400");
|
||||
Response r = ex.response;
|
||||
System.err.println(r.toString());
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import cn.hellohao.utils.*;
|
||||
import com.aliyun.oss.OSS;
|
||||
@@ -27,6 +28,8 @@ public class OSSImageupload {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
meta.setHeader("content-type", fileMiME.getData().toString());
|
||||
System.out.println("待上传的图片:"+username + "/" + ShortUID + "." + entry.getKey());
|
||||
ossClient.putObject(key.getBucketname(), username + "/" + ShortUID + "." + entry.getKey(),file);
|
||||
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());//entry.getValue().getOriginalFilename()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import cn.hellohao.pojo.UploadConfig;
|
||||
import cn.hellohao.utils.*;
|
||||
@@ -26,6 +27,8 @@ public class UFileImageupload {
|
||||
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
meta.setHeader("content-type", fileMiME.getData().toString());
|
||||
uFile.setContentMD5(UpYun.md5(file));
|
||||
boolean result = uFile.writeFile(username + "/" + ShortUID + "." + entry.getKey(), file, true);
|
||||
if(result){
|
||||
@@ -34,6 +37,7 @@ public class UFileImageupload {
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
}else{
|
||||
returnImage.setCode("400");
|
||||
System.err.println("上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import cn.hellohao.pojo.UploadConfig;
|
||||
import cn.hellohao.utils.*;
|
||||
@@ -29,6 +30,8 @@ public class USSImageupload {
|
||||
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
meta.setHeader("content-type", fileMiME.getData().toString());
|
||||
upyun.setContentMD5(UpYun.md5(file));
|
||||
boolean result = upyun.writeFile(username + "/" + ShortUID + "." + entry.getKey(), file, true);
|
||||
if(result){
|
||||
@@ -37,6 +40,7 @@ public class USSImageupload {
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
}else{
|
||||
returnImage.setCode("400");
|
||||
System.err.println("上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class UploadServicel {
|
||||
e.printStackTrace();
|
||||
System.out.println("未获取到图片的MD5,成成UUID");
|
||||
}
|
||||
Msg fileMiME = TypeDict.FileMiME(file, uploadConfig.getSuffix());
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
if(!fileMiME.getCode().equals("200")) {
|
||||
//非图像文本
|
||||
msg.setCode("4000");
|
||||
|
||||
@@ -86,11 +86,11 @@ public class FirstRun implements InitializingBean {
|
||||
Print.Normal("Stage 7");
|
||||
}
|
||||
|
||||
Integer ret6 = RunSqlScript.RunSelectCount(judgeTable+"'imgandalbum' and column_name = 'notes' and TABLE_SCHEMA='picturebed'");
|
||||
if(ret6==0){
|
||||
RunSqlScript.RunInsert(sql11);
|
||||
Print.Normal("Stage 8");
|
||||
}
|
||||
// Integer ret6 = RunSqlScript.RunSelectCount(judgeTable+"'imgandalbum' and column_name = 'notes' and TABLE_SCHEMA='picturebed'");
|
||||
// if(ret6==0){
|
||||
// RunSqlScript.RunInsert(sql11);
|
||||
// Print.Normal("Stage 8");
|
||||
// }
|
||||
|
||||
RunSqlScript.RunInsert(sql10);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class FirstRun implements InitializingBean {
|
||||
private String sql10 = "alter table config modify column `explain` varchar(1000),modify column links varchar(1000),modify column notice varchar(1000),modify column baidu varchar(1000)";
|
||||
|
||||
//添加imgandalbum字段notes(添加画廊图片说明)
|
||||
private String sql11 = "alter table imgandalbum add notes varchar(1000) DEFAULT ' '";
|
||||
// private String sql11 = "alter table imgandalbum add notes varchar(1000) DEFAULT ' '";
|
||||
|
||||
private String inddx_md5key = "ALTER TABLE imgdata ADD INDEX index_md5key_url ( md5key,imgurl)";
|
||||
// create index yarn_app_result_i4 on yarn_app_result (flow_exec_id(100), another_column(50));
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
import cn.hellohao.service.impl.ImgreviewServiceImpl;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
@@ -27,9 +25,6 @@ public class GetIPS implements Runnable {
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
/*** * 用于测试跨域 * @author huangweii * 2015年5月29日 */
|
||||
|
||||
public static String getIpAddr(HttpServletRequest request){
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if(org.apache.commons.lang3.StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ImgUrlUtil {
|
||||
//下载并且保存成功后 判断格式 如果不是图像格式 就删除
|
||||
//
|
||||
if(new File(saveDir+File.separator+fileName).exists()){
|
||||
Msg msg = TypeDict.FileMiME(file,null);
|
||||
Msg msg = TypeDict.FileMiME(file);
|
||||
if(msg.getCode().equals("200")){
|
||||
File f = new File(saveDir+File.separator+fileName);
|
||||
String imgPath = saveDir+File.separator+fileName+"."+(msg.getData().toString().replace("image/",""));
|
||||
|
||||
@@ -69,7 +69,7 @@ MIDI (mid),文件头:4D546864
|
||||
}
|
||||
|
||||
//apache大法
|
||||
public static Msg FileMiME(File file, String suffix){
|
||||
public static Msg FileMiME(File file ){
|
||||
final Msg msg = new Msg();
|
||||
try {
|
||||
Tika tika = new Tika();
|
||||
|
||||
Reference in New Issue
Block a user