mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75d753c53c | ||
|
|
677c53104a | ||
|
|
113e69fff2 | ||
|
|
0ede684acb | ||
|
|
f0dd1d0db8 | ||
|
|
59aaaa1c82 | ||
|
|
f990c4cd80 |
@@ -39,13 +39,10 @@
|
||||
[Core版](https://hellohao.cn):开源版的基础上增加`Backblaze(B2)` 并且可`同个对象存储商家`可开多个存储源(可添加至90+存储源)
|
||||
|
||||
|
||||
### 更新日志 `20240124`
|
||||
### 更新日志 `20240319`
|
||||
|
||||
- 新增支持对接WebDAV存储源
|
||||
- 修复本地存储源上传失败的情况
|
||||
- 修复某些存储源目录创建不正确的问题
|
||||
- 优化页面部分提示
|
||||
- 修复潜在的一些安全隐患
|
||||
- 修复部分部署场景部署不成功的问题
|
||||
- 提高系统稳定性
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.springframework.util.unit.DataSize;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.sql.DataSource;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
@@ -35,7 +35,6 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
|
||||
String serviceName = httpServletRequest.getServletPath();//获取接口
|
||||
String Users_Origin = httpServletRequest.getHeader("usersOrigin");
|
||||
String token = httpServletRequest.getHeader("Authorization");
|
||||
//验证前端域名
|
||||
if(httpServletRequest.getMethod().equals("POST") && !serviceName.contains("/api") && !serviceName.contains("/verifyCode")
|
||||
&& !serviceName.contains("/getClientVersion") && !serviceName.contains("/client")){
|
||||
try{
|
||||
@@ -75,7 +74,6 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
UsernamePasswordToken tokenOBJ = new UsernamePasswordToken(userData.getEmail(),userData.getPassword());
|
||||
tokenOBJ.setRememberMe(true);
|
||||
//执行登录方法,如果没有异常,说明登录成功
|
||||
subject.login(tokenOBJ);
|
||||
SecurityUtils.getSubject().getSession().setTimeout(3600000);
|
||||
User loginUser = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
@@ -102,7 +100,6 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
|
||||
subject.login(tokenOBJ);
|
||||
SecurityUtils.getSubject().getSession().setTimeout(3600000);//一小时
|
||||
} catch (Exception e) {
|
||||
// System.err.println("拦截器,登录失败,false");
|
||||
this.CODE = "403";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class IndexController {
|
||||
@Autowired private IRedisService iRedisService;
|
||||
@Autowired private AppClientService appClientService;
|
||||
@Autowired private WebDAVImageupload webDAVImageupload;
|
||||
public static String version = "20240124";
|
||||
public static String version = "20240319";
|
||||
@RequestMapping(value = "/")
|
||||
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
|
||||
model.addAttribute("name", "服务端程序(开源版)");
|
||||
|
||||
@@ -9,13 +9,9 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CodeMapper {
|
||||
//查询扩容码
|
||||
List<Code> selectCode(@Param("code") String code);
|
||||
Code selectCodekey(@Param("code") String code);
|
||||
//Integer selectCodekey(@Param("value") String value);
|
||||
//添加
|
||||
Integer addCode(Code code);
|
||||
//删除扩容码
|
||||
Integer deleteCode(@Param("code") String code);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,9 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface KeysMapper {
|
||||
//查询密钥
|
||||
Keys selectKeys(@Param("id") Integer id);
|
||||
List<Keys> getStorageName();
|
||||
List<Keys> getStorage();
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
List<Keys> getKeys();
|
||||
|
||||
|
||||
@@ -11,16 +11,12 @@ public class Msg implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5196249482551119279L;
|
||||
|
||||
//返回码
|
||||
private String code ="200";
|
||||
|
||||
//提示信息
|
||||
private String info="操作成功";
|
||||
|
||||
//返回数据
|
||||
private Object data;
|
||||
|
||||
//异常
|
||||
private String exceptions;
|
||||
|
||||
|
||||
|
||||
@@ -15,13 +15,17 @@ import com.qcloud.cos.model.PutObjectRequest;
|
||||
import com.qcloud.cos.model.PutObjectResult;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class COSImageupload {
|
||||
private static Logger logger = LoggerFactory.getLogger(COSImageupload.class);
|
||||
static COSClient cosClient;
|
||||
static Keys key;
|
||||
|
||||
@@ -29,16 +33,18 @@ public class COSImageupload {
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
File file = null;
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
stream = new FileInputStream(file);
|
||||
try {
|
||||
String bucketName = key.getBucketname();
|
||||
String userkey = username + "/" + ShortUIDName + "." + prefix;
|
||||
PutObjectRequest putObjectRequest =
|
||||
new PutObjectRequest(bucketName, userkey, file);
|
||||
new PutObjectRequest(bucketName, userkey, stream,null);
|
||||
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
|
||||
} catch (CosServiceException serverException) {
|
||||
returnImage.setCode("400");
|
||||
@@ -47,10 +53,12 @@ public class COSImageupload {
|
||||
returnImage.setCode("400");
|
||||
clientException.printStackTrace();
|
||||
}
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
logger.error("COS协议上传时发生异常:",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.util.*;
|
||||
* @date 2021/10/28 16:38
|
||||
*/
|
||||
@Service
|
||||
@EnableAsync
|
||||
public class ClientService {
|
||||
private static Logger logger = LoggerFactory.getLogger(ClientService.class);
|
||||
@Autowired private ConfdataService confdataService;
|
||||
@@ -41,7 +40,6 @@ public class ClientService {
|
||||
@Autowired private GetSource getSource;
|
||||
@Autowired private ImgViolationJudgeServiceImpl imgViolationJudgeService;
|
||||
|
||||
@Async("taskExecutor")
|
||||
public Msg uploadImg(
|
||||
HttpServletRequest request, MultipartFile multipartFile, String email, String pass,Integer setday) {
|
||||
Msg msg = new Msg();
|
||||
@@ -62,31 +60,70 @@ public class ClientService {
|
||||
}
|
||||
imageFileName = multipartFile.getOriginalFilename();
|
||||
File file = SetFiles.changeFile_new(multipartFile);
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
User u2 = new User();
|
||||
if (!file.exists() || email == null || pass == null) {
|
||||
msg.setCode("4005");
|
||||
msg.setInfo("必要参数不能为空");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
if (uploadConfig.getBlacklist() != null) {
|
||||
String[] iparr = uploadConfig.getBlacklist().split(";");
|
||||
for (String s : iparr) {
|
||||
if (s.equals(userip)) {
|
||||
msg.setCode("4010");
|
||||
msg.setInfo("你暂时不能上传");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
u2.setEmail(email);
|
||||
u2.setPassword(Base64.getEncoder().encodeToString(pass.getBytes()));
|
||||
User u = userMapper.getUsers(u2);
|
||||
if (null == u || u.getIsok() != 1) {
|
||||
msg.setCode("4006");
|
||||
msg.setInfo("用户信息不正确,账号异常");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
String imguid = UUID.randomUUID().toString().replace("-", "");
|
||||
Msg msg1 = updateImgCheck(u, uploadConfig);
|
||||
if (!msg1.getCode().equals("300")) {
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg1;
|
||||
}
|
||||
JSONObject updateJson = JSONObject.parseObject(msg1.getData().toString());
|
||||
final JSONObject groupJson = updateJson.getJSONObject("group");
|
||||
final Group group = groupJson.toJavaObject(Group.class);
|
||||
Long memory = updateJson.getLong("memory");
|
||||
Long UsedTotleMemory = updateJson.getLong("UsedTotleMemory");
|
||||
Long TotleMemory = updateJson.getLong("TotleMemory");
|
||||
String updatePath = updateJson.getString("updatePath");
|
||||
|
||||
sourceKeyId = group.getKeyid();
|
||||
Keys key = keysMapper.selectKeys(sourceKeyId);
|
||||
Long tmp = (memory == -1 ? -2 : UsedTotleMemory);
|
||||
if (tmp >= memory) {
|
||||
msg.setCode("4007");
|
||||
msg.setInfo(u == null ? "游客空间已用尽" : "您的可用空间不足");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
if (file.length() > TotleMemory) {
|
||||
@@ -94,43 +131,43 @@ public class ClientService {
|
||||
System.err.println("最大限制:" + TotleMemory);
|
||||
msg.setCode("4008");
|
||||
msg.setInfo("图像超出系统限制大小");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
md5key = DigestUtils.md5Hex(fis);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("未获取到图片的MD5,成成UUID");
|
||||
}finally{
|
||||
try {
|
||||
if (null != fis)
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
md5key = DigestUtils.md5Hex(stream);
|
||||
// FileInputStream fis = null;
|
||||
// try {
|
||||
// fis = new FileInputStream(file);
|
||||
// md5key = DigestUtils.md5Hex(fis);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("未获取到图片的MD5,成成UUID异常:",e);
|
||||
// }finally{
|
||||
// try {
|
||||
// if (null != fis)
|
||||
// fis.close();
|
||||
// } catch (Exception e) {
|
||||
// logger.error("ClientService-110异常",e);
|
||||
// }
|
||||
// }
|
||||
Msg fileMiME = TypeDict.FileMiME(stream);
|
||||
if (!fileMiME.getCode().equals("200")) {
|
||||
msg.setCode("4009");
|
||||
msg.setInfo(fileMiME.getInfo());
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
if (md5key == null || md5key.equals("")) {
|
||||
md5key = UUID.randomUUID().toString().replace("-", "");
|
||||
}
|
||||
String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
|
||||
if (uploadConfig.getBlacklist() != null) {
|
||||
String[] iparr = uploadConfig.getBlacklist().split(";");
|
||||
for (String s : iparr) {
|
||||
if (s.equals(userip)) {
|
||||
msg.setCode("4010");
|
||||
msg.setInfo("你暂时不能上传");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
|
||||
Images imgObj = new Images();
|
||||
String imgnameEd = null;
|
||||
Map<Map<String, String>, File> map = new HashMap<>();
|
||||
@@ -154,6 +191,7 @@ public class ClientService {
|
||||
}else{
|
||||
msg.setInfo("未获取到指定图像:110503");
|
||||
msg.setCode("110503");
|
||||
file.delete();
|
||||
return msg;
|
||||
}
|
||||
imgObj.setUpdatetime(df.format(new Date()));
|
||||
@@ -177,6 +215,7 @@ public class ClientService {
|
||||
imgObj.setIdname(imageFileName);
|
||||
Msg insertRet = imgServiceImpl.insertImgDataForCheck(imgObj,u,confdata,file.getName());
|
||||
if (insertRet.getCode().equals("000")) {
|
||||
file.delete();
|
||||
return insertRet;
|
||||
}
|
||||
long stime = System.currentTimeMillis();
|
||||
@@ -192,43 +231,48 @@ public class ClientService {
|
||||
imgServiceImpl.deleimgForImgUid(imgObj.getImguid());
|
||||
msg.setCode("5001");
|
||||
msg.setInfo("上传服务内部错误");
|
||||
file.delete();
|
||||
return msg;
|
||||
}
|
||||
file.delete();
|
||||
msg.setData(jsonObject);
|
||||
return msg;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
msg.setCode("5001");
|
||||
msg.setInfo("Error for server:500");
|
||||
logger.error("ClientService:Error for server-202行异常",e);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public static Group group;
|
||||
public static Long memory;
|
||||
public static Long TotleMemory;
|
||||
public static Long UsedTotleMemory;
|
||||
public static String updatePath = "tourist";
|
||||
// public static Group group;
|
||||
// public static Long memory;
|
||||
// public static Long TotleMemory;
|
||||
// public static Long UsedTotleMemory;
|
||||
// public static String updatePath = "tourist";
|
||||
|
||||
private Msg updateImgCheck(User user, UploadConfig uploadConfig) {
|
||||
Msg msg = new Msg();
|
||||
java.text.DateFormat dateFormat = null;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String updatePath = "tourist";
|
||||
try {
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
Group group = GetCurrentSource.GetSource(user == null ? null : user.getId());
|
||||
jsonObject.put("group",group);
|
||||
if (user == null) {
|
||||
if (uploadConfig.getIsupdate() != 1) {
|
||||
msg.setCode("1000");
|
||||
msg.setInfo("系统已禁用游客上传");
|
||||
return msg;
|
||||
}
|
||||
group = GetCurrentSource.GetSource(null);
|
||||
memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
|
||||
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
|
||||
UsedTotleMemory =
|
||||
Long memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
|
||||
Long TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
|
||||
Long UsedTotleMemory =
|
||||
imgServiceImpl.getusermemory(0) == null
|
||||
? 0L
|
||||
: imgServiceImpl.getusermemory(0); // 单位 B
|
||||
jsonObject.put("memory",memory);
|
||||
jsonObject.put("TotleMemory",TotleMemory);
|
||||
jsonObject.put("UsedTotleMemory",UsedTotleMemory);
|
||||
} else {
|
||||
// 判断用户能不能上传
|
||||
if (uploadConfig.getUserclose() != 1) {
|
||||
@@ -237,21 +281,24 @@ public class ClientService {
|
||||
return msg;
|
||||
}
|
||||
updatePath = user.getUsername();
|
||||
group = GetCurrentSource.GetSource(user.getId());
|
||||
memory = Long.valueOf(user.getMemory()); // 单位 B
|
||||
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
|
||||
UsedTotleMemory =
|
||||
Long memory = Long.valueOf(user.getMemory()); // 单位 B
|
||||
Long TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
|
||||
Long UsedTotleMemory =
|
||||
imgServiceImpl.getusermemory(user.getId()) == null
|
||||
? 0L
|
||||
: imgServiceImpl.getusermemory(user.getId()); // 单位 B
|
||||
jsonObject.put("memory",memory);
|
||||
jsonObject.put("TotleMemory",TotleMemory);
|
||||
jsonObject.put("UsedTotleMemory",UsedTotleMemory);
|
||||
}
|
||||
// 判断上传的图片目录结构类型
|
||||
if (uploadConfig.getUrltype() == 2) {
|
||||
updatePath = dateFormat.format(new Date());
|
||||
jsonObject.put("updatePath",updatePath);
|
||||
msg.setData(jsonObject);
|
||||
}
|
||||
msg.setCode("300");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("ClientService-异常",e);
|
||||
msg.setCode("500");
|
||||
}
|
||||
return msg;
|
||||
|
||||
@@ -7,15 +7,19 @@ import cn.hutool.extra.ftp.Ftp;
|
||||
import cn.hutool.extra.ftp.FtpMode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.net.ftp.FTP;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class FtpServiceImpl {
|
||||
private static Logger logger = LoggerFactory.getLogger(FtpServiceImpl.class);
|
||||
private Keys key;
|
||||
|
||||
public static int Initialize(Keys k) {
|
||||
@@ -66,22 +70,26 @@ public class FtpServiceImpl {
|
||||
return returnImage;
|
||||
}
|
||||
File file = null;
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
stream = new FileInputStream(file);
|
||||
boolean isUpload = ftp.upload(
|
||||
"/" + username,
|
||||
ShortUIDName + "." + prefix,
|
||||
file);
|
||||
stream);
|
||||
if (!isUpload) {
|
||||
returnImage.setCode("400");
|
||||
}
|
||||
try {if(stream!=null){stream.close();}} catch (Exception e) { }
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
logger.error("FTP发生异常:",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -14,13 +14,17 @@ import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.util.Auth;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class KODOImageupload {
|
||||
private static Logger logger = LoggerFactory.getLogger(KODOImageupload.class);
|
||||
static String upToken;
|
||||
static BucketManager bucketManager;
|
||||
static Keys key;
|
||||
@@ -33,15 +37,15 @@ public class KODOImageupload {
|
||||
Auth auth = Auth.create(key.getAccessKey(), key.getAccessSecret());
|
||||
String upToken = auth.uploadToken(key.getBucketname(), null, 7200, null);
|
||||
File file = null;
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
stream = new FileInputStream(file);
|
||||
try {
|
||||
Response response =
|
||||
uploadManager.put(
|
||||
file, username + "/" + ShortUIDName + "." + prefix, upToken);
|
||||
Response response = uploadManager.put(stream,username + "/" + ShortUIDName + "." + prefix, upToken, null, null);
|
||||
DefaultPutRet putRet =
|
||||
new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
|
||||
@@ -54,10 +58,12 @@ public class KODOImageupload {
|
||||
} catch (QiniuException ex2) {
|
||||
}
|
||||
}
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
logger.error("KODO发生异常:",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.netease.cloud.auth.Credentials;
|
||||
import com.netease.cloud.services.nos.NosClient;
|
||||
import com.netease.cloud.services.nos.model.ObjectListing;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -11,13 +11,17 @@ import com.aliyun.oss.model.ObjectListing;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class OSSImageupload {
|
||||
private static Logger logger = LoggerFactory.getLogger(OSSImageupload.class);
|
||||
static OSS ossClient;
|
||||
static Keys key;
|
||||
|
||||
@@ -25,6 +29,7 @@ public class OSSImageupload {
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
File file = null;
|
||||
FileInputStream stream = null;
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setHeader("Content-Disposition", "inline");
|
||||
try {
|
||||
@@ -32,19 +37,22 @@ public class OSSImageupload {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
stream = new FileInputStream(file);
|
||||
Msg fileMiME = TypeDict.FileMiME(stream);
|
||||
meta.setHeader("content-type", fileMiME.getData().toString());
|
||||
PutObjectRequest putObjectRequest =
|
||||
new PutObjectRequest(
|
||||
key.getBucketname(),
|
||||
username + "/" + ShortUIDName + "." + prefix,
|
||||
file,
|
||||
stream,
|
||||
meta);
|
||||
ossClient.putObject(putObjectRequest);
|
||||
try {if(stream!=null){stream.close();}} catch (Exception e) { }
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
logger.error("OSS上传发生异常:",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -12,16 +12,14 @@ import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.model.Bucket;
|
||||
import com.amazonaws.services.s3.model.DeleteObjectRequest;
|
||||
import com.amazonaws.services.s3.model.ObjectListing;
|
||||
import com.amazonaws.services.s3.model.PutObjectRequest;
|
||||
import com.amazonaws.services.s3.model.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -51,21 +49,28 @@ public class S3Imageupload {
|
||||
return returnImage;
|
||||
}
|
||||
File file = null;
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
stream = new FileInputStream(file);
|
||||
//解决存储源不能浏览图片的问题
|
||||
// ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
// objectMetadata.addUserMetadata();
|
||||
AS3.putObject(
|
||||
new PutObjectRequest(
|
||||
KEY.getBucketname(),
|
||||
username + "/" + ShortUIDName + "." + prefix,
|
||||
file));
|
||||
stream,null));
|
||||
// S3Object object = s3.getObject( new GetObjectRequest( key.getBucketname(),
|
||||
try {if(stream!=null){stream.close();}} catch (Exception e) { }
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
logger.error("S3协议上传发生异常:",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -8,14 +8,18 @@ import cn.hellohao.utils.TypeDict;
|
||||
import com.UpYun;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class USSImageupload {
|
||||
private static Logger logger = LoggerFactory.getLogger(USSImageupload.class);
|
||||
static UpYun upyun;
|
||||
static Keys key;
|
||||
|
||||
@@ -23,6 +27,7 @@ public class USSImageupload {
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
File file = null;
|
||||
FileInputStream stream = null;
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setHeader("Content-Disposition", "inline");
|
||||
try {
|
||||
@@ -30,21 +35,24 @@ public class USSImageupload {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
stream = new FileInputStream(file);
|
||||
Msg fileMiME = TypeDict.FileMiME(stream);
|
||||
meta.setHeader("content-type", fileMiME.getData().toString());
|
||||
upyun.setContentMD5(UpYun.md5(file));
|
||||
boolean result =
|
||||
upyun.writeFile(username + "/" + ShortUIDName + "." + prefix, file, true);
|
||||
upyun.writeFile(username + "/" + ShortUIDName + "." + prefix, stream, true, null);
|
||||
if (result) {
|
||||
|
||||
} else {
|
||||
System.err.println("上传失败");
|
||||
returnImage.setCode("400");
|
||||
}
|
||||
try {if(stream!=null){stream.close();}} catch (Exception e) { }
|
||||
}
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {if(stream!=null){stream.close();}} catch (Exception ex) { }
|
||||
logger.error("OSS上传发生异常:",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -25,7 +25,10 @@ import org.springframework.stereotype.Service;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -35,7 +38,6 @@ import java.util.concurrent.CompletableFuture;
|
||||
* @date 2020/1/9 15:46
|
||||
*/
|
||||
@Service
|
||||
@EnableAsync
|
||||
public class UploadServicel {
|
||||
private static Logger logger = LoggerFactory.getLogger(UploadServicel.class);
|
||||
@Autowired
|
||||
@@ -51,7 +53,6 @@ public class UploadServicel {
|
||||
@Autowired deleImages deleimages;
|
||||
@Autowired ImgViolationJudgeServiceImpl imgViolationJudgeService;
|
||||
|
||||
@Async("taskExecutor")
|
||||
public Msg uploadForLoc(
|
||||
HttpServletRequest request,
|
||||
File file,
|
||||
@@ -81,47 +82,23 @@ public class UploadServicel {
|
||||
return imgData;
|
||||
}
|
||||
}
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
String imguid = UUID.randomUUID().toString().replace("-", "");
|
||||
Msg msg1 = updateImgCheck(u, uploadConfig);
|
||||
if (!msg1.getCode().equals("300")) {
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg1;
|
||||
}
|
||||
sourceKeyId = group.getKeyid();
|
||||
Keys key = keysMapper.selectKeys(sourceKeyId);
|
||||
Long tmp = (memory == -1 ? -2 : UsedTotleMemory);
|
||||
if (tmp >= memory) {
|
||||
msg.setCode("4005");
|
||||
msg.setInfo(u == null ? "游客空间已用尽" : "您的可用空间不足");
|
||||
return msg;
|
||||
}
|
||||
if (file.length() > TotleMemory) {
|
||||
msg.setCode("4006");
|
||||
msg.setInfo("图像超出系统限制大小");
|
||||
return msg;
|
||||
}
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
if (!fileMiME.getCode().equals("200")) {
|
||||
msg.setCode("4000");
|
||||
msg.setInfo(fileMiME.getInfo());
|
||||
return msg;
|
||||
}
|
||||
if (md5key == null || md5key.equals("")) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
md5key = DigestUtils.md5Hex(fis);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取MD5错误",e);
|
||||
}finally{
|
||||
try {
|
||||
if (null != fis)
|
||||
fis.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
|
||||
JSONObject updateJson = JSONObject.parseObject(msg1.getData().toString());
|
||||
final JSONObject groupJson = updateJson.getJSONObject("group");
|
||||
final Group group = groupJson.toJavaObject(Group.class);
|
||||
Long memory = updateJson.getLong("memory");
|
||||
Long UsedTotleMemory = updateJson.getLong("UsedTotleMemory");
|
||||
Long TotleMemory = updateJson.getLong("TotleMemory");
|
||||
String updatePath = updateJson.getString("updatePath");
|
||||
if (uploadConfig.getBlacklist() != null) {
|
||||
String[] iparr = uploadConfig.getBlacklist().split(";");
|
||||
for (String s : iparr) {
|
||||
@@ -129,10 +106,66 @@ public class UploadServicel {
|
||||
file.delete();
|
||||
msg.setCode("4003");
|
||||
msg.setInfo("你暂时不能上传");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceKeyId = group.getKeyid();
|
||||
Keys key = keysMapper.selectKeys(sourceKeyId);
|
||||
Long tmp = (memory == -1 ? -2 : UsedTotleMemory);
|
||||
if (tmp >= memory) {
|
||||
msg.setCode("4005");
|
||||
msg.setInfo(u == null ? "游客空间已用尽" : "您的可用空间不足");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
if (file.length() > TotleMemory) {
|
||||
msg.setCode("4006");
|
||||
msg.setInfo("图像超出系统限制大小");
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
Msg fileMiME = TypeDict.FileMiME(stream);
|
||||
if (!fileMiME.getCode().equals("200")) {
|
||||
msg.setCode("4000");
|
||||
msg.setInfo(fileMiME.getInfo());
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
file.delete();
|
||||
} catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
if (md5key == null || md5key.equals("")) {
|
||||
md5key = DigestUtils.md5Hex(stream);
|
||||
// FileInputStream fis = null;
|
||||
// try {
|
||||
// fis = new FileInputStream(file);
|
||||
// md5key = DigestUtils.md5Hex(fis);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("获取MD5错误",e);
|
||||
// }finally{
|
||||
// try {
|
||||
// if (null != fis)
|
||||
// fis.close();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
|
||||
try {
|
||||
if(stream!=null){stream.close();}
|
||||
} catch (Exception e) { }
|
||||
// 判断路径格式 处理一下,去掉最前面的/
|
||||
String RootPath = key.getRootPath().replace(" ", "");
|
||||
if (!RootPath.equals("/")) {
|
||||
@@ -162,6 +195,7 @@ public class UploadServicel {
|
||||
}else{
|
||||
msg.setInfo("未获取到指定图像:110503");
|
||||
msg.setCode("110503");
|
||||
try { file.delete(); } catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
imgObj.setUpdatetime(df.format(new Date()));
|
||||
@@ -186,6 +220,7 @@ public class UploadServicel {
|
||||
// Integer insertRet = imgMapper.insertImgData(imgObj);
|
||||
Msg insertRet = imgServiceImpl.insertImgDataForCheck(imgObj,u,confdata,file.getName());
|
||||
if (insertRet.getCode().equals("000")) {
|
||||
try { file.delete(); } catch (Exception e) { }
|
||||
return insertRet;
|
||||
}
|
||||
|
||||
@@ -199,24 +234,21 @@ public class UploadServicel {
|
||||
jsonObject.put("name", imgObj.getImgname());
|
||||
jsonObject.put("imguid", imgObj.getImguid());
|
||||
imgViolationJudgeService.LegalImageCheck(imgObj,key);
|
||||
// new Thread(
|
||||
// () -> {
|
||||
// LegalImageCheck(imgObj);
|
||||
// })
|
||||
// .start();
|
||||
} else {
|
||||
imgServiceImpl.deleimgForImgUid(imgObj.getImguid());
|
||||
msg.setCode("5001");
|
||||
msg.setInfo("上传服务内部错误");
|
||||
try { file.delete(); } catch (Exception e) { }
|
||||
return msg;
|
||||
}
|
||||
file.delete();
|
||||
msg.setData(jsonObject);
|
||||
file.delete();
|
||||
return msg;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
msg.setInfo("上传时发生了一些错误");
|
||||
msg.setCode("110500");
|
||||
file.delete();
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -316,18 +348,20 @@ public class UploadServicel {
|
||||
return msg;
|
||||
}
|
||||
|
||||
private static Group group; // 上传用户或游客的所属分组
|
||||
private static Long memory; // 上传用户或者游客的分配容量 memory
|
||||
private static Long TotleMemory; // 用户或者游客下可使用的总容量 //maxsize
|
||||
private static Long UsedTotleMemory; // 用户或者游客已经用掉的总容量 //usermemory
|
||||
private static String updatePath = "tourist";
|
||||
// private static Group group; // 上传用户或游客的所属分组
|
||||
// private static Long memory; // 上传用户或者游客的分配容量 memory
|
||||
// private static Long TotleMemory; // 用户或者游客下可使用的总容量 //maxsize
|
||||
// private static Long UsedTotleMemory; // 用户或者游客已经用掉的总容量 //usermemory
|
||||
// private static String updatePath = "tourist";
|
||||
|
||||
// 判断用户 或 游客 当前上传图片的一系列校验
|
||||
private Msg updateImgCheck(User user, UploadConfig uploadConfig) {
|
||||
Msg msg = new Msg();
|
||||
java.text.DateFormat dateFormat = null;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String updatePath = "tourist";
|
||||
try {
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
Group group = GetCurrentSource.GetSource(user == null ? null : user.getId());
|
||||
jsonObject.put("group",group);
|
||||
if (user == null) {
|
||||
if (uploadConfig.getIsupdate() != 1) {
|
||||
msg.setCode("1000");
|
||||
@@ -335,13 +369,15 @@ public class UploadServicel {
|
||||
return msg;
|
||||
}
|
||||
updatePath = "tourist";
|
||||
group = GetCurrentSource.GetSource(null);
|
||||
memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
|
||||
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
|
||||
UsedTotleMemory =
|
||||
Long memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
|
||||
Long TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
|
||||
Long UsedTotleMemory =
|
||||
imgServiceImpl.getusermemory(0) == null
|
||||
? 0L
|
||||
: imgServiceImpl.getusermemory(0); // 单位 B
|
||||
jsonObject.put("memory",memory);
|
||||
jsonObject.put("TotleMemory",TotleMemory);
|
||||
jsonObject.put("UsedTotleMemory",UsedTotleMemory);
|
||||
} else {
|
||||
if (uploadConfig.getUserclose() != 1) {
|
||||
msg.setCode("1001");
|
||||
@@ -349,20 +385,26 @@ public class UploadServicel {
|
||||
return msg;
|
||||
}
|
||||
updatePath = user.getUsername();
|
||||
group = GetCurrentSource.GetSource(user.getId());
|
||||
memory = Long.valueOf(user.getMemory()); // 单位 B *1024*1024
|
||||
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
|
||||
UsedTotleMemory =
|
||||
Long memory = Long.valueOf(user.getMemory()); // 单位 B *1024*1024
|
||||
Long TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
|
||||
Long UsedTotleMemory =
|
||||
imgServiceImpl.getusermemory(user.getId()) == null
|
||||
? 0L
|
||||
: imgServiceImpl.getusermemory(user.getId()); // 单位 B
|
||||
jsonObject.put("memory",memory);
|
||||
jsonObject.put("TotleMemory",TotleMemory);
|
||||
jsonObject.put("UsedTotleMemory",UsedTotleMemory);
|
||||
}
|
||||
if (uploadConfig.getUrltype() == 2) {
|
||||
updatePath = dateFormat.format(new Date());
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
||||
updatePath = currentDate.format(formatter);
|
||||
}
|
||||
jsonObject.put("updatePath",updatePath);
|
||||
msg.setData(jsonObject);
|
||||
msg.setCode("300");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("updateImgCheck异常:",e);
|
||||
msg.setCode("500");
|
||||
}
|
||||
return msg;
|
||||
@@ -373,8 +415,6 @@ public class UploadServicel {
|
||||
public static String plusDay(int setday) {
|
||||
Date d = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String currdate = format.format(d);
|
||||
System.out.println("现在的日期是:" + currdate);
|
||||
Calendar ca = Calendar.getInstance();
|
||||
ca.setTime(d);
|
||||
ca.add(Calendar.DATE, setday); // num为增加的天数,可以改变的
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -66,9 +67,7 @@ public class WebDAVImageupload {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
createDirectories(httpClient, key.getEndpoint(), "/" + username);
|
||||
System.out.println("WebDAV地址:"+key.getEndpoint() + "/" + username + "/" + ShortUIDName + "." + prefix);
|
||||
HttpPut httpPut = new HttpPut(key.getEndpoint() + "/" + username + "/" + ShortUIDName + "." + prefix);
|
||||
FileEntity fileEntity = new FileEntity(file, ContentType.DEFAULT_BINARY);
|
||||
httpPut.setEntity(fileEntity);
|
||||
@@ -84,7 +83,7 @@ public class WebDAVImageupload {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("ImageuploadWebDAV:92异常",e);
|
||||
logger.error("ImageuploadWebDAV:87异常",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
|
||||
@@ -145,7 +145,6 @@ public class FirstRun implements InitializingBean {
|
||||
//检查表是否存在,后边加'imgdata' and column_name = 'explains' 检查字段是否存在
|
||||
private String isTableName = "SELECT count(table_name) FROM information_schema.TABLES WHERE TABLE_SCHEMA='tbed' and table_name =";
|
||||
private String judgeTable = "select count(*) from information_schema.columns where TABLE_SCHEMA='tbed' and table_name = ";
|
||||
//创建blacklist 2019-11-29
|
||||
private String sql0 =
|
||||
"alter table `keys` add (Region varchar(255) DEFAULT null,RootPath varchar(255) DEFAULT '/');";
|
||||
private String sql1 = "select count(*) from information_schema.columns where table_name = 'uploadconfig' and column_name = 'blacklist'";
|
||||
@@ -212,9 +211,9 @@ public class FirstRun implements InitializingBean {
|
||||
try {
|
||||
File f = new File(filePath);
|
||||
if (f.exists()) {
|
||||
System.out.print("文件存在");
|
||||
logger.info("文件存在");
|
||||
} else {
|
||||
System.out.print("文件不存在");
|
||||
logger.info("文件不存在,准备创建");
|
||||
// f.createNewFile();// 不存在则创建
|
||||
FileUtil.createTempFile(f);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ImgUrlUtil {
|
||||
httpUrlConnection.setConnectTimeout(300000);
|
||||
httpUrlConnection.setReadTimeout(300000);
|
||||
httpUrlConnection.connect();
|
||||
String code = new Integer(httpUrlConnection.getResponseCode()).toString();
|
||||
String code = Integer.toString(httpUrlConnection.getResponseCode());
|
||||
String message = httpUrlConnection.getResponseMessage();
|
||||
System.out.println("getResponseCode code ="+ code);
|
||||
System.out.println("getResponseMessage message ="+ message);
|
||||
@@ -75,7 +75,7 @@ public class ImgUrlUtil {
|
||||
throw new Exception("ResponseCode is not begin with 2,code="+code);
|
||||
}
|
||||
map.put("Check","true");
|
||||
System.out.println("连接正常");
|
||||
// System.out.println("连接正常");
|
||||
}catch(Exception ex){
|
||||
System.out.println(ex.getMessage());
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class ImgUrlUtil {
|
||||
|
||||
|
||||
public static Map<String ,Object> downLoadFromUrl(String urlStr,String referer,String fileName,String savePath){
|
||||
|
||||
FileInputStream fileInputStream = null;
|
||||
Map<String ,Object> resmap = new HashMap<>();
|
||||
Map<String ,String> map = checkURLStatusCode(urlStr);
|
||||
if(map.size()==0 || map.get("Check").equals("false")){
|
||||
@@ -120,7 +120,8 @@ public class ImgUrlUtil {
|
||||
}
|
||||
//下载并且保存成功后 判断格式 如果不是图像格式 就删除
|
||||
if(new File(saveDir+File.separator+fileName).exists()){
|
||||
Msg msg = TypeDict.FileMiME(file);
|
||||
fileInputStream = new FileInputStream(file);
|
||||
Msg msg = TypeDict.FileMiME(fileInputStream);
|
||||
if(msg.getCode().equals("200")){
|
||||
File f = new File(saveDir+File.separator+fileName);
|
||||
String imgPath = saveDir+File.separator+fileName+"."+(msg.getData().toString().replace("image/",""));
|
||||
@@ -137,9 +138,16 @@ public class ImgUrlUtil {
|
||||
resmap.put("res",false);
|
||||
resmap.put("StatusCode","500");
|
||||
}
|
||||
if(fileInputStream!=null){
|
||||
fileInputStream.close();
|
||||
}
|
||||
return resmap;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
try{
|
||||
if(fileInputStream!=null){
|
||||
fileInputStream.close();
|
||||
}
|
||||
}catch (Exception e2){ }
|
||||
resmap.put("res",false);
|
||||
resmap.put("StatusCode","500");
|
||||
return resmap;
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import cn.hellohao.service.impl.S3Imageupload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
|
||||
final class RunSqlScript {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RunSqlScript.class);
|
||||
public static String DBDRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
public static String DBURL ;
|
||||
//现在使用的是mysql数据库,是直接连接的,所以此处必须有用户名和密码
|
||||
@@ -21,7 +25,7 @@ final class RunSqlScript {
|
||||
try {
|
||||
Class.forName(DBDRIVER);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("RunSqlScript[29]", e);
|
||||
}
|
||||
//2、连接数据库
|
||||
//通过连接管理器连接数据库
|
||||
@@ -29,14 +33,14 @@ final class RunSqlScript {
|
||||
//在连接的时候直接输入用户名和密码才可以连接
|
||||
conn = DriverManager.getConnection(DBURL,USERNAME,PASSWORD);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("RunSqlScript[36]", e);
|
||||
}
|
||||
//3、向数据库中插入一条数据
|
||||
//String sql = "select count(*) from information_schema.columns where table_name = 'config' and column_name = 'id'";
|
||||
try {
|
||||
stmt = conn.createStatement();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("RunSqlScript[43]", e);
|
||||
}
|
||||
//4、执行语句
|
||||
try {
|
||||
@@ -46,7 +50,7 @@ final class RunSqlScript {
|
||||
count = resultSet.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("RunSqlScript[53]", e);
|
||||
return -1;
|
||||
}
|
||||
//5、关闭操作
|
||||
@@ -54,7 +58,7 @@ final class RunSqlScript {
|
||||
stmt.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("RunSqlScript[61]", e);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -71,8 +75,7 @@ final class RunSqlScript {
|
||||
try {
|
||||
Class.forName(DBDRIVER);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Print.Normal("SqlHelper.java - ClassNotFoundException");
|
||||
logger.error("RunSqlScript[78]", e);
|
||||
}
|
||||
//2、连接数据库
|
||||
//通过连接管理器连接数据库
|
||||
@@ -80,23 +83,21 @@ final class RunSqlScript {
|
||||
//在连接的时候直接输入用户名和密码才可以连接
|
||||
conn = DriverManager.getConnection(DBURL,USERNAME,PASSWORD);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Print.Normal("SqlHelper.java - SQLException1");
|
||||
logger.error("RunSqlScript[86]", e);
|
||||
}
|
||||
try {
|
||||
stmt = conn.createStatement();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Print.Normal("SqlHelper.java - SQLException2");
|
||||
logger.error("RunSqlScript[91]", e);
|
||||
}
|
||||
//4、执行语句
|
||||
try {
|
||||
count = stmt.executeUpdate(sql);
|
||||
} catch (SQLException e) {
|
||||
if(e.getMessage().contains("Duplicate key name") && e.getMessage().contains("index_md5key_url")){
|
||||
Print.Normal("Database index already exists, skip this step.");
|
||||
logger.info("Database index already exists, skip this step.");
|
||||
}else{
|
||||
e.printStackTrace();
|
||||
logger.error("RunSqlScript[100]", e);
|
||||
}
|
||||
}
|
||||
//5、关闭操作
|
||||
@@ -104,7 +105,7 @@ final class RunSqlScript {
|
||||
stmt.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
Print.Normal("SqlHelper.java - SQLException4");
|
||||
logger.error("RunSqlScript[108]", e);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package cn.hellohao.utils;
|
||||
|
||||
import cn.hellohao.pojo.Chunk;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
@@ -13,6 +16,7 @@ import java.text.DecimalFormat;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SetFiles {
|
||||
private static Logger logger = LoggerFactory.getLogger(SetFiles.class);
|
||||
// 转换文件方法
|
||||
public static File changeFile(MultipartFile multipartFile) {
|
||||
// 获取文件名
|
||||
@@ -47,17 +51,16 @@ public class SetFiles {
|
||||
|
||||
// 转换文件方法
|
||||
public static File changeFile_new(MultipartFile multipartFile) {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();//getOriginalFilename
|
||||
// 获取文件后缀
|
||||
String prefix = fileName.substring(fileName.lastIndexOf("."));
|
||||
// todo 修改临时文件文件名
|
||||
File file = null;
|
||||
try {
|
||||
file = File.createTempFile(fileName, prefix);
|
||||
multipartFile.transferTo(file);
|
||||
String new_FileName = System.getProperty("java.io.tmpdir")+"hellohao_tmp_upload"+File.separator+fileName;
|
||||
file = new File(new_FileName);
|
||||
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error("SetFiles.changeFile_new", e);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,16 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class TypeDict {
|
||||
|
||||
//apache大法
|
||||
public static Msg FileMiME(File file ){
|
||||
public static Msg FileMiME(InputStream stream){
|
||||
final Msg msg = new Msg();
|
||||
try {
|
||||
Tika tika = new Tika();
|
||||
String fileType = tika.detect(file);
|
||||
String fileType = tika.detect(stream);
|
||||
if (fileType != null && fileType.contains("/")) {
|
||||
if(fileType.contains("image/")){
|
||||
msg.setData(fileType);
|
||||
|
||||
@@ -4,7 +4,7 @@ server.port=10088
|
||||
#前端域名需要带协议头http(s)://
|
||||
CROS_ALLOWED_ORIGINS=${HELLOHAO_WEB_HOST:http://127.0.0.1:8080}
|
||||
#数据库账号
|
||||
spring.datasource.username=${MYSQL_NAME:root}
|
||||
spring.datasource.username=${MYSQL_USERNAME:root}
|
||||
#数据库密码test
|
||||
spring.datasource.password=${MYSQL_PASS:root}
|
||||
#数据库链接地址
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 查询当前用户:根据邮箱,根据id -->
|
||||
<select id="getUsers" parameterType="cn.hellohao.pojo.User" resultType="cn.hellohao.pojo.User">
|
||||
SELECT id,
|
||||
username,
|
||||
@@ -85,7 +84,7 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<!-- 查询当前用户:根据id -->
|
||||
|
||||
<select id="getUsersid" parameterType="integer" resultType="cn.hellohao.pojo.User">
|
||||
SELECT id,
|
||||
username,
|
||||
@@ -101,7 +100,7 @@
|
||||
FROM user
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
<!-- 查询当前用户:根据uid -->
|
||||
|
||||
<select id="getUsersMail" parameterType="string" resultType="cn.hellohao.pojo.User">
|
||||
SELECT id,
|
||||
username,
|
||||
@@ -118,13 +117,6 @@
|
||||
WHERE uid = #{uid}
|
||||
</select>
|
||||
|
||||
<!-- 插入图片信息 -->
|
||||
<!-- <insert id="insertimg" parameterType="cn.hellohao.pojo.Images">-->
|
||||
<!-- INSERT INTO imgdata (id, imgname, imgurl, userid, updatetime,sizes,abnormal,source,imgtype,md5key,imguid,format,about,violation)-->
|
||||
<!-- VALUES (NULL, #{imgname}, #{imgurl}, #{userid}, #{updatetime},#{sizes},#{abnormal},#{source},#{imgtype},#{md5key},#{imguid},#{format},#{about},null)-->
|
||||
<!-- </insert>-->
|
||||
|
||||
<!-- 修改资料 -->
|
||||
<update id="change" parameterType="cn.hellohao.pojo.User">
|
||||
UPDATE `user`
|
||||
<set>
|
||||
@@ -185,12 +177,10 @@
|
||||
SELECT count(username) FROM `user` where username=#{username}
|
||||
</select>
|
||||
|
||||
<!-- 查询用户总数 -->
|
||||
<select id="getUserTotal" resultType="integer">
|
||||
SELECT count(*) FROM `user`
|
||||
</select>
|
||||
|
||||
<!-- 获取用户的详细信息 -->
|
||||
<select id="getuserlist" resultType="cn.hellohao.pojo.User" parameterType="string">
|
||||
SELECT
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user