mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f02d865389 | ||
|
|
48b0e1c5ca | ||
|
|
a04bbc1ea6 | ||
|
|
31b4426c10 | ||
|
|
766c125673 | ||
|
|
0de7e0e0fc | ||
|
|
f24a2d5557 | ||
|
|
87394258ad | ||
|
|
89a66a17b3 | ||
|
|
3e4c90c8d9 | ||
|
|
fb9f2a896e | ||
|
|
9ca8695cfd | ||
|
|
33d4990ded | ||
|
|
679ada60bc | ||
|
|
e2e723eb52 | ||
|
|
60db6036a5 | ||
|
|
790fded8ca | ||
|
|
fc53e4c8ac |
@@ -1,6 +0,0 @@
|
||||
*.js linguist-language=java
|
||||
|
||||
*.css linguist-language=java
|
||||
|
||||
*.html linguist-language=java
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
# 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: 托管的所有开源代码可能存在作者修改/测试/调整等行为,均为实验性代码,故并不保证程序或功能的可用性,如果你想要部署程序,请下载我们提供的编译整合包进行安装部署。
|
||||
|
||||
|
||||
### 引导
|
||||
|
||||
[官网](https://tbed.hellohao.cn) | [论坛](http://bbs.hellohao.cn) | [文档](https://doc.hellohao.cn) | [演示站](https://pic.hellohao.cn) | [桌面客户端](https://tbed.hellohao.cn/app) | [前端源码](https://github.com/Hello-hao/tbed-web)
|
||||
[官网](https://tbed.hellohao.cn) | [文档](https://doc.hellohao.cn) | [演示站](https://pic.hellohao.cn) | [桌面客户端](https://tbed.hellohao.cn/app) | [微信小程序](https://tbed.hellohao.cn/wechat) | [前端源码](https://github.com/Hello-hao/tbed-web)
|
||||
|
||||
|
||||
### 前言
|
||||
@@ -27,20 +38,12 @@
|
||||
|
||||
[Core版](https://hellohao.cn):开源版的基础上增加`Backblaze(B2)` 并且可`同个对象存储商家`可开多个存储源(可添加至90+存储源)
|
||||
|
||||
|
||||
### 更新日志 `20230622`
|
||||
|
||||
- 修复首页批量复制窗点击复制报错
|
||||
- 优化画廊分享复制分享信息时网址和提示字符的分割,以防被encode
|
||||
- 修复选择筛选框表单内容后,不检索也会筛选的异常情况
|
||||
- 筛选条件添加时间倒序/顺序、文件大小倒序/顺序
|
||||
- 优化用户登录账号支持邮箱/用户名方式登录
|
||||
- 修复了移动端web页面首页退出按钮无反应问题
|
||||
- 优化默认的站点logo展示逻辑,解决进入页面瞬间显示默认logo的问题
|
||||
- 强化图像链接转存功能,支持防盗链地址转存
|
||||
### 更新日志 `20240111`
|
||||
|
||||
|
||||
[^_^]: 程序宣传视频:[自制宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/)
|
||||
- 修复本地存储源上传失败的情况
|
||||
- 修复某些存储源目录创建不正确的问题
|
||||
- 优化页面部分提示
|
||||
|
||||
|
||||
### 主要功能
|
||||
@@ -110,6 +113,8 @@
|
||||
- /HellohaoData/:/HellohaoData/
|
||||
environment:
|
||||
MYSQL_URL: jdbc:mysql://hellohaodb/tbed?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
# 数据库用户名(一般使用本镜像数据库无需修改,如果使用外部三方数据库自行修改自己的用户名)
|
||||
MYSQL_USERNAME: root
|
||||
# 自定设置一个MySQL的密码,请保证与下方 POSTGRES_PASSWORD 的变量值一致
|
||||
MYSQL_PASS: tIaNGg@SHa&hIo56
|
||||
# 前端域名(反代10089端口的域名)
|
||||
@@ -167,13 +172,8 @@
|
||||
|
||||

|
||||
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
|
||||
### 桌面客户端(win/mac)
|
||||
> 获取地址:[官网获取](https://www.hellohao.cn/app)
|
||||
|
||||
> `开源版`/`Core版` 都可以使用
|
||||
> 
|
||||
@@ -214,6 +214,8 @@
|
||||
- Shiro
|
||||
|
||||
### 声明
|
||||
Hellohao图像托管已申请[**中国国家版权局计算机软件著作权**](https://register.ccopyright.com.cn/query.html)登记,受法律法规保护。
|
||||
> 登记号:2023SR1210640
|
||||
|
||||
本项目遵循[GNU Affero General Public License v3.0](https://choosealicense.com/licenses/agpl-3.0/#)开源协议,使用前请悉知。
|
||||
如果你想商用或程序定制,请先与我们联系,分享你的利益。
|
||||
|
||||
@@ -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>
|
||||
@@ -196,7 +206,7 @@
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>7.2.22</version>
|
||||
<version>7.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
|
||||
@@ -10,10 +10,12 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* @author Hellohao
|
||||
@@ -139,11 +141,16 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
|
||||
info = "用户未找到";
|
||||
}
|
||||
System.err.println("拦截器False-"+info);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
||||
httpServletResponse.setCharacterEncoding("UTF-8");
|
||||
httpServletResponse.setContentType("application/json");
|
||||
PrintWriter writer = httpServletResponse.getWriter();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code",this.CODE);
|
||||
jsonObject.put("info",info);
|
||||
response.getWriter().write(jsonObject.toJSONString());
|
||||
writer.write(jsonObject.toJSONString());
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
System.out.println("返回token验证失败403请求,报异常了");
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class ShiroConfig {
|
||||
filterMap.put("/verifyCode","anon");
|
||||
filterMap.put("/verifyCodeForRegister","anon");
|
||||
filterMap.put("/verifyCodeForRetrieve","anon");
|
||||
filterMap.put("/verifyCodeFortowSendEmail","anon");
|
||||
filterMap.put("/api/**","anon");
|
||||
filterMap.put("/user/**","anon");
|
||||
filterMap.put("/ota/**","anon");
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.TokenExpiredException;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -24,7 +23,7 @@ public class JWTUtil {
|
||||
|
||||
public static String createToken(User user){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.SECOND,604800 );//单位秒,604800 为7天
|
||||
calendar.add(Calendar.SECOND,2592000 );//单位秒
|
||||
Algorithm algorithm = Algorithm.HMAC256(SECRET);
|
||||
String token = JWT.create()
|
||||
.withClaim("email", user.getEmail())
|
||||
|
||||
@@ -467,6 +467,7 @@ public class AdminController {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
String images = jsonObj.getString("images");
|
||||
String uuid = jsonObj.getString("uuid");
|
||||
Boolean forceDel = jsonObj.getBoolean("forceDel")==null?false:jsonObj.getBoolean("forceDel");
|
||||
if (images == null) {
|
||||
msg.setCode("404");
|
||||
msg.setInfo("为获取到图像信息");
|
||||
@@ -499,7 +500,7 @@ public class AdminController {
|
||||
if (imgIds.size() == 0) {
|
||||
msg.setCode("110404");
|
||||
} else {
|
||||
deleimages.dele(uuid, imgIds.stream().toArray(Long[]::new));
|
||||
deleimages.dele(forceDel,uuid, imgIds.stream().toArray(Long[]::new));
|
||||
msg.setCode("200");
|
||||
}
|
||||
return msg;
|
||||
|
||||
@@ -44,10 +44,11 @@ public class IndexController {
|
||||
@Autowired private IRedisService iRedisService;
|
||||
@Autowired private AppClientService appClientService;
|
||||
|
||||
public static String version = "20240111";
|
||||
@RequestMapping(value = "/")
|
||||
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
|
||||
model.addAttribute("name", "服务端程序(开源版)");
|
||||
model.addAttribute("version", "20230622");
|
||||
model.addAttribute("version", version);
|
||||
model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest));
|
||||
model.addAttribute("links", "https://github.com/Hello-hao/tbed");
|
||||
return "welcome";
|
||||
@@ -64,6 +65,8 @@ public class IndexController {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
AppClient appClient = appClientService.getAppClientData("app");
|
||||
jsonObject.put("webname", cd.getString("webname"));
|
||||
jsonObject.put("systype","free");
|
||||
jsonObject.put("version",version);
|
||||
jsonObject.put("websubtitle", cd.getString("websubtitle"));
|
||||
jsonObject.put("keywords", cd.getString("keywords"));
|
||||
jsonObject.put("webms", cd.getString("webms"));
|
||||
@@ -79,10 +82,11 @@ public class IndexController {
|
||||
jsonObject.put("clientname", appClient.getAppname());
|
||||
jsonObject.put("clientlogo", appClient.getApplogo());
|
||||
jsonObject.put("appupdate", appClient.getAppupdate());
|
||||
jsonObject.put("serverVersion",version);
|
||||
msg.setData(jsonObject);
|
||||
return msg;
|
||||
}
|
||||
@PostMapping("/uploadChunkFile")
|
||||
@PostMapping(value = {"/uploadChunkFile","/client/uploadChunkFile"})
|
||||
@ResponseBody
|
||||
@CrossOrigin
|
||||
public Msg uploadChunk(HttpServletRequest request,Chunk chunk) {
|
||||
@@ -105,7 +109,7 @@ public class IndexController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/processFile")
|
||||
@PostMapping(value = {"/processFile","/client/processFile"})
|
||||
@ResponseBody
|
||||
@CrossOrigin
|
||||
public Msg processFile(HttpServletRequest request,@RequestParam(value = "data", defaultValue = "") String data){
|
||||
@@ -320,6 +324,29 @@ public class IndexController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/verifyCodeFortowSendEmail","/wechat/verifyCodeFortowSendEmail"})
|
||||
@ResponseBody
|
||||
public Msg verifyCodeFortowSendEmail() {
|
||||
Msg msg = new Msg();
|
||||
try {
|
||||
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(90, 35, 2, 2);
|
||||
// 自定义验证码内容为四则运算方式
|
||||
captcha.setGenerator(new MathGenerator(1));
|
||||
String code = getVerifyCodeOperator(captcha.getCode());
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
iRedisService.setValue("verifyCodeFortowSendEmail_"+uid,code);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("codeKey",uid);
|
||||
jsonObject.put("codeImg",captcha.getImageBase64());
|
||||
msg.setData(jsonObject);
|
||||
return msg;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
msg.setCode("500");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVerifyCodeOperator(String str) {
|
||||
int a = Integer.valueOf(str.substring(0, 1));
|
||||
String yxf = str.substring(1, 2);
|
||||
@@ -357,7 +384,7 @@ public class IndexController {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
msg = deleimages.dele(null, image.getId());
|
||||
msg = deleimages.dele(false,null, image.getId());
|
||||
List<Long> Delids = (List<Long>) msg.getData();
|
||||
if (!Delids.contains(image.getId())) {
|
||||
msg.setCode("500");
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -44,6 +46,7 @@ public class UserController {
|
||||
private SysConfigService sysConfigService;
|
||||
@Autowired
|
||||
IRedisService iRedisService;
|
||||
private Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||
|
||||
@PostMapping("/register")
|
||||
@ResponseBody
|
||||
@@ -143,6 +146,57 @@ public class UserController {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/validateEmail","/wechat/validateEmail"})
|
||||
@ResponseBody
|
||||
public Msg validateEmail(HttpServletRequest httpServletRequest,@RequestParam(value = "data", defaultValue = "") String data) {
|
||||
Msg msg = new Msg();
|
||||
try {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
String email = jsonObj.getString("email");
|
||||
String towSendEmailCode = jsonObj.getString("towSendEmailCode");
|
||||
Object verifyCodeFortowSendEmail =iRedisService.getValue("verifyCodeFortowSendEmail_"+httpServletRequest.getHeader("verifyCodeFortowSendEmail"));
|
||||
User u = new User();
|
||||
u.setEmail(email);
|
||||
User user = userService.getUsers(u);
|
||||
if(user.getIsok()!=0){
|
||||
msg.setInfo("不知细叶谁裁出,二月春风似剪刀");
|
||||
return msg;
|
||||
}
|
||||
if(null==verifyCodeFortowSendEmail){
|
||||
msg.setCode("4035");
|
||||
msg.setInfo("验证码已失效,请重新弄获取。");
|
||||
return msg;
|
||||
}else if(null==towSendEmailCode){
|
||||
msg.setCode("4036");
|
||||
msg.setInfo("验证码不能为空。");
|
||||
return msg;
|
||||
}
|
||||
if((verifyCodeFortowSendEmail.toString().toLowerCase()).compareTo((towSendEmailCode.toLowerCase()))==0){
|
||||
//注册完发激活链接
|
||||
final Confdata dataJson = confdataService.selectConfdata("config");
|
||||
JSONObject confdata = JSONObject.parseObject(dataJson.getJsondata());
|
||||
EmailConfig emailConfig = emailConfigService.getemail();
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Integer a = NewSendEmail.sendEmail(emailConfig,user.getUsername(), user.getUid(), user.getEmail(),confdata);
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
msg.setInfo("邮件已发送,请注意查收邮箱尽快激活账户(如果没收到,请检查垃圾邮件)");
|
||||
}else{
|
||||
msg.setCode("110408");
|
||||
msg.setInfo("验证码不正确");
|
||||
return msg;
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error("报错位置:/validateEmail",e);
|
||||
msg.setCode("500");
|
||||
msg.setInfo("邮件发送失败");
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@PostMapping("/login")//new
|
||||
@ResponseBody
|
||||
public Msg login(HttpServletRequest httpServletRequest,@RequestParam(value = "data", defaultValue = "") String data) {
|
||||
@@ -184,7 +238,8 @@ public class UserController {
|
||||
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
if(user.getIsok()==0){
|
||||
msg.setInfo("你的账号暂未激活");
|
||||
msg.setCode("110403");
|
||||
msg.setData(user.getEmail());
|
||||
msg.setCode("110402");
|
||||
return msg;
|
||||
}
|
||||
if(user.getIsok()<0){
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,8 +4,6 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Images {
|
||||
// 默认的时间字符串格式
|
||||
|
||||
//id, imgname, imgurl, userid
|
||||
private Long id;
|
||||
private String imgname;
|
||||
@@ -41,327 +39,9 @@ public class Images {
|
||||
private String idname;
|
||||
private Integer isRepeat;//如果没有开启查重的时候他是0,开启为1
|
||||
private String searchname;
|
||||
private String brieflink;
|
||||
private String shortlink;
|
||||
private String order;
|
||||
//
|
||||
// public Images() {
|
||||
// super();
|
||||
// }
|
||||
//
|
||||
// public Images(String imgurl, String sizes, String abnormal, String updatetime, String username, String md5key, String imguid) {
|
||||
// this.imgurl = imgurl;
|
||||
// this.sizes = sizes;
|
||||
// this.abnormal = abnormal;
|
||||
// this.updatetime = updatetime;
|
||||
// this.username = username;
|
||||
// this.md5key = md5key;
|
||||
// this.imguid = imguid;
|
||||
// }
|
||||
//
|
||||
// public Images(Long id, String imgname, String imgurl, Integer userid, String sizes, String abnormal, Integer source,
|
||||
// Integer imgtype, String updatetime, String username, Integer storageType, String starttime, String stoptime,
|
||||
// String explains, String md5key, String notes, String useridlist, String imguid, String albumtitle,
|
||||
// String password, Integer selecttype,Long countNum,Integer monthNum,String yyyy,
|
||||
// String format,String about,Integer great,String[] classifuidlist,String classificationuid,String violation,
|
||||
// String idname,Integer isRepeat,String searchname) {
|
||||
// this.id = id;
|
||||
// this.imgname = imgname;
|
||||
// this.imgurl = imgurl;
|
||||
// this.userid = userid;
|
||||
// this.sizes = sizes;
|
||||
// this.abnormal = abnormal;
|
||||
// this.source = source;
|
||||
// this.imgtype = imgtype;
|
||||
// this.updatetime = updatetime;
|
||||
// this.username = username;
|
||||
// this.storageType = storageType;
|
||||
// this.starttime = starttime;
|
||||
// this.stoptime = stoptime;
|
||||
// this.explains = explains;
|
||||
// this.md5key = md5key;
|
||||
// this.notes = notes;
|
||||
// this.useridlist = useridlist;
|
||||
// this.imguid = imguid;
|
||||
// this.albumtitle = albumtitle;
|
||||
// this.password = password;
|
||||
// this.selecttype = selecttype;
|
||||
// this.countNum = countNum;
|
||||
// this.monthNum = monthNum;
|
||||
// this.yyyy = yyyy;
|
||||
// this.format = format;
|
||||
// this.about = about;
|
||||
// this.great = great;
|
||||
// this.classifuidlist = classifuidlist;
|
||||
// this.classificationuid = classificationuid;
|
||||
// this.violation = violation;
|
||||
// this.idname = idname;
|
||||
// this.isRepeat = isRepeat;
|
||||
// this.searchname = searchname;
|
||||
// }
|
||||
//
|
||||
// public Long getId() {
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public void setId(Long id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// public String getImgname() {
|
||||
// return imgname;
|
||||
// }
|
||||
//
|
||||
// public void setImgname(String imgname) {
|
||||
// this.imgname = imgname;
|
||||
// }
|
||||
//
|
||||
// public String getImgurl() {
|
||||
// return imgurl;
|
||||
// }
|
||||
//
|
||||
// public void setImgurl(String imgurl) {
|
||||
// this.imgurl = imgurl;
|
||||
// }
|
||||
//
|
||||
// public Integer getUserid() {
|
||||
// return userid;
|
||||
// }
|
||||
//
|
||||
// public void setUserid(Integer userid) {
|
||||
// this.userid = userid;
|
||||
// }
|
||||
//
|
||||
// public String getSizes() {
|
||||
// return sizes;
|
||||
// }
|
||||
//
|
||||
// public void setSizes(String sizes) {
|
||||
// this.sizes = sizes;
|
||||
// }
|
||||
//
|
||||
// public String getAbnormal() {
|
||||
// return abnormal;
|
||||
// }
|
||||
//
|
||||
// public void setAbnormal(String abnormal) {
|
||||
// this.abnormal = abnormal;
|
||||
// }
|
||||
//
|
||||
// public Integer getSource() {
|
||||
// return source;
|
||||
// }
|
||||
//
|
||||
// public void setSource(Integer source) {
|
||||
// this.source = source;
|
||||
// }
|
||||
//
|
||||
// public Integer getImgtype() {
|
||||
// return imgtype;
|
||||
// }
|
||||
//
|
||||
// public void setImgtype(Integer imgtype) {
|
||||
// this.imgtype = imgtype;
|
||||
// }
|
||||
//
|
||||
// public String getUpdatetime() {
|
||||
// return updatetime;
|
||||
// }
|
||||
//
|
||||
// public void setUpdatetime(String updatetime) {
|
||||
// this.updatetime = updatetime;
|
||||
// }
|
||||
//
|
||||
// public String getUsername() {
|
||||
// return username;
|
||||
// }
|
||||
//
|
||||
// public void setUsername(String username) {
|
||||
// this.username = username;
|
||||
// }
|
||||
//
|
||||
// public Integer getStorageType() {
|
||||
// return storageType;
|
||||
// }
|
||||
//
|
||||
// public void setStorageType(Integer storageType) {
|
||||
// this.storageType = storageType;
|
||||
// }
|
||||
//
|
||||
// public String getStarttime() {
|
||||
// return starttime;
|
||||
// }
|
||||
//
|
||||
// public void setStarttime(String starttime) {
|
||||
// this.starttime = starttime;
|
||||
// }
|
||||
//
|
||||
// public String getStoptime() {
|
||||
// return stoptime;
|
||||
// }
|
||||
//
|
||||
// public void setStoptime(String stoptime) {
|
||||
// this.stoptime = stoptime;
|
||||
// }
|
||||
//
|
||||
// public String getExplains() {
|
||||
// return explains;
|
||||
// }
|
||||
//
|
||||
// public void setExplains(String explains) {
|
||||
// this.explains = explains;
|
||||
// }
|
||||
//
|
||||
// public String getMd5key() {
|
||||
// return md5key;
|
||||
// }
|
||||
//
|
||||
// public void setMd5key(String md5key) {
|
||||
// this.md5key = md5key;
|
||||
// }
|
||||
//
|
||||
// public String getNotes() {
|
||||
// return notes;
|
||||
// }
|
||||
//
|
||||
// public void setNotes(String notes) {
|
||||
// this.notes = notes;
|
||||
// }
|
||||
//
|
||||
// public String getUseridlist() {
|
||||
// return useridlist;
|
||||
// }
|
||||
//
|
||||
// public void setUseridlist(String useridlist) {
|
||||
// this.useridlist = useridlist;
|
||||
// }
|
||||
//
|
||||
// public String getImguid() {
|
||||
// return imguid;
|
||||
// }
|
||||
//
|
||||
// public void setImguid(String imguid) {
|
||||
// this.imguid = imguid;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public String getAlbumtitle() {
|
||||
// return albumtitle;
|
||||
// }
|
||||
//
|
||||
// public void setAlbumtitle(String albumtitle) {
|
||||
// this.albumtitle = albumtitle;
|
||||
// }
|
||||
//
|
||||
// public String getPassword() {
|
||||
// return password;
|
||||
// }
|
||||
//
|
||||
// public void setPassword(String password) {
|
||||
// this.password = password;
|
||||
// }
|
||||
//
|
||||
// public Integer getSelecttype() {
|
||||
// return selecttype;
|
||||
// }
|
||||
//
|
||||
// public void setSelecttype(Integer selecttype) {
|
||||
// this.selecttype = selecttype;
|
||||
// }
|
||||
//
|
||||
// public Long getCountNum() {
|
||||
// return countNum;
|
||||
// }
|
||||
//
|
||||
// public void setCountNum(Long countNum) {
|
||||
// this.countNum = countNum;
|
||||
// }
|
||||
//
|
||||
// public Integer getMonthNum() {
|
||||
// return monthNum;
|
||||
// }
|
||||
//
|
||||
// public void setMonthNum(Integer monthNum) {
|
||||
// this.monthNum = monthNum;
|
||||
// }
|
||||
//
|
||||
// public String getYyyy() {
|
||||
// return yyyy;
|
||||
// }
|
||||
//
|
||||
// public void setYyyy(String yyyy) {
|
||||
// this.yyyy = yyyy;
|
||||
// }
|
||||
//
|
||||
// public String getFormat() {
|
||||
// return format;
|
||||
// }
|
||||
//
|
||||
// public void setFormat(String format) {
|
||||
// this.format = format;
|
||||
// }
|
||||
//
|
||||
// public String getAbout() {
|
||||
// return about;
|
||||
// }
|
||||
//
|
||||
// public void setAbout(String about) {
|
||||
// this.about = about;
|
||||
// }
|
||||
//
|
||||
// public Integer getGreat() {
|
||||
// return great;
|
||||
// }
|
||||
//
|
||||
// public void setGreat(Integer great) {
|
||||
// this.great = great;
|
||||
// }
|
||||
//
|
||||
// public String[] getClassifuidlist() {
|
||||
// return classifuidlist;
|
||||
// }
|
||||
//
|
||||
// public void setClassifuidlist(String[] classifuidlist ) {
|
||||
// this.classifuidlist = classifuidlist;
|
||||
// }
|
||||
//
|
||||
// public String getClassificationuid() {
|
||||
// return classificationuid;
|
||||
// }
|
||||
//
|
||||
// public void setClassificationuid(String classificationuid) {
|
||||
// this.classificationuid = classificationuid;
|
||||
// }
|
||||
//
|
||||
// public String getViolation() {
|
||||
// return violation;
|
||||
// }
|
||||
//
|
||||
// public void setViolation(String violation) {
|
||||
// this.violation = violation;
|
||||
// }
|
||||
//
|
||||
// public String getIdname() {
|
||||
// return idname;
|
||||
// }
|
||||
//
|
||||
// public void setIdname(String idname) {
|
||||
// this.idname = idname;
|
||||
// }
|
||||
//
|
||||
// public Integer getIsRepeat() {
|
||||
// return isRepeat;
|
||||
// }
|
||||
//
|
||||
// public void setIsRepeat(Integer isRepeat) {
|
||||
// this.isRepeat = isRepeat;
|
||||
// }
|
||||
//
|
||||
// public String getSearchname() {
|
||||
// return searchname;
|
||||
// }
|
||||
//
|
||||
// public void setSearchname(String searchname) {
|
||||
// this.searchname = searchname;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,5 +14,6 @@ public class Keys {
|
||||
private Integer storageType;
|
||||
private String keyname;
|
||||
private String RootPath;//存入的目录
|
||||
private Boolean SysTransmit;
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -132,9 +132,10 @@ 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);
|
||||
@@ -167,6 +168,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);
|
||||
|
||||
@@ -5,10 +5,10 @@ import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import com.google.gson.Gson;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.Region;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
@@ -28,18 +28,7 @@ public class KODOImageupload {
|
||||
public ReturnImage ImageuploadKODO(
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
Configuration cfg;
|
||||
if (key.getEndpoint().equals("1")) {
|
||||
cfg = new Configuration(Zone.zone0());
|
||||
} else if (key.getEndpoint().equals("2")) {
|
||||
cfg = new Configuration(Zone.zone1());
|
||||
} else if (key.getEndpoint().equals("3")) {
|
||||
cfg = new Configuration(Zone.zone2());
|
||||
} else if (key.getEndpoint().equals("4")) {
|
||||
cfg = new Configuration(Zone.zoneNa0());
|
||||
} else {
|
||||
cfg = new Configuration(Zone.zoneAs0());
|
||||
}
|
||||
Configuration cfg = new Configuration(Region.autoRegion());
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(key.getAccessKey(), key.getAccessSecret());
|
||||
String upToken = auth.uploadToken(key.getBucketname(), null, 7200, null);
|
||||
@@ -76,41 +65,25 @@ public class KODOImageupload {
|
||||
|
||||
public static Integer Initialize(Keys k) {
|
||||
int ret = -1;
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(k.getAccessKey())
|
||||
|| org.apache.commons.lang3.StringUtils.isBlank(k.getAccessSecret())
|
||||
|| org.apache.commons.lang3.StringUtils.isBlank(k.getEndpoint())
|
||||
|| org.apache.commons.lang3.StringUtils.isBlank(k.getBucketname())
|
||||
if (StringUtils.isBlank(k.getAccessKey())
|
||||
|| StringUtils.isBlank(k.getAccessSecret())
|
||||
|| StringUtils.isBlank(k.getEndpoint())
|
||||
|| StringUtils.isBlank(k.getBucketname())
|
||||
|| StringUtils.isBlank(k.getRequestAddress())) {
|
||||
return -1;
|
||||
}
|
||||
Configuration cfg;
|
||||
if (k.getEndpoint().equals("1")) {
|
||||
cfg = new Configuration(Zone.zone0());
|
||||
} else if (k.getEndpoint().equals("2")) {
|
||||
cfg = new Configuration(Zone.zone1());
|
||||
} else if (k.getEndpoint().equals("3")) {
|
||||
cfg = new Configuration(Zone.zone2());
|
||||
} else if (k.getEndpoint().equals("4")) {
|
||||
cfg = new Configuration(Zone.zoneNa0());
|
||||
} else {
|
||||
cfg = new Configuration(Zone.zoneAs0());
|
||||
}
|
||||
Configuration cfg = new Configuration(Region.autoRegion());
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(k.getAccessKey(), k.getAccessSecret());
|
||||
String upToken =
|
||||
auth.uploadToken(
|
||||
k.getBucketname(),
|
||||
null,
|
||||
7200,
|
||||
null); // auth.uploadToken(k.getBucketname());
|
||||
BucketManager bmObj = new BucketManager(auth, cfg);
|
||||
String upToken = auth.uploadToken(k.getBucketname(), null, 7200, null);
|
||||
BucketManager BM = new BucketManager(auth, cfg);
|
||||
BucketManager.FileListIterator fileListIterator = null;
|
||||
try {
|
||||
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
|
||||
fileListIterator = BM.createFileListIterator(k.getBucketname(), "", 1, "/");
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
if (items != null) {
|
||||
ret = 1;
|
||||
bucketManager = bmObj;
|
||||
bucketManager = BM;
|
||||
key = k;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -129,13 +129,19 @@ 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);
|
||||
@@ -168,6 +174,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 +184,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 +224,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,226 @@
|
||||
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();
|
||||
CloseableHttpClient httpClient =null;
|
||||
Keys key = null;
|
||||
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);
|
||||
//webdav不能自动创建目录,上传件先创建目录
|
||||
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);
|
||||
// System.out.println(response.getStatusLine().getStatusCode());//正常成功201 已经存在204(有可能204还代表其他意思)
|
||||
// System.out.println("File upload response for " + file.getName() + ": " + response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
// System.out.println(EntityUtils.toString(response.getEntity(),"UTF-8"));
|
||||
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;
|
||||
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();
|
||||
try {
|
||||
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);
|
||||
// if (sardine.exists(keys.getEndpoint() + images.getImgname())) {
|
||||
// InputStream inputStream = sardine.get(keys.getEndpoint() + images.getImgname());
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Content-Type", "image/jpeg");
|
||||
// headers.add("Content-disposition", "attachment; filename=wallhaven-5g6yr3.jpg");
|
||||
return ResponseEntity.ok()
|
||||
.headers(headers)
|
||||
//.header("Content-disposition", "attachment; filename=Nextcloud.png")
|
||||
// .header("Content-Type", "image/jpg")
|
||||
.body(new InputStreamResource(response.getEntity().getContent()));
|
||||
// } else {
|
||||
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||
// }
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class deleImages {
|
||||
@Autowired private KeysServiceImpl keysService;
|
||||
@Autowired private IRedisService iRedisService;
|
||||
|
||||
public Msg dele(String uuid, Long... imgIds) {
|
||||
public Msg dele(boolean forceDel,String uuid, Long... imgIds) {
|
||||
Msg msg = new Msg();
|
||||
MyProgress myProgress = new MyProgress();
|
||||
myProgress.InitializeDelImg();
|
||||
@@ -44,6 +44,20 @@ public class deleImages {
|
||||
boolean isDele = false;
|
||||
try {
|
||||
Images image = imgService.selectByPrimaryKey(imgIds[i]);
|
||||
if (forceDel) {
|
||||
try {
|
||||
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
|
||||
imgTempService.delImgAndExp(image.getImguid());
|
||||
imgService.deleimg(image.getId());
|
||||
ids.add(image.getId());
|
||||
successCount++;
|
||||
System.out.println("删除成功加一个" + image.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
|
||||
errorIds.add(image.getImgurl());
|
||||
}
|
||||
}
|
||||
Keys key = keysService.selectKeys(image.getSource());
|
||||
if (key.getStorageType() == 1) {
|
||||
isDele = nosImageupload.delNOS(key.getId(), image);
|
||||
@@ -64,20 +78,21 @@ public class deleImages {
|
||||
} else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
// if (isDele) {
|
||||
try {
|
||||
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
|
||||
imgTempService.delImgAndExp(image.getImguid());
|
||||
imgService.deleimg(image.getId());
|
||||
ids.add(image.getId());
|
||||
successCount++;
|
||||
System.out.println("删除成功加一个" + image.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
|
||||
errorIds.add(image.getImgurl());
|
||||
if (!forceDel) {
|
||||
try {
|
||||
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
|
||||
imgTempService.delImgAndExp(image.getImguid());
|
||||
imgService.deleimg(image.getId());
|
||||
ids.add(image.getId());
|
||||
successCount++;
|
||||
System.out.println("删除成功加一个" + image.getId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
|
||||
errorIds.add(image.getImgurl());
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
if(uuid!=null){
|
||||
myProgress.setDelSuccessCount(successCount);
|
||||
myProgress.setDelSuccessImgList(ids);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -51,6 +51,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 = s3Imageupload.ImageuploadS3(fileMap, userpath,keyID);
|
||||
}
|
||||
else{
|
||||
new StorageSourceInitException("GetSource类捕捉异常:未找到存储源");
|
||||
|
||||
@@ -4,11 +4,11 @@ server.port=10088
|
||||
#前端域名需要带协议头http(s)://
|
||||
CROS_ALLOWED_ORIGINS=${HELLOHAO_WEB_HOST:http://127.0.0.1:8080}
|
||||
#数据库账号
|
||||
spring.datasource.username=root
|
||||
spring.datasource.username=${MYSQL_NAME:root}
|
||||
#数据库密码test
|
||||
spring.datasource.password=${MYSQL_PASS:root}
|
||||
#数据库链接地址
|
||||
spring.datasource.url=${MYSQL_URL:jdbc:mysql://127.0.0.1:3306/tbed?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8}
|
||||
spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost:3306/tbed?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8}
|
||||
#MySQL Driver 无需修改
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
|
||||
@@ -51,7 +51,7 @@ spring.datasource.druid.web-stat-filter.exclusions=false
|
||||
#log4j.logger.cn.hellohao.dao=DEBUG
|
||||
log4j2.formatMsgNoLookups=True
|
||||
logging.level.cn.hellohao=DEBUG
|
||||
logging.file.name=/HellohaoData/tbedlog/tbed_core.log
|
||||
logging.file.name=/HellohaoData/tbedlog/tbed.log
|
||||
logging.pattern.console=%blue(%d{yyyy-MM-dd HH:mm:ss,SSS}) [%cyan(%t)] [%yellow(%c)]-[%highlight(%p)] %msg%n
|
||||
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
|
||||
logging.logback.rollingpolicy.clean-history-on-start=true
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
FROM
|
||||
`album`
|
||||
<where>
|
||||
1=1
|
||||
<if test="albumkey != null">
|
||||
`albumkey` = #{albumkey}
|
||||
and `albumkey` = #{albumkey}
|
||||
</if>
|
||||
<if test="userid != null">
|
||||
`userid` = #{userid}
|
||||
and `userid` = #{userid}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
@@ -38,14 +39,15 @@
|
||||
u.username
|
||||
FROM `album` a LEFT JOIN user u on a.userid = u.id
|
||||
<where>
|
||||
1=1
|
||||
<if test="albumkey != null">
|
||||
`albumkey` like '%${albumkey}%'
|
||||
and `albumkey` like '%${albumkey}%'
|
||||
</if>
|
||||
<if test="username != null">
|
||||
`username` like '%${username}%'
|
||||
and `username` like '%${username}%'
|
||||
</if>
|
||||
<if test="userid != null">
|
||||
a.userid = #{userid}
|
||||
and a.userid = #{userid}
|
||||
</if>
|
||||
</where>
|
||||
order by a.createdate
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
FROM
|
||||
`imgandalbum`
|
||||
<where>
|
||||
1=1
|
||||
<if test="albumkey != null">
|
||||
`albumkey` = #{albumkey}
|
||||
</if>
|
||||
@@ -21,6 +22,7 @@
|
||||
FROM
|
||||
`imgandalbum`
|
||||
<where>
|
||||
1=1
|
||||
<if test="imgname != null">
|
||||
`imgname` = #{imgname}
|
||||
</if>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user