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