mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
369b88ffb3 | ||
|
|
bfa41ac049 | ||
|
|
ca0da1dd06 | ||
|
|
44814e79b0 | ||
|
|
f02d865389 | ||
|
|
48b0e1c5ca | ||
|
|
a04bbc1ea6 | ||
|
|
31b4426c10 | ||
|
|
766c125673 | ||
|
|
0de7e0e0fc | ||
|
|
f24a2d5557 | ||
|
|
87394258ad | ||
|
|
89a66a17b3 | ||
|
|
3e4c90c8d9 |
@@ -1,12 +1,23 @@
|
||||
# Hellohao图像托管程序 - 也许这会是最优秀的图床程序
|
||||
|
||||

|
||||
# Hellohao图像托管 - 也许这会是最优秀的图像托管程序
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.hellohao.cn/" target="_blank">
|
||||
<img width="1920px" src="https://upload.cc/i1/2022/02/11/HSg5tX.png">
|
||||
</a>
|
||||
</p>
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
<h3 align="center">赞助商</h3>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.eltyun.com/" target="_blank">
|
||||
<img width="350px" src="https://t.tdo.ink/hellohao/s9ugmihq.png">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
>:exclamation: 托管的所有开源代码可能存在作者修改/测试/调整等行为,均为实验性代码,故并不保证程序或功能的可用性,如果你想要部署程序,请下载我们提供的编译整合包进行安装部署。
|
||||
|
||||
|
||||
@@ -27,21 +38,15 @@
|
||||
|
||||
[Core版](https://hellohao.cn):开源版的基础上增加`Backblaze(B2)` 并且可`同个对象存储商家`可开多个存储源(可添加至90+存储源)
|
||||
|
||||
|
||||
### 更新日志 `20240102`
|
||||
|
||||
- 重构:相册页面UI显示效果
|
||||
- 新增:相册页支持拖拽移动目录并支持了目录相互移动
|
||||
- 新增:删除功能新增了强制删除选项
|
||||
- 优化:大图片上传逻辑判断及展示效果
|
||||
- 调整:用户个人信息失效时间,提高用户体验
|
||||
- 调整:去除前端浏览器控制台输出Slogan
|
||||
- 优化:七牛云存储源兼容了新地区的对接
|
||||
- 优化:用户体验操作或提示
|
||||
- 优化:系统处理图片的逻辑
|
||||
### 更新日志 `20240124`
|
||||
|
||||
- 新增支持对接WebDAV存储源
|
||||
- 修复本地存储源上传失败的情况
|
||||
- 修复某些存储源目录创建不正确的问题
|
||||
- 优化页面部分提示
|
||||
- 修复潜在的一些安全隐患
|
||||
|
||||
[^_^]: 程序宣传视频:[自制宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/)
|
||||
|
||||
|
||||
### 主要功能
|
||||
@@ -149,6 +154,8 @@
|
||||
|
||||
更多部署教程参考程序[相关文档](http://doc.hellohao.cn)
|
||||
|
||||
更强大的功能可[购买Core版](http://tbed.hellohao.cn/pay)程序
|
||||
|
||||
|
||||
### 启动项目
|
||||
> 访问你的前端域名即可
|
||||
@@ -170,12 +177,6 @@
|
||||
|
||||

|
||||
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
|
||||
### 桌面客户端(win/mac)
|
||||
> 获取地址:[官网获取](https://www.hellohao.cn/app)
|
||||
|
||||
@@ -190,7 +191,7 @@
|
||||
|
||||

|
||||
|
||||
[//]: # ()
|
||||
[//]: # ""
|
||||
|
||||
|
||||
### 运行环境
|
||||
@@ -237,4 +238,3 @@ Hellohao图像托管已申请[**中国国家版权局计算机软件著作权**]
|
||||
**如需程序定制或其他业务,请与我们取得联系**
|
||||
[Hellohao图像托管官网](http://hellohao.cn)
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +130,17 @@
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- webdav-->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.lookfirst</groupId>
|
||||
<artifactId>sardine</artifactId>
|
||||
<version>5.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baidu.aip</groupId>
|
||||
<artifactId>java-sdk</artifactId>
|
||||
@@ -238,7 +248,7 @@
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class ShiroConfig {
|
||||
filterMap.put("/verifyCodeForRetrieve","anon");
|
||||
filterMap.put("/verifyCodeFortowSendEmail","anon");
|
||||
filterMap.put("/api/**","anon");
|
||||
filterMap.put("/w/**","anon");
|
||||
filterMap.put("/user/**","anon");
|
||||
filterMap.put("/ota/**","anon");
|
||||
filterMap.put("/admin/root/**","roles[admin]");
|
||||
|
||||
@@ -16,9 +16,9 @@ public class PoolConfig {
|
||||
@Bean(name = "taskExecutor")
|
||||
public ThreadPoolTaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(properties.getCorePoolSize());
|
||||
executor.setMaxPoolSize(properties.getMaxPoolSize());
|
||||
executor.setQueueCapacity(properties.getQueueCapacity());
|
||||
executor.setCorePoolSize(properties.getCorePoolSize()); //设置核心线程数
|
||||
executor.setMaxPoolSize(properties.getMaxPoolSize()); //设置最大线程数
|
||||
executor.setQueueCapacity(properties.getQueueCapacity()); //设置队列容量
|
||||
executor.setThreadNamePrefix(properties.getThreadNamePrefix());
|
||||
executor.setKeepAliveSeconds(properties.getKeepAliveTime());
|
||||
executor.setWaitForTasksToCompleteOnShutdown(properties.isWaitForTasksToCompleteOnShutdown());
|
||||
@@ -42,7 +42,7 @@ public class PoolConfig {
|
||||
private int corePoolSize = 5;
|
||||
private int maxPoolSize = 50;
|
||||
private int keepAliveTime = 15;
|
||||
private int queueCapacity = 6;
|
||||
private int queueCapacity = 10;
|
||||
private String threadNamePrefix = "Tbed-Thread";
|
||||
private boolean allowCoreThreadTimeout = false;
|
||||
private boolean waitForTasksToCompleteOnShutdown = false;
|
||||
|
||||
@@ -7,7 +7,6 @@ import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.AlbumServiceImpl;
|
||||
import cn.hellohao.service.impl.UserServiceImpl;
|
||||
import cn.hellohao.service.impl.deleImages;
|
||||
import cn.hellohao.utils.Base64Encryption;
|
||||
import cn.hellohao.utils.SetFiles;
|
||||
import cn.hellohao.utils.SetText;
|
||||
import cn.hellohao.utils.progress.MyProgress;
|
||||
@@ -28,10 +27,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Hellohao
|
||||
@@ -444,10 +440,11 @@ public class AdminController {
|
||||
user.setEmail(email);
|
||||
}
|
||||
}
|
||||
user.setPassword(Base64Encryption.encryptBASE64(password.getBytes()));
|
||||
|
||||
user.setPassword(Base64.getEncoder().encodeToString(password.getBytes()));
|
||||
user.setUid(u.getUid());
|
||||
} else {
|
||||
user.setPassword(Base64Encryption.encryptBASE64(password.getBytes()));
|
||||
user.setPassword(Base64.getEncoder().encodeToString(password.getBytes()));
|
||||
user.setUid(u.getUid());
|
||||
}
|
||||
userService.change(user);
|
||||
|
||||
@@ -47,6 +47,22 @@ public class AdminRootController {
|
||||
private ImgreviewService imgreviewService;
|
||||
@Autowired
|
||||
private AppClientService appClientService;
|
||||
@Autowired
|
||||
private NOSImageupload nOSImageupload;
|
||||
@Autowired
|
||||
private OSSImageupload ossImageupload;
|
||||
@Autowired
|
||||
private USSImageupload ussImageupload;
|
||||
@Autowired
|
||||
private KODOImageupload kodoImageupload;
|
||||
@Autowired
|
||||
private COSImageupload cosImageupload;
|
||||
@Autowired
|
||||
private FtpServiceImpl ftpService;
|
||||
@Autowired
|
||||
private S3Imageupload s3Imageupload;
|
||||
@Autowired
|
||||
private WebDAVImageupload webDAVImageupload;
|
||||
|
||||
|
||||
@PostMapping(value = "/getUserList")
|
||||
@@ -189,19 +205,21 @@ public class AdminRootController {
|
||||
Keys key = keysService.selectKeys(keyId);
|
||||
Integer ret = 0;
|
||||
if (key.getStorageType() == 1) {
|
||||
ret = NOSImageupload.Initialize(key);
|
||||
ret = nOSImageupload.Initialize(key);
|
||||
} else if (key.getStorageType() == 2) {
|
||||
ret = OSSImageupload.Initialize(key);
|
||||
ret = ossImageupload.Initialize(key);
|
||||
} else if (key.getStorageType() == 3) {
|
||||
ret = USSImageupload.Initialize(key);
|
||||
ret = ussImageupload.Initialize(key);
|
||||
} else if (key.getStorageType() == 4) {
|
||||
ret = KODOImageupload.Initialize(key);
|
||||
ret = kodoImageupload.Initialize(key);
|
||||
} else if (key.getStorageType() == 6) {
|
||||
ret = COSImageupload.Initialize(key);
|
||||
ret = cosImageupload.Initialize(key);
|
||||
} else if (key.getStorageType() == 7) {
|
||||
ret = FtpServiceImpl.Initialize(key);
|
||||
ret = ftpService.Initialize(key);
|
||||
} else if (key.getStorageType() == 8) {
|
||||
ret = S3Imageupload.Initialize(key);
|
||||
ret = s3Imageupload.Initialize(key);
|
||||
}else if (key.getStorageType() == 9) {
|
||||
ret = webDAVImageupload.Initialize(key);
|
||||
}
|
||||
Long l = imgService.getsourcememory(keyId);
|
||||
jsonObject.put("isok", ret);
|
||||
@@ -224,23 +242,6 @@ public class AdminRootController {
|
||||
@ResponseBody
|
||||
public Msg updateStorage(@RequestParam(value = "data", defaultValue = "") String data) {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
// Integer id = jsonObj.getInteger("id");
|
||||
// String AccessKey = jsonObj.getString("AccessKey");
|
||||
// String AccessSecret = jsonObj.getString("AccessSecret");
|
||||
// String Endpoint = jsonObj.getString("Endpoint");
|
||||
// String Bucketname = jsonObj.getString("Bucketname");
|
||||
// String RequestAddress = jsonObj.getString("RequestAddress");
|
||||
// Integer storageType = jsonObj.getInteger("storageType");
|
||||
// String keyname = jsonObj.getString("keyname");
|
||||
// Keys keys = new Keys();
|
||||
// keys.setId(id);
|
||||
// keys.setAccessKey(AccessKey);
|
||||
// keys.setAccessSecret(AccessSecret);
|
||||
// keys.setEndpoint(Endpoint);
|
||||
// keys.setBucketname(Bucketname);
|
||||
// keys.setRequestAddress(RequestAddress);
|
||||
// keys.setStorageType(storageType);
|
||||
// keys.setKeyname(keyname);
|
||||
Keys keys = JSON.toJavaObject(jsonObj,Keys.class);
|
||||
Msg msg = keysService.updateKey(keys);
|
||||
return msg;
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hellohao.config.GlobalConstant;
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.UploadServicel;
|
||||
import cn.hellohao.service.impl.WebDAVImageupload;
|
||||
import cn.hellohao.service.impl.deleImages;
|
||||
import cn.hellohao.utils.GetIPS;
|
||||
import cn.hellohao.utils.MyVersion;
|
||||
@@ -19,6 +20,8 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -43,8 +46,8 @@ public class IndexController {
|
||||
@Autowired private deleImages deleimages;
|
||||
@Autowired private IRedisService iRedisService;
|
||||
@Autowired private AppClientService appClientService;
|
||||
|
||||
public static String version = "20240102";
|
||||
@Autowired private WebDAVImageupload webDAVImageupload;
|
||||
public static String version = "20240124";
|
||||
@RequestMapping(value = "/")
|
||||
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
|
||||
model.addAttribute("name", "服务端程序(开源版)");
|
||||
@@ -191,6 +194,14 @@ public class IndexController {
|
||||
return retMsg;
|
||||
}
|
||||
|
||||
//webdav本地托管
|
||||
@GetMapping("/w/{shortuuid}")
|
||||
public ResponseEntity<InputStreamResource> getNextcloudImage(HttpServletRequest request, @PathVariable("shortuuid") String shortuuid) {
|
||||
ResponseEntity<InputStreamResource> webDAV = webDAVImageupload.getWebDAV(shortuuid);
|
||||
return webDAV;
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getUploadInfo")
|
||||
@ResponseBody
|
||||
public Msg getUploadInfo() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hellohao.auth.token.JWTUtil;
|
||||
import cn.hellohao.config.SysName;
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.utils.Base64Encryption;
|
||||
import cn.hellohao.utils.NewSendEmail;
|
||||
import cn.hellohao.utils.Print;
|
||||
import cn.hellohao.utils.SetText;
|
||||
@@ -27,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class UserController {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
String username = jsonObj.getString("username");
|
||||
String email = jsonObj.getString("email");
|
||||
String password = Base64Encryption.encryptBASE64(jsonObj.getString("password").getBytes());
|
||||
String password = Base64.getEncoder().encodeToString(jsonObj.getString("password").getBytes());
|
||||
String verifyCodeForRegister = jsonObj.getString("verifyCode");
|
||||
Object redis_verifyCodeForRegister = iRedisService.getValue("verifyCodeForRegister_"+httpServletRequest.getHeader("verifyCodeForRegister"));
|
||||
if(!SetText.checkEmail(email)){
|
||||
@@ -203,7 +203,7 @@ public class UserController {
|
||||
Msg msg = new Msg();
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
String email = jsonObj.getString("email");
|
||||
String password = Base64Encryption.encryptBASE64(jsonObj.getString("password").getBytes());
|
||||
String password = Base64.getEncoder().encodeToString(jsonObj.getString("password").getBytes());
|
||||
String verifyCode = jsonObj.getString("verifyCode");
|
||||
if(null == email || null == password || null == verifyCode){
|
||||
msg.setCode("5000");
|
||||
@@ -385,7 +385,7 @@ public class UserController {
|
||||
User user = userService.getUsers(u2);
|
||||
user.setIsok(1);
|
||||
String new_pass = HexUtil.decodeHexStr(cip);//解密密码
|
||||
user.setPassword(Base64Encryption.encryptBASE64(new_pass.getBytes()));
|
||||
user.setPassword(Base64.getEncoder().encodeToString(new_pass.getBytes()));
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
user.setUid(uid);
|
||||
if (user != null) {
|
||||
|
||||
@@ -22,6 +22,10 @@ public interface ImgMapper {
|
||||
|
||||
Images selectByPrimaryKey(@Param("id") Long id);
|
||||
|
||||
Images selectImgByBrieflink(@Param("brieflink") String brieflink);
|
||||
|
||||
Images selectImgByShortlink(@Param("shortlink") String shortlink);
|
||||
|
||||
Integer counts(@Param("userid") Integer userid);
|
||||
|
||||
Integer setImg(Images images);
|
||||
|
||||
@@ -39,6 +39,8 @@ public class Images {
|
||||
private String idname;
|
||||
private Integer isRepeat;//如果没有开启查重的时候他是0,开启为1
|
||||
private String searchname;
|
||||
private String brieflink;
|
||||
private String shortlink;
|
||||
private String order;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,5 +14,9 @@ public class Keys {
|
||||
private Integer storageType;
|
||||
private String keyname;
|
||||
private String RootPath;//存入的目录
|
||||
private Boolean SysTransmit;
|
||||
|
||||
public Boolean getSysTransmit() {
|
||||
return SysTransmit==null?false:SysTransmit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ public class FirstJob {
|
||||
@Autowired
|
||||
private S3Imageupload s3Imageupload;
|
||||
@Autowired
|
||||
private WebDAVImageupload webDAVImageupload;
|
||||
@Autowired
|
||||
private FtpServiceImpl ftpService;
|
||||
@Autowired
|
||||
ImgTempService imgTempService;
|
||||
@@ -78,6 +80,8 @@ public class FirstJob {
|
||||
firstJob.ftpService.delFTP(keys.getId(), images);
|
||||
}else if(keys.getStorageType()==8){
|
||||
firstJob.s3Imageupload.deleS3(keys.getId(), images);
|
||||
}else if(keys.getStorageType()==9){
|
||||
firstJob.webDAVImageupload.delWebDAV(keys.getId(), images);
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.hellohao.service;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,6 +22,10 @@ public interface ImgService {
|
||||
|
||||
Images selectByPrimaryKey(Long id);
|
||||
|
||||
Images selectImgByBrieflink(String brieflink);
|
||||
|
||||
Images selectImgByShortlink(String shortlink);
|
||||
|
||||
Integer counts(Integer userid);
|
||||
|
||||
Integer setImg(Images images);
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -26,12 +28,11 @@ import java.util.*;
|
||||
* @date 2021/10/28 16:38
|
||||
*/
|
||||
@Service
|
||||
@EnableAsync
|
||||
public class ClientService {
|
||||
private static Logger logger = LoggerFactory.getLogger(ClientService.class);
|
||||
@Autowired
|
||||
ConfdataService confdataService;
|
||||
@Autowired
|
||||
SysConfigService sysConfigService;
|
||||
@Autowired private ConfdataService confdataService;
|
||||
@Autowired private SysConfigService sysConfigService;
|
||||
@Autowired private UserMapper userMapper;
|
||||
@Autowired private KeysMapper keysMapper;
|
||||
@Autowired private UploadConfigMapper uploadConfigMapper;
|
||||
@@ -40,6 +41,7 @@ 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();
|
||||
@@ -67,7 +69,7 @@ public class ClientService {
|
||||
return msg;
|
||||
}
|
||||
u2.setEmail(email);
|
||||
u2.setPassword(Base64Encryption.encryptBASE64(pass.getBytes()));
|
||||
u2.setPassword(Base64.getEncoder().encodeToString(pass.getBytes()));
|
||||
User u = userMapper.getUsers(u2);
|
||||
if (null == u || u.getIsok() != 1) {
|
||||
msg.setCode("4006");
|
||||
@@ -132,17 +134,20 @@ public class ClientService {
|
||||
Images imgObj = new Images();
|
||||
String imgnameEd = null;
|
||||
Map<Map<String, String>, File> map = new HashMap<>();
|
||||
String shortUuid_y = SetText.getShortUuid();
|
||||
String shortUuid_s = SetText.getShortUuid();
|
||||
if (file.exists()) {
|
||||
Map<String, String> m1 = new HashMap<>();
|
||||
String shortUuid_y = SetText.getShortUuid();
|
||||
m1.put("prefix", prefix);
|
||||
m1.put("name", shortUuid_y);
|
||||
map.put(m1, file);
|
||||
imgnameEd = updatePath + "/" + shortUuid_y + "." + prefix;
|
||||
imgObj.setImgname(imgnameEd);
|
||||
if (key.getStorageType().equals(5)) {
|
||||
imgObj.setImgurl(key.getRequestAddress() + "/ota/" + imgnameEd);
|
||||
} else {
|
||||
imgObj.setImgurl(confdata.getString("domain") + "/ota/" + imgnameEd);
|
||||
} else if(key.getStorageType().equals(9) && key.getSysTransmit()){
|
||||
imgObj.setImgurl(confdata.getString("domain") + "/w/" + shortUuid_y);
|
||||
}else {
|
||||
imgObj.setImgurl(key.getRequestAddress() + "/" + imgnameEd);
|
||||
}
|
||||
imgObj.setSizes(Long.toString(file.length()));
|
||||
@@ -167,6 +172,8 @@ public class ClientService {
|
||||
imgObj.setMd5key(md5key);
|
||||
imgObj.setImguid(imguid);
|
||||
imgObj.setFormat(fileMiME.getData().toString());
|
||||
imgObj.setShortlink(shortUuid_y);
|
||||
imgObj.setBrieflink(shortUuid_s);
|
||||
imgObj.setIdname(imageFileName);
|
||||
Msg insertRet = imgServiceImpl.insertImgDataForCheck(imgObj,u,confdata,file.getName());
|
||||
if (insertRet.getCode().equals("000")) {
|
||||
|
||||
@@ -46,6 +46,16 @@ public class ImgServiceImpl implements ImgService {
|
||||
return imgMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Images selectImgByBrieflink(String brieflink) {
|
||||
return imgMapper.selectImgByBrieflink(brieflink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Images selectImgByShortlink(String shortlink) {
|
||||
return imgMapper.selectImgByShortlink(shortlink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer counts(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -131,10 +141,9 @@ public class ImgServiceImpl implements ImgService {
|
||||
if(sysConfig.getCheckduplicate().equals("1")){
|
||||
//查重
|
||||
Images img = new Images();
|
||||
img.setUserid(user.getId());
|
||||
img.setUserid(user==null?0:user.getId());
|
||||
img.setMd5key(images.getMd5key());
|
||||
List<Images> list = imgMapper.selectImgUrlByMD5(img);
|
||||
jsonObject.put("url", list.get(0).getImgurl());
|
||||
if (list.size() > 0) {
|
||||
jsonObject.put("url", list.get(0).getImgurl());
|
||||
jsonObject.put("name", flilename);
|
||||
|
||||
@@ -58,6 +58,8 @@ public class InitializationStorage implements CommandLineRunner {
|
||||
FtpServiceImpl.Initialize(key);
|
||||
}else if(key.getStorageType()==8){
|
||||
S3Imageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==9){
|
||||
WebDAVImageupload.Initialize(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.utils.Print;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -30,6 +31,8 @@ public class KeysServiceImpl implements KeysService {
|
||||
private FtpServiceImpl ftpService;
|
||||
@Autowired
|
||||
private S3Imageupload s3Imageupload;
|
||||
@Autowired
|
||||
private WebDAVImageupload webDAVImageupload;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -51,6 +54,29 @@ public class KeysServiceImpl implements KeysService {
|
||||
public Msg updateKey(Keys key) {
|
||||
Msg msg = new Msg();
|
||||
Integer ret = -2;
|
||||
//修正一边数据格式,去除末尾的斜杠
|
||||
if(key.getStorageType()==9 || key.getStorageType()==8){
|
||||
//s3或者webdav
|
||||
if(!StringUtils.isBlank(key.getRootPath()) && !key.getRootPath().equals("/")){
|
||||
if (key.getRootPath().endsWith("/")) {
|
||||
String rootpath = key.getRootPath();
|
||||
key.setRootPath(rootpath.substring(0, rootpath.length() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isBlank(key.getEndpoint())){
|
||||
final String endpoint = key.getEndpoint();
|
||||
if (endpoint.endsWith("/")) {
|
||||
key.setEndpoint(endpoint.substring(0, endpoint.length() - 1));
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isBlank(key.getRequestAddress())){
|
||||
final String requestAddress = key.getRequestAddress();
|
||||
if (requestAddress.endsWith("/")) {
|
||||
key.setRequestAddress(requestAddress.substring(0, requestAddress.length() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
if(key.getStorageType()==1){
|
||||
ret =nOSImageupload.Initialize(key);
|
||||
}else if (key.getStorageType()==2){
|
||||
@@ -67,6 +93,8 @@ public class KeysServiceImpl implements KeysService {
|
||||
ret = ftpService.Initialize(key);
|
||||
}else if(key.getStorageType()==8){
|
||||
ret = s3Imageupload.Initialize(key);
|
||||
}else if(key.getStorageType()==9){
|
||||
ret = webDAVImageupload.Initialize(key);
|
||||
}else{
|
||||
Print.Normal("为获取到存储参数,或者使用存储源是本地的。");
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import cn.hellohao.utils.SetText;
|
||||
import cn.hellohao.utils.TypeDict;
|
||||
import com.UpYun;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class UFileImageupload1 {
|
||||
static UpYun uFile;
|
||||
static Keys key;
|
||||
|
||||
/*
|
||||
* 废弃方法待补位
|
||||
* */
|
||||
|
||||
public ReturnImage ImageuploadUFile(
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
File file = null;
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setHeader("Content-Disposition", "inline");
|
||||
try {
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
file = entry.getValue();
|
||||
Msg fileMiME = TypeDict.FileMiME(file);
|
||||
meta.setHeader("content-type", fileMiME.getData().toString());
|
||||
uFile.setContentMD5(UpYun.md5(file));
|
||||
boolean result =
|
||||
uFile.writeFile(
|
||||
username + "/" + ShortUID + "." + entry.getKey(), file, true);
|
||||
if (result) {
|
||||
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());
|
||||
returnImage.setImgurl(
|
||||
key.getRequestAddress()
|
||||
+ "/"
|
||||
+ username
|
||||
+ "/"
|
||||
+ ShortUID
|
||||
+ "."
|
||||
+ entry.getKey());
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
} else {
|
||||
returnImage.setCode("400");
|
||||
System.err.println("上传失败");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
returnImage.setCode("500");
|
||||
return returnImage;
|
||||
}
|
||||
|
||||
public static Integer Initialize(Keys k) {
|
||||
int ret = -1;
|
||||
if (k.getAccessSecret() != null
|
||||
&& k.getAccessKey() != null
|
||||
&& k.getBucketname() != null
|
||||
&& k.getRequestAddress() != null) {
|
||||
if (!k.getAccessSecret().equals("")
|
||||
&& !k.getAccessKey().equals("")
|
||||
&& !k.getBucketname().equals("")
|
||||
&& !k.getRequestAddress().equals("")) {
|
||||
UpYun ufObj = new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
|
||||
List<UpYun.FolderItem> items = null;
|
||||
try {
|
||||
items = ufObj.readDir("/", null);
|
||||
ret = 1;
|
||||
uFile = ufObj;
|
||||
key = k;
|
||||
} catch (Exception e) {
|
||||
System.out.println("UFile Object Is null");
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Boolean delUFile(Integer keyID, Images images) {
|
||||
boolean b = true;
|
||||
try {
|
||||
boolean result = uFile.deleteFile(images.getImgname(), null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
b = false;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -33,6 +35,7 @@ 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
|
||||
@@ -48,6 +51,7 @@ public class UploadServicel {
|
||||
@Autowired deleImages deleimages;
|
||||
@Autowired ImgViolationJudgeServiceImpl imgViolationJudgeService;
|
||||
|
||||
@Async("taskExecutor")
|
||||
public Msg uploadForLoc(
|
||||
HttpServletRequest request,
|
||||
File file,
|
||||
@@ -129,21 +133,29 @@ public class UploadServicel {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断路径格式 处理一下,去掉最前面的/
|
||||
String RootPath = key.getRootPath().replace(" ", "");
|
||||
if (!RootPath.equals("/")) {
|
||||
updatePath = RootPath.substring(1) + "/" + updatePath;
|
||||
}
|
||||
// 先存数据库
|
||||
Images imgObj = new Images();
|
||||
String imgnameEd = null;
|
||||
Map<Map<String, String>, File> map = new HashMap<>();
|
||||
String shortUuid_y = SetText.getShortUuid();
|
||||
String shortUuid_s = SetText.getShortUuid();
|
||||
if (file.exists()) {
|
||||
Map<String, String> m1 = new HashMap<>();
|
||||
String shortUuid_y = SetText.getShortUuid();
|
||||
m1.put("prefix", prefix);
|
||||
m1.put("name", shortUuid_y);
|
||||
map.put(m1, file);
|
||||
imgnameEd = updatePath + "/" + shortUuid_y + "." + prefix;
|
||||
imgObj.setImgname(imgnameEd);
|
||||
if (key.getStorageType().equals(5)) {
|
||||
imgObj.setImgurl(key.getRequestAddress() + "/ota/" + imgnameEd);
|
||||
} else {
|
||||
imgObj.setImgurl(confdata.getString("domain") + "/ota/" + imgnameEd);
|
||||
} else if(key.getStorageType().equals(9) && key.getSysTransmit()){
|
||||
imgObj.setImgurl(confdata.getString("domain") + "/w/" + shortUuid_y);
|
||||
}else {
|
||||
imgObj.setImgurl(key.getRequestAddress() + "/" + imgnameEd);
|
||||
}
|
||||
imgObj.setSizes(Long.toString(file.length()));
|
||||
@@ -168,6 +180,8 @@ public class UploadServicel {
|
||||
imgObj.setMd5key(md5key);
|
||||
imgObj.setImguid(imguid);
|
||||
imgObj.setFormat(fileMiME.getData().toString());
|
||||
imgObj.setShortlink(shortUuid_y);
|
||||
imgObj.setBrieflink(shortUuid_s);
|
||||
imgObj.setIdname(imgName);
|
||||
// Integer insertRet = imgMapper.insertImgData(imgObj);
|
||||
Msg insertRet = imgServiceImpl.insertImgDataForCheck(imgObj,u,confdata,file.getName());
|
||||
@@ -176,6 +190,7 @@ public class UploadServicel {
|
||||
}
|
||||
|
||||
long stime = System.currentTimeMillis();
|
||||
System.out.println("上传前地址:"+updatePath);
|
||||
ReturnImage returnImage = getSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
|
||||
if (returnImage.getCode().equals("200")) {
|
||||
long etime = System.currentTimeMillis();
|
||||
@@ -215,7 +230,6 @@ public class UploadServicel {
|
||||
String md5 = jsonObj.getString("md5");
|
||||
String classifications = jsonObj.getString("classifications");
|
||||
Integer day = jsonObj.getInteger("day");
|
||||
String source = jsonObj.getString("source");
|
||||
String imgIdentifier = jsonObj.getString("imgIdentifier");
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
classifications = classifications==null?"":classifications;
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.config.GlobalConstant;
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import cn.hellohao.service.ImgService;
|
||||
import cn.hellohao.service.KeysService;
|
||||
import cn.hellohao.utils.TypeDict;
|
||||
import com.github.sardine.impl.methods.HttpMkCol;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class WebDAVImageupload {
|
||||
|
||||
static CloseableHttpClient httpClient;
|
||||
static Keys key;
|
||||
|
||||
@Autowired
|
||||
private ImgService imgService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
private static Logger logger = LoggerFactory.getLogger(WebDAVImageupload.class);
|
||||
public ReturnImage ImageuploadWebDAV(Map<Map<String, String>, File> fileMap, String username,Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
try {
|
||||
if(null==httpClient || null==key){
|
||||
System.out.println("WebDAV = 存储源对象为空");
|
||||
returnImage.setCode("500");
|
||||
return returnImage;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("ImageuploadWebDAV:61异常",e);
|
||||
System.out.println("WebDAV = 存储源对象为空");
|
||||
returnImage.setCode("500");
|
||||
return returnImage;
|
||||
}
|
||||
File file = 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();
|
||||
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);
|
||||
HttpResponse response = httpClient.execute(httpPut);
|
||||
final int statusCode = response.getStatusLine().getStatusCode();
|
||||
logger.info("WebDav上传响应代码:"+statusCode);
|
||||
EntityUtils.consume(response.getEntity());
|
||||
if(statusCode >= 200 && statusCode < 300){
|
||||
returnImage.setCode("200");
|
||||
}else{
|
||||
returnImage.setCode(Integer.toString(statusCode));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("ImageuploadWebDAV:92异常",e);
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
return returnImage;
|
||||
}
|
||||
|
||||
//webdav初始化
|
||||
public static Integer Initialize(Keys k) {
|
||||
int ret = -1;
|
||||
try {
|
||||
if(k.getSysTransmit()==false){
|
||||
if (StringUtils.isBlank(k.getAccessKey())
|
||||
|| StringUtils.isBlank(k.getAccessSecret())
|
||||
|| StringUtils.isBlank(k.getEndpoint())
|
||||
|| StringUtils.isBlank(k.getRequestAddress())) {
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
if (StringUtils.isBlank(k.getAccessKey())
|
||||
|| StringUtils.isBlank(k.getAccessSecret())
|
||||
|| StringUtils.isBlank(k.getEndpoint())) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
String endpoint = k.getEndpoint();
|
||||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(
|
||||
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
|
||||
new UsernamePasswordCredentials(k.getAccessKey(), k.getAccessSecret()));
|
||||
CloseableHttpClient httpClientObj = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credentialsProvider)
|
||||
.build();
|
||||
HttpUriRequest request = RequestBuilder.create("PROPFIND")
|
||||
.setUri(endpoint +"/"+ k.getRootPath())
|
||||
.addHeader("Depth", "1")
|
||||
.setEntity(new StringEntity(
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
|
||||
"<D:propfind xmlns:D=\"DAV:\">\n" +
|
||||
" <D:allprop/>\n" +
|
||||
"</D:propfind>",
|
||||
ContentType.create("text/xml", "UTF-8")))
|
||||
.build();
|
||||
HttpResponse response = httpClientObj.execute(request);
|
||||
System.out.println("=====>"+response.getStatusLine().getStatusCode());
|
||||
if(response.getStatusLine().getStatusCode()==207 || response.getStatusLine().getStatusCode()==404){
|
||||
ret = 1;
|
||||
httpClient = httpClientObj;
|
||||
key = k;
|
||||
}else {
|
||||
return -1;
|
||||
}
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} catch (Exception e) {
|
||||
logger.error("WebDAV初始化失败", e);
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Boolean delWebDAV(Integer keyID, Images images) {
|
||||
boolean b = true;
|
||||
try {
|
||||
Keys keys = keysService.selectKeys(images.getSource());
|
||||
String rootPath = keys.getRootPath().equals("/")?"":keys.getRootPath();
|
||||
String fileUrl = keys.getEndpoint()+"/"+images.getImgname();
|
||||
System.err.println("删除缩yuan图:"+fileUrl);
|
||||
HttpDelete httpDelete = new HttpDelete(fileUrl);
|
||||
HttpResponse response = httpClient.execute(httpDelete);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode == 204) {
|
||||
logger.info("File deleted: " + fileUrl);
|
||||
// checkAndDeleteEmptyParentDirectories(httpClient,fileUrl);
|
||||
} else {
|
||||
logger.error("Failed to delete file: " + fileUrl);
|
||||
}
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} catch (Exception e) {
|
||||
logger.error("WebDav删除异常:",e);
|
||||
b = false;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
public ResponseEntity<InputStreamResource> getWebDAV(String shortUuid) {
|
||||
boolean b = true;
|
||||
try {
|
||||
Images images = null;
|
||||
images = imgService.selectImgByShortlink(shortUuid);
|
||||
Keys keys = keysService.selectKeys(images.getSource());
|
||||
String rootPath = keys.getRootPath().equals("/")?"":keys.getRootPath();
|
||||
String fileUrl = keys.getEndpoint()+"/"+images.getImgname();
|
||||
HttpGet httpGet = new HttpGet(fileUrl);
|
||||
HttpResponse response = httpClient.execute(httpGet);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Content-Type", "image/jpeg");
|
||||
return ResponseEntity.ok()
|
||||
.headers(headers)
|
||||
.body(new InputStreamResource(response.getEntity().getContent()));
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createDirectories(CloseableHttpClient httpClient, String baseUrl, String directoryPath) throws Exception {
|
||||
String[] directories = directoryPath.split("/");
|
||||
String currentPath = baseUrl;
|
||||
for (String directory : directories) {
|
||||
currentPath += directory + "/";
|
||||
HttpMkCol httpMkCol = new HttpMkCol(currentPath);
|
||||
HttpResponse response = httpClient.execute(httpMkCol);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode == 201) {
|
||||
System.out.println("Directory created: " + currentPath);
|
||||
} else if (statusCode == 405) {
|
||||
System.out.println("Directory already exists: " + currentPath);
|
||||
} else {
|
||||
System.err.println("Failed to create directory: " + currentPath);
|
||||
}
|
||||
EntityUtils.consume(response.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public class deleImages {
|
||||
@Autowired private USSImageupload ussImageupload;
|
||||
@Autowired private S3Imageupload s3Imageupload;
|
||||
@Autowired private FtpServiceImpl ftpService;
|
||||
@Autowired private WebDAVImageupload webDAVImageupload;
|
||||
@Autowired private ImgAndAlbumService imgAndAlbumService;
|
||||
@Autowired private ImgTempService imgTempService;
|
||||
@Autowired private ImgService imgService;
|
||||
@@ -75,6 +76,8 @@ public class deleImages {
|
||||
isDele = ftpService.delFTP(key.getId(), image);
|
||||
} else if (key.getStorageType() == 8) {
|
||||
isDele = s3Imageupload.deleS3(key.getId(), image);
|
||||
}else if (key.getStorageType() == 9) {
|
||||
isDele = webDAVImageupload.delWebDAV(key.getId(), image);
|
||||
} else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
@@ -149,6 +152,8 @@ public class deleImages {
|
||||
ftpService.delFTP(key.getId(), image);
|
||||
} else if (key.getStorageType() == 8) {
|
||||
s3Imageupload.deleS3(key.getId(), image);
|
||||
}else if (key.getStorageType() == 9) {
|
||||
webDAVImageupload.delWebDAV(key.getId(), image);
|
||||
} else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
|
||||
@@ -1,29 +1,51 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* Created by Hellohao on 2019-08-27.
|
||||
*/
|
||||
public class Base64Encryption {
|
||||
public static void toBaseCode(String str) {
|
||||
String data = encryptBASE64(str.getBytes());
|
||||
}
|
||||
public static String decryptBASE64(String key) {
|
||||
byte[] b =null;
|
||||
try {
|
||||
b = (new BASE64Decoder()).decodeBuffer(key);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new String(b);
|
||||
}
|
||||
public static String encryptBASE64(byte[] key) {
|
||||
String string = "SGVsbG9oYW8K";
|
||||
return (new BASE64Encoder()).encodeBuffer(key).replaceAll("\r|\n", "");
|
||||
}
|
||||
}
|
||||
//package cn.hellohao.utils;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.Base64;
|
||||
//
|
||||
///**
|
||||
// * Created by Hellohao on 2019-08-27.
|
||||
// */
|
||||
//public class Base64Encryption {
|
||||
//// public static void toBaseCode(String str) {
|
||||
//// String data = encryptBASE64(str.getBytes());
|
||||
//// }
|
||||
//// public static String decryptBASE64(String key) {
|
||||
//// byte[] b =null;
|
||||
//// try {
|
||||
//// b = (new BASE64Decoder()).decodeBuffer(key);
|
||||
//// } catch (IOException e) {
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
//// return new String(b);
|
||||
//// }
|
||||
//// public static String encryptBASE64(byte[] key) {
|
||||
//// String string = "SGVsbG9oYW8K";
|
||||
//// return (new BASE64Encoder()).encodeBuffer(key).replaceAll("\r|\n", "");
|
||||
//// }
|
||||
//
|
||||
//
|
||||
// public static void toBaseCode(String str) {
|
||||
// String data = encryptBASE64(str.getBytes());
|
||||
// }
|
||||
//
|
||||
// public static String decryptBASE64(String key) {
|
||||
// byte[] b = null;
|
||||
// try {
|
||||
// b = Base64.getDecoder().decode(key);
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return new String(b);
|
||||
// }
|
||||
//
|
||||
// public static String encryptBASE64(byte[] key) {
|
||||
// String string = "SGVsbG9oYW8K";
|
||||
// return Base64.getEncoder().encodeToString(key);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import sun.misc.BASE64Decoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* base64转为multipartFile工具类
|
||||
@@ -74,21 +74,30 @@ public class Base64ToMultipartFile implements MultipartFile {
|
||||
* @return
|
||||
*/
|
||||
public static MultipartFile base64Convert(String base64) {
|
||||
String[] baseStrs = base64.split(",");
|
||||
// String[] baseStrs = base64.split(",");
|
||||
// BASE64Decoder decoder = new BASE64Decoder();
|
||||
// byte[] b = new byte[0];
|
||||
// try {
|
||||
// b = decoder.decodeBuffer(baseStrs[1]);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// for (int i = 0; i < b.length; ++i) {
|
||||
// if (b[i] < 0) {
|
||||
// b[i] += 256;
|
||||
// }
|
||||
// }
|
||||
// return new Base64ToMultipartFile (b, baseStrs[0]);
|
||||
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
byte[] b = new byte[0];
|
||||
try {
|
||||
b = decoder.decodeBuffer(baseStrs[1]);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] baseStrs = base64.split(",");
|
||||
byte[] b = Base64.getDecoder().decode(baseStrs[1]);
|
||||
for (int i = 0; i < b.length; ++i) {
|
||||
if (b[i] < 0) {
|
||||
b[i] += 256;
|
||||
}
|
||||
}
|
||||
return new Base64ToMultipartFile (b, baseStrs[0]);
|
||||
return new Base64ToMultipartFile(b, baseStrs[0]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -111,6 +111,30 @@ public class FirstRun implements InitializingBean {
|
||||
RunSqlScript.RunInsert(instartConfdata);
|
||||
Print.Normal("Add table.confdata");
|
||||
}
|
||||
Integer ret7 =
|
||||
RunSqlScript.RunSelectCount(judgeTable + " 'keys' and column_name = 'SysTransmit'");
|
||||
if (ret7 == 0) {
|
||||
RunSqlScript.RunInsert(sql7);
|
||||
Print.Normal("Add keys.SysTransmit");
|
||||
}
|
||||
Integer ret8 =
|
||||
RunSqlScript.RunSelectCount(judgeTable + " 'imgdata' and column_name = 'brieflink'");
|
||||
if (ret8 == 0) {
|
||||
RunSqlScript.RunInsert(sql8);
|
||||
Print.Normal("Add imgdata.brieflink");
|
||||
}
|
||||
Integer ret9 =
|
||||
RunSqlScript.RunSelectCount(judgeTable + " 'imgdata' and column_name = 'shortlink'");
|
||||
if (ret9 == 0) {
|
||||
RunSqlScript.RunInsert(sql9);
|
||||
Print.Normal("Add imgdata.shortlink");
|
||||
}
|
||||
Integer ret10 =
|
||||
RunSqlScript.RunSelectCount(" select count(*) from tbed.keys where storageType='9'");
|
||||
if (ret10 == 0) {
|
||||
RunSqlScript.RunInsert(sql10);
|
||||
Print.Normal("Add Webdav Config");
|
||||
}
|
||||
RunSqlScript.RunInsert(index_imgdata);
|
||||
RunSqlScript.RunInsert("ALTER TABLE tbed.`user` MODIFY id int auto_increment;");
|
||||
Print.Normal("Stage success");
|
||||
@@ -130,12 +154,12 @@ public class FirstRun implements InitializingBean {
|
||||
private String sql3 ="CREATE TABLE `imgandalbum` (`imgname` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`albumkey` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic";
|
||||
private String sql4 ="CREATE TABLE `album` (`albumkey` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`albumtitle` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,`createdate` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `password` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic";
|
||||
private String sql6 = "alter table imgdata add explains varchar(5000)";
|
||||
//添加album表字段userid
|
||||
private String sql7 = "alter table album add userid int(10)";
|
||||
//添加imgdata表字段md5key
|
||||
private String sql8 = "alter table imgdata add md5key varchar(5000)";
|
||||
private String sql7 =
|
||||
"alter table `keys` add SysTransmit varchar(50) DEFAULT NULL ;";
|
||||
private String sql8 = "alter table `imgdata` add brieflink varchar(100) DEFAULT null ;";
|
||||
private String sql9 = "alter table `imgdata` add shortlink varchar(100) DEFAULT null ;";
|
||||
// 图片标识名字段
|
||||
private String sql11 = "alter table `imgdata` add idname varchar(255) DEFAULT '未命名' ;";
|
||||
private String sql10 = "INSERT INTO `tbed`.`keys`(`id`, `AccessKey`, `AccessSecret`, `Endpoint`, `Bucketname`, `RequestAddress`, `storageType`, `keyname`, `Region`, `RootPath`, `SysTransmit`) VALUES (null, '账号', '密码', '连接', '', '存储源请求域名', 9, 'WebDAV', NULL, '/', NULL);";
|
||||
|
||||
private String sql12 = "alter table tbed.user add `token` varchar(255)";
|
||||
//创建客户端程序相关表
|
||||
|
||||
@@ -39,8 +39,6 @@ public class GetCurrentSource {
|
||||
userService = userServiceImpl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Group GetSource(Integer userid) {
|
||||
//UserType 0-未分配 1-游客 2-用户 3-管理员
|
||||
User user =null;
|
||||
|
||||
@@ -31,7 +31,8 @@ public class GetSource {
|
||||
FtpServiceImpl ftpService;
|
||||
@Autowired
|
||||
S3Imageupload s3Imageupload;
|
||||
|
||||
@Autowired
|
||||
WebDAVImageupload webDAVImageupload;
|
||||
public ReturnImage storageSource(Integer type, Map<Map<String, String>, File> fileMap, String userpath,Integer keyID){
|
||||
ReturnImage returnImage = null;
|
||||
try {
|
||||
@@ -51,6 +52,8 @@ public class GetSource {
|
||||
returnImage = ftpService.FtpUploadFile(fileMap, userpath,keyID);
|
||||
}else if(type==8){
|
||||
returnImage = s3Imageupload.ImageuploadS3(fileMap, userpath,keyID);
|
||||
}else if(type==9){
|
||||
returnImage = webDAVImageupload.ImageuploadWebDAV(fileMap, userpath,keyID);
|
||||
}
|
||||
else{
|
||||
new StorageSourceInitException("GetSource类捕捉异常:未找到存储源");
|
||||
|
||||
@@ -30,22 +30,22 @@ private static final int VALICATE_CODE_LENGTH = 4;
|
||||
* @param height
|
||||
*/
|
||||
private static void fillBackground(Graphics graphics, int width, int height) {
|
||||
// 填充背景
|
||||
graphics.setColor(Color.WHITE);
|
||||
//设置矩形坐标x y 为0
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
// 填充背景
|
||||
graphics.setColor(Color.WHITE);
|
||||
//设置矩形坐标x y 为0
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
|
||||
// 加入干扰线条
|
||||
for (int i = 0; i < 8; i++) {
|
||||
//设置随机颜色算法参数
|
||||
graphics.setColor(RandomUtils.randomColor(40, 150));
|
||||
Random random = new Random();
|
||||
int x = random.nextInt(width);
|
||||
int y = random.nextInt(height);
|
||||
int x1 = random.nextInt(width);
|
||||
int y1 = random.nextInt(height);
|
||||
graphics.drawLine(x, y, x1, y1);
|
||||
}
|
||||
// 加入干扰线条
|
||||
for (int i = 0; i < 8; i++) {
|
||||
//设置随机颜色算法参数
|
||||
graphics.setColor(RandomUtils.randomColor(40, 150));
|
||||
Random random = new Random();
|
||||
int x = random.nextInt(width);
|
||||
int y = random.nextInt(height);
|
||||
int x1 = random.nextInt(width);
|
||||
int y1 = random.nextInt(height);
|
||||
graphics.drawLine(x, y, x1, y1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +59,15 @@ graphics.drawLine(x, y, x1, y1);
|
||||
*/
|
||||
@Override
|
||||
public String generate(int width, int height, OutputStream os) throws IOException {
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics graphics = image.getGraphics();
|
||||
fillBackground(graphics, width, height);
|
||||
String randomStr = RandomUtils.randomString(VALICATE_CODE_LENGTH);
|
||||
createCharacter(graphics, randomStr);
|
||||
graphics.dispose();
|
||||
//设置JPEG格式
|
||||
ImageIO.write(image, "JPEG", os);
|
||||
return randomStr;
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics graphics = image.getGraphics();
|
||||
fillBackground(graphics, width, height);
|
||||
String randomStr = RandomUtils.randomString(VALICATE_CODE_LENGTH);
|
||||
createCharacter(graphics, randomStr);
|
||||
graphics.dispose();
|
||||
//设置JPEG格式
|
||||
ImageIO.write(image, "JPEG", os);
|
||||
return randomStr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,20 +79,20 @@ return randomStr;
|
||||
*/
|
||||
@Override
|
||||
public VerifyCode generate(int width, int height) {
|
||||
VerifyCode verifyCode = null;
|
||||
try (
|
||||
//将流的初始化放到这里就不需要手动关闭流
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
) {
|
||||
String code = generate(width, height, baos);
|
||||
verifyCode = new VerifyCode();
|
||||
verifyCode.setCode(code);
|
||||
verifyCode.setImgBytes(baos.toByteArray());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
verifyCode = null;
|
||||
}
|
||||
return verifyCode;
|
||||
VerifyCode verifyCode = null;
|
||||
try (
|
||||
//将流的初始化放到这里就不需要手动关闭流
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
) {
|
||||
String code = generate(width, height, baos);
|
||||
verifyCode = new VerifyCode();
|
||||
verifyCode.setCode(code);
|
||||
verifyCode.setImgBytes(baos.toByteArray());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
verifyCode = null;
|
||||
}
|
||||
return verifyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,15 +102,15 @@ return verifyCode;
|
||||
* @param randomStr
|
||||
*/
|
||||
private void createCharacter(Graphics g, String randomStr) {
|
||||
char[] charArray = randomStr.toCharArray();
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
//设置RGB颜色算法参数
|
||||
g.setColor(new Color(50 + RandomUtils.nextInt(100),
|
||||
50 + RandomUtils.nextInt(100), 50 + RandomUtils.nextInt(100)));
|
||||
//设置字体大小,类型
|
||||
g.setFont(new Font(FONT_TYPES[RandomUtils.nextInt(FONT_TYPES.length)], Font.BOLD, 26));
|
||||
//设置x y 坐标
|
||||
g.drawString(String.valueOf(charArray[i]), 15 * i + 5, 19 + RandomUtils.nextInt(8));
|
||||
}
|
||||
}
|
||||
char[] charArray = randomStr.toCharArray();
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
//设置RGB颜色算法参数
|
||||
g.setColor(new Color(50 + RandomUtils.nextInt(100),
|
||||
50 + RandomUtils.nextInt(100), 50 + RandomUtils.nextInt(100)));
|
||||
//设置字体大小,类型
|
||||
g.setFont(new Font(FONT_TYPES[RandomUtils.nextInt(FONT_TYPES.length)], Font.BOLD, 26));
|
||||
//设置x y 坐标
|
||||
g.drawString(String.valueOf(charArray[i]), 15 * i + 5, 19 + RandomUtils.nextInt(8));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,10 @@
|
||||
<where>
|
||||
1=1
|
||||
<if test="albumkey != null">
|
||||
and `albumkey` like '%${albumkey}%'
|
||||
and `albumkey` like CONCAT('%', #{albumkey}, '%')
|
||||
</if>
|
||||
<if test="username != null">
|
||||
and `username` like '%${username}%'
|
||||
and `username` like CONCAT('%', #{username}, '%')
|
||||
</if>
|
||||
<if test="userid != null">
|
||||
and a.userid = #{userid}
|
||||
|
||||
@@ -53,11 +53,11 @@
|
||||
<choose>
|
||||
<when test="selecttype==1">
|
||||
and
|
||||
a.userid in ( SELECT id from `user` where username LIKE '%${username}%')
|
||||
a.userid in ( SELECT id from `user` where username LIKE CONCAT('%', #{username}, '%'))
|
||||
</when>
|
||||
<otherwise>
|
||||
and
|
||||
a.userid not in ( SELECT id from `user` where username LIKE '%${username}%')
|
||||
a.userid not in ( SELECT id from `user` where username LIKE CONCAT('%', #{username}, '%'))
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
@@ -71,10 +71,10 @@
|
||||
and CONCAT(
|
||||
imgurl,
|
||||
idname
|
||||
) LIKE '%${searchname}%'
|
||||
) LIKE CONCAT('%', #{searchname}, '%')
|
||||
</if>
|
||||
<if test="idname != null and idname !=''">
|
||||
and idname LIKE '%${idname}%'
|
||||
and idname LIKE CONCAT('%', #{idname}, '%')
|
||||
</if>
|
||||
order by
|
||||
<choose>
|
||||
@@ -126,13 +126,14 @@
|
||||
`format`,
|
||||
about,
|
||||
violation,
|
||||
idname
|
||||
idname,
|
||||
brieflink,
|
||||
shortlink
|
||||
)
|
||||
VALUES (null, #{imgname}, #{imgurl}, #{userid}, #{updatetime},#{sizes},#{abnormal},#{source},#{imgtype},
|
||||
#{explains},#{md5key},#{imguid},#{format},#{about},null,#{idname})
|
||||
#{explains},#{md5key},#{imguid},#{format},#{about},null,#{idname},#{brieflink},#{shortlink})
|
||||
</insert>
|
||||
|
||||
|
||||
<!-- 此用户下总数 -->
|
||||
<select id="countimg" parameterType="integer" resultType="integer">
|
||||
select count(*) from imgdata where userid = #{userid}
|
||||
@@ -150,6 +151,14 @@
|
||||
select * from imgdata where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectImgByBrieflink" parameterType="string" resultType="cn.hellohao.pojo.Images">
|
||||
select * from imgdata where binary brieflink = #{brieflink}
|
||||
</select>
|
||||
|
||||
<select id="selectImgByShortlink" parameterType="string" resultType="cn.hellohao.pojo.Images">
|
||||
select * from imgdata where binary shortlink = #{shortlink}
|
||||
</select>
|
||||
|
||||
<select id="counts" resultType="integer">
|
||||
select count(*) from imgdata where 1=1
|
||||
<if test="userid != null">
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
WHEN storageType=6 THEN '腾讯云'
|
||||
WHEN storageType=7 THEN 'FTP'
|
||||
WHEN storageType=8 THEN 'S3协议'
|
||||
WHEN storageType=9 THEN 'WebDAV'
|
||||
ELSE '未知' END AS storageName,
|
||||
keyname
|
||||
FROM `keys` GROUP BY storageType,id,storageName,keyname
|
||||
@@ -51,7 +52,8 @@
|
||||
RequestAddress = #{RequestAddress},
|
||||
keyname = #{keyname},
|
||||
Region = #{Region},
|
||||
RootPath = #{RootPath}
|
||||
RootPath = #{RootPath},
|
||||
SysTransmit=#{SysTransmit}
|
||||
WHERE
|
||||
storageType = #{storageType}
|
||||
</update>
|
||||
|
||||
@@ -213,7 +213,7 @@
|
||||
and CONCAT(
|
||||
username,
|
||||
email
|
||||
) LIKE '%${username}%'
|
||||
) LIKE CONCAT('%', #{username}, '%')
|
||||
</if>
|
||||
order by birthder desc
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user